public async Task <Maybe <T> > DeleteAsync(T entity) { HexadoDbContext.Set <T>().Remove(entity); await HexadoDbContext.SaveChangesAsync(); return(entity.ToMaybe()); }
public virtual async Task <Maybe <T> > CreateAsync(T entity) { await HexadoDbContext.Set <T>().AddAsync(entity); await HexadoDbContext.SaveChangesAsync(); return(entity.ToMaybe()); }
public virtual async Task <Maybe <T> > GetAsync(string id) { var entity = (await HexadoDbContext.Set <T>() .FindAsync(id)) .ToMaybe(); if (!entity.HasValue) { return(entity); } HexadoDbContext.Entry(entity.Value).State = EntityState.Detached; return(entity); }
public virtual async Task <Maybe <T> > UpdateAsync(T entity) { HexadoDbContext.Set <T>().Update(entity); await HexadoDbContext.SaveChangesAsync(); await HexadoDbContext.Entry(entity).ReloadAsync(); HexadoDbContext.Entry(entity).State = EntityState.Detached; return(entity.ToMaybe()); }
public virtual async Task <Maybe <T> > DeleteByIdAsync(string id) { var entityToDelete = await GetAsync(id); if (!entityToDelete.HasValue) { return(Maybe <T> .Nothing); } HexadoDbContext.Set <T>().Remove(entityToDelete.Value); await HexadoDbContext.SaveChangesAsync(); return(entityToDelete); }
public Maybe <IEnumerable <string> > GetCities() { var result = HexadoDbContext.Set <Event>() .GroupBy(p => new { p.Address.City }) .Select(x => x.Key.City) .ToList() .AsEnumerable() .ToMaybe(); return(result); }
public async Task ClearAsync() { HexadoDbContext.Set <T>().RemoveRange(HexadoDbContext.Set <T>()); await HexadoDbContext.SaveChangesAsync(); }