コード例 #1
0
        public ActionResult EditMyMentorInfo(NewMentorModel updatedMentor)
        {
            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
                    {
                        Id = updatedMentor.Id,
                        CurrentActivity   = updatedMentor.CurrentActivity,
                        Expectations      = updatedMentor.Expectations,
                        MaxMentees        = updatedMentor.MaxMentees,
                        MeetingsMode      = updatedMentor.MeetingsMode,
                        MentoringTarget   = updatedMentor.MentoringTarget,
                        OtherAvailability = updatedMentor.OtherAvailability,
                        OtherTopic        = updatedMentor.OtherTopic
                    };

                    _mentorService.UpdateMentor(mentor);
                }

                return(RedirectToAction("MyMentorInfo"));
            }

            return(View(updatedMentor));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        private NewMentorModel ToNewMentorModel(Mentor mentor)
        {
            var allTopics = _topicService.GetAll();
            var topics    = allTopics.Select(t => new TopicModel {
                Checked = false, Description = t.Description, Id = t.Id
            });

            var allTimeSlots = _timeSlotService.GetAll();
            var availability = allTimeSlots.Select(t => new TimeSlotModel {
                Checked = false, Description = t.Description, Id = t.Id
            });

            var allMenteeSeniorityLevels = _menteeSeniorityService.GetAll();
            var allMenteeSeniorities     = allMenteeSeniorityLevels.Select(s => new MenteeSeniorityModel {
                Id = s.Id, Checked = false, Description = s.Description
            });

            var meetingMode = from MeetingMode e in Enum.GetValues(typeof(MeetingMode))
                              select new { Value = e.ToString(), Text = EnumExtension.GetEnumDescription(e) };

            ViewBag.MeetingModes = new SelectList(meetingMode, "Value", "Text");

            var newMentorModel = new NewMentorModel
            {
                Topics          = topics.ToList(),
                Availability    = availability.ToList(),
                SeniorityLevel  = allMenteeSeniorities.ToList(),
                CurrentActivity = mentor.CurrentActivity
            };

            foreach (var topic in mentor.Topic)
            {
                var specificTopic = newMentorModel.Topics.FirstOrDefault(t => t.Id == topic.Id);
                if (specificTopic != null)
                {
                    specificTopic.Checked = true;
                }
            }

            foreach (var menteeSeniorities in mentor.MenteeSeniorities)
            {
                var menteeSeniority = newMentorModel.SeniorityLevel.FirstOrDefault(t => t.Id == menteeSeniorities.Id);
                if (menteeSeniority != null)
                {
                    menteeSeniority.Checked = true;
                }
            }

            newMentorModel.OtherTopic      = mentor.OtherTopic;
            newMentorModel.MentoringTarget = mentor.MentoringTarget;
            newMentorModel.MaxMentees      = mentor.MaxMentees;
            foreach (var avail in mentor.Availability)
            {
                var specificAvailability = newMentorModel.Availability.FirstOrDefault(a => a.Id == avail.Id);
                if (specificAvailability != null)
                {
                    specificAvailability.Checked = true;
                }
            }
            newMentorModel.OtherAvailability = mentor.OtherAvailability;
            newMentorModel.MeetingsMode      = mentor.MeetingsMode;
            newMentorModel.Expectations      = mentor.Expectations;
            newMentorModel.Seniority         = mentor.User.Seniority;
            newMentorModel.Location          = mentor.User.Location;


            return(newMentorModel);
        }