public DomainModelResponse AddUserToCourse(UpdateUserCourse request) { UserProfile up = _repUser.Get(filter: f => f.EmailId == request.emailId).FirstOrDefault(); if(up == null) { _securityResponse.addResponse("AddUserToCourse", MessageCodes.ErrDoesnotExist, "User : "******"AddUserToCourse", MessageCodes.ErrDoesnotExist, "Role : " + request.RoleCode); throw _securityResponse; } cur.RoleId = role.RoleId; cur.Role = role; Course course = _repCourse.Get(filter: f => f.CourseCode == request.courseCode).FirstOrDefault(); if(course == null) { _securityResponse.addResponse("AddUserToCourse", MessageCodes.ErrDoesnotExist, "Course : " + request.courseCode); throw _securityResponse; } cur.CourseId = course.CourseId; cur.Course = course; _repCourseUserRole.Add(cur); _uow.Commit(); _securityResponse.addResponse("AddUserToCourse", MessageCodes.InfoCreatedSuccessfully, "CourseUserRole for user : " + request.emailId); return _securityResponse; }
public DomainModelResponse Add(CourseAddRequest request) { GroupType gt = _repGroupType.Get(filter: x => x.GroupTypeCode == request.GroupType).FirstOrDefault(); Course course = new Course() { CourseCode = request.CourseCode, CourseName = request.CourseName, CourseDescription = request.CourseDescription, LastChangedTime = DateTime.UtcNow, DesiredSkillSets = request.DesiredSkillSets, GroupType = gt, PrefGroupTypeId = gt.GroupTypeId, PrefGroupSize = request.GroupSize, SimilarSkillSetPreffered = request.PreferSimiliarSkillSet }; _repCourse.Add(course); _uow.Commit(); course = _repCourse.Get(filter: f => f.CourseCode == request.CourseCode).FirstOrDefault(); if (request.userList != null) { List<string> roleCodes = request.userList.Select(x => x.roleCode).ToList(); List<string> emailIds = request.userList.Select(x => x.emailId).ToList(); List<EntityModel.Role> roles = _repRole.Get(filter: f => roleCodes.Contains(f.RoleCode)).ToList(); List<UserProfile> userProfiles = _repUserProfile.Get(filter: f => emailIds.Contains(f.EmailId)).ToList(); foreach(var user in request.userList) { CourseUserRole cur = new CourseUserRole() { CourseId = course.CourseId, Course = course, Role = roles.Where(x => x.RoleCode == user.roleCode).FirstOrDefault(), RoleId = roles.Where(x => x.RoleCode == user.roleCode).FirstOrDefault().RoleId, UserId = userProfiles.Where(x => x.EmailId == user.emailId).FirstOrDefault().UserId, UserProfile = userProfiles.Where(x => x.EmailId == user.emailId).FirstOrDefault(), LastChangedTime = DateTime.UtcNow }; _repCourseUserRole.Add(cur); } _uow.Commit(); } _courseResponse.addResponse("Add", MessageCodes.InfoCreatedSuccessfully, "Course : " + request.CourseCode); return _courseResponse; }
public DomainModelResponse Update(CourseUpdateRequest request) { Course course = _repCourse.Get(filter: f => f.CourseCode == request.CourseCode).FirstOrDefault(); bool updateCourse = false; if(request.CourseName != null) //Course name update { course.CourseName = request.CourseName; updateCourse = true; } if (request.CourseDescription != null) { course.CourseDescription = request.CourseDescription; updateCourse = true; } if(request.QuestionnaireCode != null) { EntityModel.Questionnaire questionnaire = _repQuestionnaire.Get(filter: f => f.QuestionnaireCode == request.QuestionnaireCode).FirstOrDefault(); course.QuestionnaireId = questionnaire.QuestionnaireId; course.Questionnaire = questionnaire; updateCourse = true; } if(updateCourse) _repCourse.Update(course); if(request.CourseNewUsers != null) { List<string> roleCodes = request.CourseNewUsers.Select(x => x.roleCode).ToList(); List<string> emailIds = request.CourseNewUsers.Select(x => x.emailId).ToList(); List<EntityModel.Role> roles = _repRole.Get(filter: f => roleCodes.Contains(f.RoleCode)).ToList(); List<UserProfile> userProfiles = _repUserProfile.Get(filter: f => emailIds.Contains(f.EmailId)).ToList(); foreach (var user in request.CourseNewUsers) { CourseUserRole cur = new CourseUserRole() { CourseId = course.CourseId, Course = course, Role = roles.Where(x => x.RoleCode == user.roleCode).FirstOrDefault(), RoleId = roles.Where(x => x.RoleCode == user.roleCode).FirstOrDefault().RoleId, UserId = userProfiles.Where(x => x.EmailId == user.emailId).FirstOrDefault().UserId, UserProfile = userProfiles.Where(x => x.EmailId == user.emailId).FirstOrDefault(), LastChangedTime = DateTime.UtcNow }; _repCourseUserRole.Add(cur); } } if (request.CourseDeleteUsers != null) { List<string> roleCodes = request.CourseDeleteUsers.Select(x => x.roleCode).ToList(); List<string> emailIds = request.CourseDeleteUsers.Select(x => x.emailId).ToList(); List<EntityModel.Role> roles = _repRole.Get(filter: f => roleCodes.Contains(f.RoleCode)).ToList(); List<UserProfile> userProfiles = _repUserProfile.Get(filter: f => emailIds.Contains(f.EmailId)).ToList(); foreach (var user in request.CourseDeleteUsers) { int RoleId = roles.Where(x => x.RoleCode == user.roleCode).FirstOrDefault().RoleId; int UserId = userProfiles.Where(x => x.EmailId == user.emailId).FirstOrDefault().UserId; CourseUserRole cur = _repCourseUserRole.Get(filter: f => f.RoleId == RoleId && f.CourseId == course.CourseId && f.UserId == UserId).FirstOrDefault(); _repCourseUserRole.Delete(cur); } } _uow.Commit(); _courseResponse.addResponse("Update", MessageCodes.InfoSavedSuccessfully, "Course : " + request.CourseCode); return _courseResponse; }