Esempio n. 1
0
        public IActionResult Delete(Guid domesticUnitID)
        {
            DomesticUnit deletedDomesticUnit = repository.DeleteDomesticUnit(domesticUnitID);

            if (deletedDomesticUnit != null)
            {
                TempData["message"] = $"{deletedDomesticUnit.Name} was deleted";
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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));
     }
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
 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();
 }
Esempio n. 6
0
        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));
        }