Пример #1
0
        public ActionResult Location(SetupOptionsModel model)
        {
            if (string.IsNullOrEmpty(model.LocationToAdd))
            {
                ModelState.AddModelError("AvailableLocations", "Please choose a location");
                return View("SetupOptions", CreateSetupOptionsModel());
            }

            var profileId = GetProfileFromCookie();
            var request = new AddLocationToProfileRequest
                              {
                                  Location = model.LocationToAdd,
                                  ProfileId = profileId
                              };

            var handler = new AddLocationToProfileRequestHandle(new ProfileRepository(), new LocationRepository());

            var response = handler.Handle(request);

            if (response.Status == ResponseCodes.Success)
            {
                return RedirectToAction("SetupOptions", "Setup");
            }

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

            return RedirectToAction("SetupOptions", "Setup");
        }
Пример #2
0
        private SetupOptionsModel CreateSetupOptionsModel()
        {
            var model = new SetupOptionsModel();

            var profileId = GetProfileFromCookie();

            model.SportsForProfile = GetSportsForProfile(profileId);
            model.CurrentLocations = GetLocationsForProfile(profileId);
            model.AvailableSports = new SelectList(new SportRepository().GetNamesOfAllSports());
            model.AvailableLocations = new SelectList(new LocationRepository().GetNamesOfAllLocations());
            model.SkillLevels = new SelectList(new SkillLevelProvider().GetListOfAvailableSkillLevels());
            return model;
        }
Пример #3
0
        public ActionResult Sports(SetupOptionsModel model)
        {
            if (string.IsNullOrEmpty(model.ChosenSport) || string.IsNullOrEmpty(model.ChosenSkillLevel))
            {
                ModelState.AddModelError("AvailableSports", "Please choose a sport AND a skill level");
                return View("SetupOptions", CreateSetupOptionsModel());
            }

            var profile = GetProfileFromCookie();
            var request = new AddSportToProfileRequest
                              {
                                  SkillLevel = int.Parse(model.ChosenSkillLevel),
                                  Sport = model.ChosenSport,
                                  UniqueId = profile
                              };

            var handler = new AddSportToProfileRequestHandle(new ProfileRepository(), new SportRepository());

            var response = handler.Handle(request);

            if (response.Status == ResponseCodes.Success)
            {
                return View("SetupOptions", CreateSetupOptionsModel());
            }

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

            return View("SetupOptions", CreateSetupOptionsModel());
        }