Skip to content

Commit 9d5aa49

Browse files
author
Roman Eriksen
committed
Fixed merge
1 parent 02cb52d commit 9d5aa49

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

exercise.wwwapi/DTOs/Cohort/CohortDTO.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public class CohortDTO
44
{
55
public string Title { get; set; }
66

7-
public ICollection<UserCohortDTO> UserCohorts { get; set; } = new List<UserCohortDTO>();
7+
public ICollection<UserCohortDTO> Students { get; set; } = new List<UserCohortDTO>();
8+
9+
public ICollection<UserCohortDTO> Teachers { get; set; } = new List<UserCohortDTO>();
810
}
911
}

exercise.wwwapi/DTOs/Cohort/UserCohortDTO.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace exercise.wwwapi.DTOs.Cohort
44
{
55
public class UserCohortDTO
66
{
7-
public UserBasicDTO User { get; set; }
8-
9-
public string Cohort { get; set; }
7+
public UserBasicDTO User { get; set; }
108
}
119
}

exercise.wwwapi/Models/Cohort.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ public class Cohort
1414
[JsonIgnore]
1515
public ICollection<UserCohort> UserCohorts { get; set; } = new List<UserCohort>();
1616
}
17-
}
18-
|
17+
}

exercise.wwwapi/Tools/MappingProfile.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ public MappingProfile()
1717
CreateMap<User, UserDTO>();
1818
CreateMap<User, UserBasicDTO>();
1919
CreateMap<Post, PostDTO>();
20-
CreateMap<Cohort, CohortDTO>();
20+
21+
CreateMap<Cohort, CohortDTO>()
22+
.ForMember(dest => dest.Students, opt => opt.MapFrom(src => src.UserCohorts.Where(u => u.User.Role == Roles.student)))
23+
.ForMember(dest => dest.Teachers, opt => opt.MapFrom(src => src.UserCohorts.Where(u => u.User.Role == Roles.teacher)));
2124

2225
CreateMap<UserCohort, UserCohortDTO>()
23-
.ForMember(dest => dest.User, opt => opt.MapFrom(src => src.User))
24-
.ForMember(dest => dest.Cohort, opt => opt.MapFrom(src => src.Cohort.Title));
26+
.ForMember(dest => dest.User, opt => opt.MapFrom(src => src.User));
2527
//CreateMap<UserCohortDTO, UserBasicDTO>();
2628

2729
CreateMap<PostComment, PostCommentDTO>()

0 commit comments

Comments
 (0)