public IActionResult Create(int communityId) { var model = new ApartMentViewModel { CommunityId = communityId }; ViewData["BLOCK_NAMES"] = new SelectList(Blocks(communityId), "Value", "Text"); return(View("Views/Communities/Apartments/Create.cshtml", model)); }
public IActionResult Delete(ApartMentViewModel model) { var apartment = _adminDatabaseContext.Flats.Include(f => f.Block).ThenInclude(b => b.Community) .First(f => f.Id == model.ApartMentId); _adminDatabaseContext.Flats.Remove(apartment); _adminDatabaseContext.SaveChanges(); return(RedirectToAction("Details", "Communities", new { communityId = apartment.Block.Community.CommunityId })); }
public IActionResult Create(ApartMentViewModel model) { if (ModelState.IsValid) { var block = _adminDatabaseContext.Blocks.Include(b => b.Community).First(b => b.Id == model.BlockId); var flat = new Apartment { Number = model.Number, IsRented = model.IsRented, Block = block }; _adminDatabaseContext.Flats.Add(flat); _adminDatabaseContext.SaveChanges(); return(RedirectToAction("Details", "Communities", new { communityId = block.Community.CommunityId })); } return(View("Views/Communities/Apartments/Create.cshtml", model)); }
public IActionResult Edit(ApartMentViewModel model) { if (ModelState.IsValid) { var apartment = _adminDatabaseContext.Flats.Include(b => b.Block).First(f => f.Id == model.ApartMentId); apartment.Number = model.Number; apartment.IsRented = model.IsRented; if (apartment.Block.Id != model.BlockId) { apartment.Block = _adminDatabaseContext.Blocks.First(b => b.Id == model.BlockId); } _adminDatabaseContext.SaveChanges(); return(RedirectToAction("Details", "Communities", new { communityId = model.CommunityId })); } ViewData["BLOCK_NAMES"] = new SelectList(Blocks(model.CommunityId), "Value", "Text"); return(View("Views/Communities/Apartments/Edit.cshtml", model)); }