public async Task <User> GetByEmail(string email) { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { return(await context.Users.FirstOrDefaultAsync(u => u.Email == email)); } }
public async Task <User> GetByUserName(string username) { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { return(await context.Users.FirstOrDefaultAsync(u => u.Username == username)); } }
public async Task <T> Get(int id) { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.ID == id); return(entity); } }
public async Task <IEnumerable <T> > GetAll() { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { IEnumerable <T> entities = await context.Set <T>().ToListAsync(); return(entities); } }
public async Task <IEnumerable <Color> > GetColorForAdditionalPrice() { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { IEnumerable <Color> colorsForAdditionalPrice = await context.Colors .Where(c => c.ForAdditionalMoney) .ToListAsync(); return(colorsForAdditionalPrice); } }
public async Task <IEnumerable <Color> > GetFreeColor() { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { IEnumerable <Color> freeColors = await context.Colors .Where(c => c.ForAdditionalMoney == false) .ToListAsync(); return(freeColors); } }
public async Task <T> Create(T entity) { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdResult.Entity); } }
public async Task <bool> Delete(int id) { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.ID == id); context.Set <T>().Remove(entity); await context.SaveChangesAsync(); return(true); } }
public async Task <T> Update(int id, T entity) { using (OrderBoatNewDbContext context = _contextFactory.CreateDbContext()) { entity.ID = id; context.Set <T>().Update(entity); await context.SaveChangesAsync(); return(entity); } }