public IActionResult Delete(Guid domesticUnitID) { DomesticUnit deletedDomesticUnit = repository.DeleteDomesticUnit(domesticUnitID); if (deletedDomesticUnit != null) { TempData["message"] = $"{deletedDomesticUnit.Name} was deleted"; } return(RedirectToAction("Index")); }
public DomesticUnit DeleteDomesticUnit(Guid domesticUnitID) { DomesticUnit dbEntry = context.DomesticUnits .FirstOrDefault(d => d.DomesticUnitID == domesticUnitID); if (dbEntry != null) { context.DomesticUnits.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public IActionResult Edit(DomesticUnit domesticUnit) { if (ModelState.IsValid) { repository.SaveDomesticUnit(domesticUnit); TempData["message"] = $"{domesticUnit.Name} has been saved"; return(RedirectToAction("Index")); } else { // if enters here there is something wrong with the data values return(View(domesticUnit)); } }
public ViewResult DomesticUnit(Guid id) { PetDomesticUnitViewModel viewModel = new PetDomesticUnitViewModel { Pet = repository.Pets.FirstOrDefault(p => p.PetID == id) }; PetLives relation = repository.PetLivesTable .FirstOrDefault(p => p.PetID == id); viewModel.DomesticUnits = relation == null ? repository.DomesticUnits : repository.DomesticUnits.Where(d => d.DomesticUnitID != relation.DomesticUnitID); if (relation != null) { DomesticUnit domesticUnit = repository.DomesticUnits .FirstOrDefault(d => d.DomesticUnitID == relation.DomesticUnitID); viewModel.CurrentDomesticUnitName = domesticUnit.Name; } return(View(viewModel)); }
public void SaveDomesticUnit(DomesticUnit domesticUnit) { if (domesticUnit.DomesticUnitID.CompareTo(Guid.Empty) == 0) { context.DomesticUnits.Add(domesticUnit); } else { DomesticUnit dbEntry = context.DomesticUnits .FirstOrDefault(d => d.DomesticUnitID == domesticUnit.DomesticUnitID); if (dbEntry != null) { dbEntry.Name = domesticUnit.Name; dbEntry.RoomNumber = domesticUnit.RoomNumber; dbEntry.BathroomNumber = domesticUnit.BathroomNumber; dbEntry.Description = domesticUnit.Description; } } context.SaveChanges(); }
public ViewResult ChooseDomesticUnit(Guid id) { SimDomesticUnitViewModel simDomesticUnit = new SimDomesticUnitViewModel { Sim = repository.Sims.FirstOrDefault(s => s.SimID == id) }; SimLives simLives = repository.SimLivesTable .FirstOrDefault(s => s.SimID == simDomesticUnit.Sim.SimID); simDomesticUnit.DomesticUnits = simLives == null ? repository.DomesticUnits : repository.DomesticUnits.Where(d => d.DomesticUnitID != simLives.DomesticUnitID); if (simLives != null) { DomesticUnit domesticUnit = repository.DomesticUnits .FirstOrDefault(d => d.DomesticUnitID == simLives.DomesticUnitID); simDomesticUnit.CurrentDomesticUnitName = domesticUnit.Name; } return(View(simDomesticUnit)); }