예제 #1
0
        public async Task <Maybe <T> > DeleteAsync(T entity)
        {
            HexadoDbContext.Set <T>().Remove(entity);
            await HexadoDbContext.SaveChangesAsync();

            return(entity.ToMaybe());
        }
예제 #2
0
        public virtual async Task <Maybe <T> > CreateAsync(T entity)
        {
            await HexadoDbContext.Set <T>().AddAsync(entity);

            await HexadoDbContext.SaveChangesAsync();

            return(entity.ToMaybe());
        }
예제 #3
0
        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);
        }
예제 #4
0
        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());
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
 public async Task ClearAsync()
 {
     HexadoDbContext.Set <T>().RemoveRange(HexadoDbContext.Set <T>());
     await HexadoDbContext.SaveChangesAsync();
 }