Exemple #1
0
        public async Task <string> Post()
        {
            var             req       = Request;
            DtRequest       dtRequest = new DtRequest(Request.Form);
            List <Employee> employees = GetObj <Employee>(dtRequest.Data);

            if (dtRequest.Action.ToLower() == "create")
            {
                foreach (Employee employee in employees)
                {
                    _context.Add(employee);
                }
                await _context.SaveChangesAsync();
            }
            else if (dtRequest.Action.ToLower() == "edit")
            {
                foreach (Employee employee in employees)
                {
                    if (employee.Id > 0)
                    {
                        _context.Employees.Update(employee);
                        await _context.SaveChangesAsync();
                    }
                }
            }

            return(GetEmployeeForDataTable(employees));
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Chỉnh sửa 1 bản ghi theo id và thôgn tin mới
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="id"></param>
        /// <param name="tEntity"></param>
        /// <returns></returns>
        public async Task <ActionResult <bool> > ChangeAnEntityByID <T1>(Guid id, T1 tEntity) where T1 : class
        {
            using (HRMContext context = new HRMContext())
            {
                //Tim xem idz`
                context.Entry(tEntity).State = EntityState.Modified;
                var res = await context.SaveChangesAsync();

                if (res < 1)
                {
                    return(false);
                }
                return(true);
                //return new ActionServiceResult((int)HttpStatusCode.OK, true, "Cập nhật thành công");
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
0
 public async static Task WriteAuditLog(AuditLog auditLog)
 {
     try
     {
         using (HRMContext db = new HRMContext())
         {
             auditLog.Id          = Guid.NewGuid();
             auditLog.LogDateTime = DateTime.UtcNow;
             db.AuditLogs.Add(auditLog);
             await db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         WriteErrorLog(new ErrorLog()
         {
             ErrorFor     = "Writing Audit Log",
             ErrorFrom    = "Utility.WriteAuditLog",
             ErrorMessage = "Exception: " + ex.Message
         });
     }
 }
Exemple #6
0
 public Task SaveChangesAsync()
 {
     return(DbContext.SaveChangesAsync());
 }