public ActionResult NewMentor(NewMentorModel newMentor) { if (ModelState.IsValid) { var currentUser = UserHelper.GetCurrentUserInfo(); var isExistingMentor = _mentorService.Search(m => m.User.Id == currentUser.Id && (m.Status == MentorStatus.Active || m.Status == MentorStatus.PendingApproval)).Any(); if (!isExistingMentor) { var mentor = new Mentor { CurrentActivity = newMentor.CurrentActivity, Expectations = newMentor.Expectations, MaxMentees = newMentor.MaxMentees, MeetingsMode = newMentor.MeetingsMode, MentoringTarget = newMentor.MentoringTarget, OtherAvailability = newMentor.OtherAvailability, OtherTopic = newMentor.OtherTopic }; var selectedTopicIds = newMentor.Topics.Where(t => t.Checked).Select(t => t.Id).ToList(); var selectedTimeSlotIds = newMentor.Availability.Where(t => t.Checked).Select(t => t.Id).ToList(); var selectedMenteeSeniorityIds = newMentor.SeniorityLevel.Where(t => t.Checked).Select(t => t.Id).ToList(); _mentorService.NewMentor(mentor, currentUser.Id, selectedTopicIds, selectedTimeSlotIds, selectedMenteeSeniorityIds, newMentor.Location, newMentor.Seniority); UserHelper.SetUserInfo(mentor.User); _emailMessageService.SaveMessage(mentor.User.Email, "PreApprovedMentor", null); } return(View("NewMentorPreApproved")); } return(View(newMentor)); }
public ActionResult NewMentee(NewMenteeModel newMentee) { var userInfo = UserHelper.GetCurrentUserInfo(); if (!userInfo.IsInRole(UserRoleCode.Mentee)) { //TODO: <code smells> var firstMentor = newMentee.FirstMentorOption.Where(m => m.IsSelected).ToList(); var isInvalidModel = false; if (firstMentor.Count == 0) { ModelState.AddModelError("FirstMentorOption", "This field is required"); isInvalidModel = true; } if (firstMentor.Count > 1) { ModelState.AddModelError("FirstMentorOption", "Please select only one option"); isInvalidModel = true; } var secondMentor = newMentee.SecondMentorOption.Where(m => m.IsSelected).ToList(); if (secondMentor.Count == 0) { ModelState.AddModelError("SecondMentorOption", "This field is required"); isInvalidModel = true; } if (secondMentor.Count > 1) { ModelState.AddModelError("SecondMentorOption", "Please select only one option"); isInvalidModel = true; } if (secondMentor.Count == 1 && firstMentor.Count == 1) { if (secondMentor.First().Id == firstMentor.First().Id) { ModelState.AddModelError("SecondMentorOption", "First and Second mentor options are equals"); isInvalidModel = true; } } //TODO: </code smells> if (isInvalidModel) { var mentorsSelectList = GetAvailableMentors(); newMentee.FirstMentorOption = mentorsSelectList; newMentee.SecondMentorOption = mentorsSelectList; return(View(newMentee)); } var currentUser = UserHelper.GetCurrentUserInfo(); var mentee = new Mentee { CurrentActivity = newMentee.CurrentActivity, Focus = newMentee.SkillFocus }; _menteeService.NewMentee(mentee, currentUser.Id, firstMentor.First().Id, secondMentor.First().Id, newMentee.Location, newMentee.Seniority); UserHelper.SetUserInfo(mentee.User); _emailMessageService.SaveMessage(mentee.User.Email, "PreApprovedMentee", null); return(View("NewMenteePendingApproval")); } return(View("Unauthorized")); }