Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions exercise.wwwapi/DTOs/Users/UserDTO.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using exercise.wwwapi.DTOs.Notes;
using exercise.wwwapi.Enums;
using exercise.wwwapi.Factories;
using exercise.wwwapi.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace exercise.wwwapi.DTOs.Users;

public class UserDTO
{
[JsonPropertyName("id")]
public int Id { get; set; }

{
[JsonPropertyName("email")]
public string Email { get; set; }

Expand All @@ -35,6 +33,12 @@ public class UserDTO
[JsonPropertyName("specialism")]
public Specialism? Specialism { get; set; }

public int? CohortId { get; set; }

public DateTime? CurrentStartdate { get; set; }
public DateTime? CurrentEnddate { get; set; }


[JsonPropertyName("notes")]

public ICollection<NoteDTO> Notes { get; set; } = new List<NoteDTO>();
Expand All @@ -48,7 +52,6 @@ public UserDTO()

public UserDTO(User model)
{
Id = model.Id;
Email = model.Email;
FirstName = model.FirstName;
LastName = model.LastName;
Expand All @@ -58,6 +61,31 @@ public UserDTO(User model)
Mobile = model.Mobile;
Specialism = model.Specialism;
Role = model.Role.ToString();
CohortId = model.User_CC.LastOrDefault()?.CohortCourse.CohortId; //autofetching the first element of usercc
CurrentStartdate = model.User_CC.LastOrDefault().CohortCourse.Cohort.StartDate; //autofetching the first element of usercc
CurrentEnddate = model.User_CC.LastOrDefault().CohortCourse.Cohort.EndDate; //autofetching the first element of usercc
Notes = model.Notes.Select(n => new NoteDTO(n)).ToList();
}

public UserDTO(User model, PrivilegeLevel privilegeLevel)
{
Email = model.Email;
FirstName = model.FirstName;
LastName = model.LastName;
Bio = model.Bio;
Github = model.Github;
Username = model.Username;
Mobile = model.Mobile;
Specialism = model.Specialism;
Role = model.Role.ToString();
CohortId = model.User_CC.LastOrDefault()?.CohortCourse.CohortId; //autofetching the first element of usercc
CurrentStartdate = model.User_CC.LastOrDefault().CohortCourse.Cohort.StartDate; //autofetching the first element of usercc
CurrentEnddate = model.User_CC.LastOrDefault().CohortCourse.Cohort.EndDate; //autofetching the first element of usercc


if (privilegeLevel == PrivilegeLevel.Teacher)
{
Notes = model.Notes.Select(n => new NoteDTO(n)).ToList();
}
}
}
3 changes: 2 additions & 1 deletion exercise.wwwapi/Data/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

ModelSeeder.Seed(modelBuilder);
var seeder = new ModelSeeder();
seeder.Seed(modelBuilder);
}
}
Loading