Exemplo n.º 1
0
        public async Task <ActionResult <List <T> > > GetAllEntities()
        {
            using (HRMContext context = new HRMContext())
            {
                return(await context.Set <T>().ToListAsync());
            }

            //return await _context.Aministrativearea.ToListAsync();
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        //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);
            }
        }
Exemplo n.º 5
0
 public Repository(HRMContext context)
 {
     DbContext = context;
     DbSet     = DbContext.Set <TEntity>();
 }