示例#1
0
        public static GiveCampLondon.Volunteer MapToVolunteerModel(this Volunteer.SignUpViewModel model)
        {
            var volunteer = new GiveCampLondon.Volunteer
            {
                FirstName         = model.FirstName,
                LastName          = model.LastName,
                Bio               = model.Bio,
                Comments          = model.Comments,
                DietaryNeeds      = model.DietaryNeeds,
                Email             = model.Email,
                HasExtraLaptop    = model.HasExtraLaptop,
                HasLaptop         = model.HasLaptop,
                IsGoodGuiDesigner = model.IsGoodGuiDesigner,
                IsStudent         = model.IsStudent,
                JobDescription    = model.JobDescription,
                PhoneNumber       = model.PhoneNumber,
                ShirtSize         = model.ShirtSize,
                ShirtStyle        = model.ShirtStyle,
                TeamName          = model.TeamName,
                TwitterHandle     = model.TwitterHandle,
                YearsOfExperience = model.YearsOfExperience
            };

            return(volunteer);
        }
        private Volunteer CreateVolunteer(SignUpViewModel model, IEnumerable<int> selectedJobRoleIds, IEnumerable<int> selectedTechnologyIds)
        {
            var volunteer = model.MapToVolunteerModel();
            volunteer.ExperienceLevel = _xpLevelRepository.Get(model.ExperienceLevel);
            volunteer.IsOnWaitList = _waitListHelper.SetWaitListStatus();
            foreach (var jobRoleId in selectedJobRoleIds)
            {
                volunteer.JobRoles.Add(_jobRoleRepository.Get(jobRoleId));
            }

            foreach (var selectedTechnologyId in selectedTechnologyIds)
            {
                volunteer.Technologies.Add(_technologyRepository.Get(selectedTechnologyId));
            }
            return volunteer;
        }
        public ActionResult SignUp(SignUpViewModel model, FormCollection collection)
        {
            var selectedJobRoleIds = GetSelectedValues(collection, "jobRoles", true, "Please select at least one job role.");
            var selectedTechnologyIds = GetSelectedValues(collection, "technologies", true, "Please select at least one technology");

            if (!ModelState.IsValid)
            {
                InitializeViewBag(model);
                return View();
            }

            if (SaveVolunteer(model, selectedJobRoleIds, selectedTechnologyIds))
            {
                return RedirectToAction("ThankYou");
            }

            ModelState.AddModelError("SignUpStatus", "Could not sign you up - please try again");
            InitializeViewBag(model);
            return View();
        }
        private bool SaveVolunteer(SignUpViewModel model, IEnumerable<int> selectedJobRoleIds, IEnumerable<int> selectedTechnologyIds)
        {
            if (ModelState.IsValid)
            {
                var volunteer = CreateVolunteer(model, selectedJobRoleIds, selectedTechnologyIds);

                _volunteerRepository.Save(volunteer);
                _notificationService.SendNotification(model.Email,
                                                      volunteer.IsOnWaitList
                                                          ? VolunteerNotificationTemplate.WelcomeWaitingVolunteer
                                                          : VolunteerNotificationTemplate.WelcomeVolunteer);

                return true;
            }
            return false;
        }
 private void InitializeViewBag(SignUpViewModel model)
 {
     ViewBag.JobRoles = _jobRoleRepository.FindAll().ToSelectList(j => j.Description, j => j.Id.ToString(), j => model != null && model.JobRoleIds != null && model.JobRoleIds.Contains(j.Id));
     ViewBag.Technologies = _technologyRepository.FindAll().ToSelectList(t => t.Description, t => t.Id.ToString(), t => model != null && model.TechnologyIds != null && model.TechnologyIds.Contains(t.Id));
     ViewBag.ExperienceLevels = _xpLevelRepository.FindAll().ToSelectList(e => e.Description, e => e.Id.ToString(), e => model != null && model.ExperienceLevel == e.Id);
 }