private void UpdateVacPropertyAmenities(string[] selectedAmenities, VacProperty vpropertyToUpdate) { if (selectedAmenities == null) { vpropertyToUpdate.Amenities = new List <Amenity>(); return; } var selectedAmenitiesHS = new HashSet <string>(selectedAmenities); var vpropertyAmenities = new HashSet <int> (vpropertyToUpdate.Amenities.Select(c => c.Id)); foreach (var amenity in db.Amenities) { if (selectedAmenitiesHS.Contains(amenity.Id.ToString())) { if (!vpropertyAmenities.Contains(amenity.Id)) { vpropertyToUpdate.Amenities.Add(amenity); } } else { if (vpropertyAmenities.Contains(amenity.Id)) { vpropertyToUpdate.Amenities.Remove(amenity); } } } }
public ActionResult DeleteConfirmed(int id) { VacProperty vacProperty = db.VacProperties.Find(id); db.VacProperties.Remove(vacProperty); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Title,Description,LocationId,MaxOccupancy,VPType,PricePN")] VacProperty vacProperty) { if (ModelState.IsValid) { db.Entry(vacProperty).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LocationId = new SelectList(db.Locations, "Id", "Address", vacProperty.LocationId); return(View(vacProperty)); }
//[Authorize(Roles = "Owner")] // GET: VacProperties/Create public ActionResult Create() { ViewBag.CityId = new SelectList(db.Cities, "Id", "Name"); ViewBag.LocationId = new SelectList(db.Locations, "Id", "Address"); var vproperty = new VacProperty(); vproperty.Amenities = new List <Amenity>(); PopulateSelectedAmenities(vproperty); var vmcreateproperty = new CreatePropertyViewModel(); vmcreateproperty.CitiesSelectListItems = new SelectList(db.Cities, "Id", "Name"); return(View(vmcreateproperty)); }
// GET: VacProperties/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VacProperty vacProperty = db.VacProperties.Find(id); if (vacProperty == null) { return(HttpNotFound()); } return(View(vacProperty)); }
// GET: VacProperties/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VacProperty vacProperty = db.VacProperties.Find(id); if (vacProperty == null) { return(HttpNotFound()); } ViewBag.LocationId = new SelectList(db.Locations, "Id", "Address", vacProperty.LocationId); return(View(vacProperty)); }
// GET: VacProperties/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VacProperty vacProperty = db.VacProperties.Include(l => l.Location.City.Region).Where(v => v.Id == id).FirstOrDefault(); if (vacProperty == null) { return(HttpNotFound()); } vacProperty.Galleries = db.Galleries.Include(v => v.VacProperty).Where(v => v.VacPropertyId == id).ToList(); return(View(vacProperty)); }
//--------------------------------------------------------- // CUSTOM METHODS //--------------------------------------------------------- private void PopulateSelectedAmenities(VacProperty vproperty) { var allAmenities = db.Amenities; var vpropertyAmenities = new HashSet <int>(vproperty.Amenities.Select(c => c.Id)); //a set that contains no duplicate elements var viewModel = new List <SelectedAmenityData>(); foreach (var amenity in allAmenities) { viewModel.Add(new SelectedAmenityData { AmenityID = amenity.Id, Title = amenity.Title, Picked = vpropertyAmenities.Contains(amenity.Id) }); } ViewBag.Amenities = viewModel; }