public void Add(Breed breed) { using (var context = new LupiDbContext()) { context.Breeds.Add(breed); context.SaveChanges(); } }
// POST: api/Breeds public void Post([FromBody] Breed breed) { using (LupiDbContext context = new LupiDbContext()) { Guid breedId = Guid.NewGuid(); breed.Id = breedId; context.Breeds.Add(breed); context.SaveChanges(); } }
public bool DeleteById(Guid id) { using (var context = new LupiDbContext()) { Breed breed = context.Breeds.FirstOrDefault(p => p.Id == id); if (breed == null) { return(false); } context.Breeds.Remove(breed); context.SaveChanges(); return(true); } }
public bool Update(Guid id, Breed newBreed) { using (var context = new LupiDbContext()) { Breed originalBreed = context.Breeds.FirstOrDefault(p => p.Id == id); if (originalBreed == null) { return(false); } originalBreed.HairColors = newBreed.HairColors; originalBreed.HairType = newBreed.HairType; originalBreed.Name = newBreed.Name; context.SaveChanges(); return(true); } }