public DTO.Animal UpdateAnimal(DTO.Animal animal) { using (var context = new SaguContext()) { var animalToUpdate = context.Animals.Find(animal.Id); if (animalToUpdate == null) throw new KeyNotFoundException(); context.Entry(animalToUpdate).CurrentValues.SetValues(animal); context.SaveChanges(); return animal; } }
public DTO.Explorer UpdateExplorer(DTO.Explorer explorer) { using (var context = new SaguContext()) { var explorerToUpdate = context.Explorers.Find(explorer.Id); if (explorerToUpdate == null) throw new KeyNotFoundException(); context.Entry(explorerToUpdate).CurrentValues.SetValues(explorer); context.SaveChanges(); return explorer; } }
public DTO.Area UpdateArea(DTO.Area area) { using (var context = new SaguContext()) { var areaToUpdate = context.Areas.Include(a => a.Image).FirstOrDefault(a => a.Id == area.Id); if (areaToUpdate == null) throw new KeyNotFoundException(); areaToUpdate.Image = area.Image.Get(i => i.AsEntity()) ?? areaToUpdate.Image; context.Entry(areaToUpdate).CurrentValues.SetValues(area); context.SaveChanges(); return area; } }