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); }
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); }
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); }
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); }
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); }
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); }