public ActionResult EditFacility(int id, FacilityChangeViewModel model) { if (this.ModelState.IsValid) { Facility mappedFacility = AutoMapperConfig.Configuration.CreateMapper().Map <Facility>(model); Facility currentFacility = this.facilities.GetFacilityDetails(id); foreach (var category in currentFacility.SportCategories) { category.Facilities.Remove(currentFacility); } currentFacility.SportCategories.Clear(); this.facilities.Save(); foreach (var categoryId in model.SportCategoriesIds) { SportCategory currentCategory = this.sportCategories.GetById(categoryId); mappedFacility.SportCategories.Add(currentCategory); } this.facilities.UpdateFacility(id, mappedFacility); return(this.RedirectToAction("FacilityDetails", "FacilitiesPublic", new { id = id, area = "Facilities" })); } return(this.View(model)); }
public ActionResult AddFacility() { FacilityChangeViewModel model = new FacilityChangeViewModel(); var cities = this.cities.All(); model.CitiesDropDown = this.GetSelectListCities(cities); var sportCategories = this.sportCategories.All(); model.SportCategoriesDropDown = this.GetSelectListSportCategories(sportCategories); return this.View(model); }
public ActionResult AddFacility() { FacilityChangeViewModel model = new FacilityChangeViewModel(); var cities = this.cities.All(); model.CitiesDropDown = this.GetSelectListCities(cities); var sportCategories = this.sportCategories.All(); model.SportCategoriesDropDown = this.GetSelectListSportCategories(sportCategories); return(this.View(model)); }
public ActionResult EditFacility(int Id) { Facility editedFacilty = this.facilities.GetFacilityDetails(Id); FacilityChangeViewModel mappedFacility = AutoMapperConfig.Configuration.CreateMapper().Map <FacilityChangeViewModel>(editedFacilty); var cities = this.cities.All(); mappedFacility.CitiesDropDown = this.GetSelectListCities(cities); var sportCategories = this.sportCategories.All(); mappedFacility.SportCategoriesDropDown = this.GetSelectListSportCategories(sportCategories); return(this.View(mappedFacility)); }
public void AddFacilityPostShouldReutrnCorrectViewWhenModelStateIsNotValid() { AutoMapperConfig autoMapperConfig = GetAutoMapper(); autoMapperConfig.Execute(typeof(FacilitiesPrivateController).Assembly); FacilityChangeViewModel model = new FacilityChangeViewModel(); var controller = new FacilitiesPrivateController(facilitiesServiceMock.Object, usersServiceMock.Object, citiesServiceMock.Object, sportCategoriesServiceMock.Object); controller.ModelState.AddModelError("key", "error"); controller.WithCallTo(x => x.AddFacility(model)) .ShouldRenderView("AddFacility") .WithModel <FacilityChangeViewModel>(); }
public ActionResult AddFacility(FacilityChangeViewModel model) { if (this.ModelState.IsValid) { Facility mappedFacility = AutoMapperConfig.Configuration.CreateMapper().Map <Facility>(model); foreach (var categoryId in model.SportCategoriesIds) { SportCategory currentCategory = this.sportCategories.GetById(categoryId); mappedFacility.SportCategories.Add(currentCategory); } mappedFacility.AuthorId = this.User.Identity.GetUserId(); this.facilities.Add(mappedFacility); return(this.RedirectToAction("FacilityDetails", "FacilitiesPublic", new { id = mappedFacility.Id, area = "Facilities" })); } return(this.View(model)); }
public ActionResult AddFacility(FacilityChangeViewModel model) { if (this.ModelState.IsValid) { Facility mappedFacility = AutoMapperConfig.Configuration.CreateMapper().Map<Facility>(model); foreach (var categoryId in model.SportCategoriesIds) { SportCategory currentCategory = this.sportCategories.GetById(categoryId); mappedFacility.SportCategories.Add(currentCategory); } mappedFacility.AuthorId = this.User.Identity.GetUserId(); this.facilities.Add(mappedFacility); return this.RedirectToAction("FacilityDetails", "FacilitiesPublic", new { id = mappedFacility.Id, area = "Facilities" }); } return this.View(model); }
public ActionResult EditFacility(int id, FacilityChangeViewModel model) { if (this.ModelState.IsValid) { Facility mappedFacility = AutoMapperConfig.Configuration.CreateMapper().Map<Facility>(model); Facility currentFacility = this.facilities.GetFacilityDetails(id); foreach (var category in currentFacility.SportCategories) { category.Facilities.Remove(currentFacility); } currentFacility.SportCategories.Clear(); this.facilities.Save(); foreach (var categoryId in model.SportCategoriesIds) { SportCategory currentCategory = this.sportCategories.GetById(categoryId); mappedFacility.SportCategories.Add(currentCategory); } this.facilities.UpdateFacility(id, mappedFacility); return this.RedirectToAction("FacilityDetails", "FacilitiesPublic", new { id = id, area = "Facilities" }); } return this.View(model); }