public async Task <ActionResult <List <T> > > GetAllEntities() { using (HRMContext context = new HRMContext()) { return(await context.Set <T>().ToListAsync()); } //return await _context.Aministrativearea.ToListAsync(); }
public async Task <ActionResult <bool> > DeleteEntỉtyByID(Guid id) { using (HRMContext context = new HRMContext()) { //Tìm xem bản ghi có trong DB hay không var aministrativearea = await context.Set <T>().FindAsync(id); if (aministrativearea == null) { return(false); } context.Set <T>().Remove(aministrativearea); var resDelete = await context.SaveChangesAsync(); if (resDelete < 1) { return(false); } return(true); } }
/// <summary> /// Lấy 1 bản ghi theo ID /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <ActionResult <T> > GetEntityByID(Guid id) { using (HRMContext context = new HRMContext()) { var aministrativearea = await context.Set <T>().FindAsync(id); if (aministrativearea == null) { return(null); } return(aministrativearea); } }
//Tạo mới 1 bản ghi public async Task <ActionResult <bool> > CreateEntity <T1>(T1 tEntity) where T1 : class { using (HRMContext context = new HRMContext()) { context.Set <T1>().Add(tEntity); var count = await context.SaveChangesAsync(); if (count < 1) { return(false); } return(true); } }
public Repository(HRMContext context) { DbContext = context; DbSet = DbContext.Set <TEntity>(); }