public async Task <Dictionary <int, string> > GetSpeciesDictionaryAsync() { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { return(await context.Species.ToDictionaryAsync(x => x.Id, x => x.Name)); } }
public async Task <IEnumerable <AnimalModel> > GetAllAnimalFilteredAsync(List <Expression <Func <Animal, bool> > > filters) { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { var query = context.Animals.AsQueryable(); foreach (var filter in filters) { query = query.Where(filter); } return(await query .Select(animal => new AnimalModel { Id = animal.Id, Name = animal.Name, IdentificationNumber = animal.IdentificationNumber, Age = animal.Age, AnimalSex = animal.AnimalSex, SpeciesId = animal.SpeciesId, SpeciesName = animal.Species.Name, Race = animal.Race, Location = animal.Location }).ToListAsync()); } }
public async Task <IEnumerable <string> > GetAllRaceAsync() { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { return(await context.Animals.Select(x => x.Race).Distinct().ToListAsync()); } }
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); } }
public async Task <IEnumerable <SpeciesModel> > GetAllSpeciesDisplayableAsync() { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { IEnumerable <SpeciesModel> entities = await context.Species.Select(species => new SpeciesModel { Id = species.Id, Name = species.Name, AnimalCount = species.Animals.Count, AuthorizedKills = species.NbMaxAuthorizedKills }).ToListAsync(); return(entities); } }
public async Task <IEnumerable <AnimalModel> > GetAllAnimalsDisplayableAsync() { using (GestionAnimalDbContext context = _contextFactory.CreateDbContext()) { IEnumerable <AnimalModel> entities = await context.Animals.Select(animal => new AnimalModel { Id = animal.Id, Name = animal.Name, Age = animal.Age, AnimalSex = animal.AnimalSex, IdentificationNumber = animal.IdentificationNumber, Location = animal.Location, Race = animal.Race, SpeciesId = animal.SpeciesId, SpeciesName = animal.Species.Name }).ToListAsync(); return(entities); } }