public ActionResult ChooseDomesticUnit(SimDomesticUnitViewModel simDomesticUnit) { SimLives simLives = new SimLives { SimID = simDomesticUnit.Sim.SimID, DomesticUnitID = simDomesticUnit.DomesticUnitID }; simLives.Sim = repository.Sims .FirstOrDefault(s => s.SimID == simLives.SimID); simLives.DomesticUnit = repository.DomesticUnits .FirstOrDefault(d => d.DomesticUnitID == simDomesticUnit.DomesticUnitID); if (ModelState.IsValid) { repository.SaveSimLives(simLives); TempData["message"] = $"{simLives.Sim.Name} now lives in {simLives.DomesticUnit.Name}"; return(RedirectToAction("Index")); } else { //if enters here there is something wrong with the data values return(View(simDomesticUnit)); } }
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)); }