public async Task <Species> CreateAsync(Species entity) { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { Species createdEntity = context.Species.Add(entity); await context.SaveChangesAsync(); return(createdEntity); } }
public async Task <Animal> CreateAsync(Animal entity) { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { Animal createdEntity = context.Animals.Add(entity); await context.SaveChangesAsync(); return(createdEntity); } }
public async Task <Species> UpdateAsync(int id, Species entity) { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { entity.Id = id; context.Species.AddOrUpdate(entity); await context.SaveChangesAsync(); return(entity); } }
public async Task <bool> DeleteAsync(int id) { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { Species entity = await context.Set <Species>().FirstOrDefaultAsync(x => x.Id == id); if (entity != null) { context.Species.Remove(entity); } await context.SaveChangesAsync(); return(true); } }