Пример #1
0
        public override async Task <Guarantee> Get(int id)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            Guarantee entry = await context.Guarantees.Include(b => b.Customer).FirstOrDefaultAsync(c => c.ID == id);

            return(entry);
        }
Пример #2
0
        public async Task <IEnumerable <ServiceItem> > GetByCustomer(int customerID)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            IEnumerable <ServiceItem> entities = await context.Set <ServiceItem>().Include(b => b.Customer).Where(c => c.Customer.ID == customerID).ToListAsync();

            return(entities);
        }
Пример #3
0
        public override async Task <IEnumerable <Guarantee> > GetAll()
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            IEnumerable <Guarantee> entities = await context.Set <Guarantee>().Include(b => b.Customer).ToListAsync();

            return(entities);
        }
Пример #4
0
        public override async Task <ServiceItem> Get(int id)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            ServiceItem entity = await context.Set <ServiceItem>().Include(c => c.Customer).FirstOrDefaultAsync(e => e.ID == id);

            return(entity);
        }
Пример #5
0
        public virtual async Task <T> Get(int id)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            T entity = await context.Set <T>().FirstOrDefaultAsync(e => e.ID == id);

            return(entity);
        }
Пример #6
0
        public virtual async Task <IEnumerable <T> > GetAll()
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            IEnumerable <T> entities = await context.Set <T>().ToListAsync();

            return(entities);
        }
Пример #7
0
        public override async Task <Guarantee> Create(Guarantee entity)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            EntityEntry <Guarantee> createdEntity = context.Guarantees.Attach(entity);
            await context.SaveChangesAsync();

            return(createdEntity.Entity);
        }
Пример #8
0
        public override async Task <ServiceItem> Create(ServiceItem entity)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            EntityEntry <ServiceItem> createdEntity = context.ServiceItems.Attach(entity);
            await context.SaveChangesAsync();

            return(createdEntity.Entity);
        }
Пример #9
0
        public virtual async Task <T> Update(int id, T entity)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            entity.ID = id;
            context.Set <T>().Update(entity);
            await context.SaveChangesAsync();

            return(entity);
        }
Пример #10
0
        public virtual async Task <T> Create(T entity)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            EntityEntry <T> createdEntity = await context.Set <T>().AddAsync(entity);

            await context.SaveChangesAsync();

            return(createdEntity.Entity);
        }
Пример #11
0
        public override async Task <Guarantee> Update(int id, Guarantee entity)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            entity.ID = id;
            context.Guarantees.Update(entity);
            context.Entry(entity).Reference(e => e.Customer).IsModified = true;
            await context.SaveChangesAsync();

            return(entity);
        }
Пример #12
0
        public async Task <int> GetVirtualID(GuaranteeType newDetailsGuaranteeType)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();

            if (await context.Guarantees.CountAsync(it => it.GuaranteeType == newDetailsGuaranteeType) == 0)
            {
                return(0);
            }

            int maxID = await context.Guarantees.Where(it => it.GuaranteeType == newDetailsGuaranteeType).MaxAsync(it => it.VirtualID);

            return(maxID + 1);
        }
Пример #13
0
        public virtual async Task <bool> Delete(int id)
        {
            await using SMGAppDbContext context = ContextFactory.CreateDbContext();
            T entityToDelete = await context.Set <T>().FirstOrDefaultAsync(e => e.ID == id);

            if (entityToDelete == null)
            {
                return(false);
            }
            context.Set <T>().Remove(entityToDelete);
            await context.SaveChangesAsync();

            return(true);
        }