public DTO.Animal CreateAnimal(DTO.Animal animal) { using (var context = new SaguContext()) { context.Animals.Add(animal.AsEntity()); context.SaveChanges(); return animal; } }
public DTO.ExploredArea CreateExploredArea(DTO.ExploredArea area) { using (var context = new SaguContext()) { context.ExploredAreas.Add(area.AsEntity()); context.SaveChanges(); return area; } }
public DTO.Area CreateArea(DTO.Area area) { using (var context = new SaguContext()) { var newArea = context.Areas.Add(area.AsEntity()); context.SaveChanges(); return newArea.AsDTO(); } }
public void DeleteAnimal(Guid id) { using (var context = new SaguContext()) { var animalToRemove = context.Animals.Find(id); if (animalToRemove == null) throw new KeyNotFoundException(); context.Animals.Remove(animalToRemove); context.SaveChanges(); } }
public void DeleteExplorer(Guid id) { using (var context = new SaguContext()) { var explorerToRemove = context.Explorers.Find(id); if (explorerToRemove == null) throw new KeyNotFoundException(); context.Explorers.Remove(explorerToRemove); context.SaveChanges(); } }
public DTO.Explorer CreateExplorer(DTO.Explorer explorer) { explorer.Id = Guid.NewGuid(); explorer.Level = 1; using (var context = new SaguContext()) { var newExplorer = context.Explorers.Add(explorer.AsEntity()); context.SaveChanges(); return newExplorer.AsDTO(); } }
public DTO.ExploredArea UpdateExploredArea(DTO.ExploredArea area) { using (var context = new SaguContext()) { var areaToUpdate = context.ExploredAreas.Find(area.Id); if (areaToUpdate == null) throw new KeyNotFoundException(); areaToUpdate.AmountExplored = area.AmountExplored; context.SaveChanges(); return area; } }
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; } }