Exemplo n.º 1
0
        public ActionResult CreateProfile(CreateProfileModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(CreateViewModel());
            }

            var request = new CreateProfileRequest(User.Identity.Name, model.Name, model.Location, model.Sports,
                                                   model.SkillLevel);

            var handler = new CreateProfileRequestHandle(new SportRepository(), new LocationRepository(),
                                                          new ProfileRepository(), new ProfileBuilder());

            var response = handler.Handle(request);

            if (response.Status == ResponseCodes.Success)
            {
                return RedirectToAction("ChooseProfile");
            }

            var errorMessage = response.Status.GetMessage();
            ModelState.AddModelError("", errorMessage);

            return View(CreateViewModel());
        }
Exemplo n.º 2
0
        private CreateProfileModel CreateViewModel()
        {
            var sports = new SportRepository().GetNamesOfAllSports();
            var locations = new LocationRepository().GetNamesOfAllLocations();

            var availableSports = new SelectList(sports);
            var availableLocations = new SelectList(locations);

            var viewModel = new CreateProfileModel
                                {
                                    AvailableSports = availableSports,
                                    AvailableLocations = availableLocations,
                                    AvailableSkillLevels = new SelectList(new SkillLevelProvider().GetListOfAvailableSkillLevels())
                                };
            return viewModel;
        }