Exemple #1
0
        public ActionResult NewMentee()
        {
            var userInfo = UserHelper.GetCurrentUserInfo();

            if (!userInfo.IsInRole(UserRoleCode.Mentee))
            {
                var mentorsSelectList = GetAvailableMentors();

                var newMentorModel = new NewMenteeModel
                {
                    FirstMentorOption  = mentorsSelectList,
                    SecondMentorOption = mentorsSelectList,
                    Location           = !userInfo.Location.Equals("unknown") ? userInfo.Location : string.Empty,
                    Seniority          = !userInfo.Seniority.Equals("unknown") ? userInfo.Seniority : string.Empty,
                };

                return(View(newMentorModel));
            }

            return(View("Unauthorized"));
        }
Exemple #2
0
        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"));
        }