Example #1
0
        public object GetItem([FromBody] int id)
        {
            var msg = new JMessage()
            {
                Error = false, Title = ""
            };
            var data = _context.StaffTimetableWorkings.FirstOrDefault(x => x.Id == id);

            if (data != null)
            {
                var model = new SStaffTimeKeepingModel
                {
                    Id         = id,
                    UserId     = data.UserId,
                    Action     = data.Action,
                    ActionTime = data.ActionTime.ToString("dd/MM/yyyy"),
                    ActionTo   = data.ActionTo.HasValue ? data.ActionTo.Value.ToString("dd/MM/yyyy") : null,
                    Note       = data.Note,
                };
                msg.Object = model;
            }
            else
            {
                msg.Error = true;
                msg.Title = "Không tồn tại dữ liệu";
            }
            return(Json(msg));
        }
        public JsonResult CheckOut([FromBody] SStaffTimeKeepingModel obj)
        {
            var msg = new JMessage {
                Error = false, Title = ""
            };

            try
            {
                var model = new StaffTimetableWorking
                {
                    UserId     = obj.UserId,
                    Action     = "CHECKOUT",
                    ActionTime = DateTime.Now,
                    Note       = obj.Note,
                };
                _context.StaffTimetableWorkings.Add(model);
                _context.SaveChanges();
                msg.Title = "Checkout thành công!";
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = "Checkout lỗi!";
            }
            return(Json(msg));
        }
Example #3
0
        public JsonResult Update(SStaffTimeKeepingModel obj, IFormFile picture)
        {
            var msg = new JMessage {
                Error = false, Title = ""
            };

            try
            {
                if (obj.Action != "NOTWORK")
                {
                    var data = _context.StaffTimetableWorkings.FirstOrDefault(x => x.Id == obj.Id);
                    if (data != null)
                    {
                        data.UserId     = obj.UserId;
                        data.Action     = obj.Action;
                        data.ActionTime = !string.IsNullOrEmpty(obj.ActionTime) ? DateTime.ParseExact(obj.ActionTime, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;
                        data.Note       = obj.Note;
                    }
                    _context.StaffTimetableWorkings.Update(data);
                }
                else
                {
                    var data = _context.StaffTimetableWorkings.FirstOrDefault(x => x.Id == obj.Id);
                    if (data != null)
                    {
                        data.UserId     = obj.UserId;
                        data.Action     = obj.Action;
                        data.ActionTime = !string.IsNullOrEmpty(obj.ActionTime) ? DateTime.ParseExact(obj.ActionTime, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;
                        data.ActionTo   = !string.IsNullOrEmpty(obj.ActionTo) ? DateTime.ParseExact(obj.ActionTo, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now;
                        data.Note       = obj.Note;
                    }
                    _context.StaffTimetableWorkings.Update(data);
                }
                _context.SaveChanges();
                msg.Title = "Cập nhập chấm công thành công!";
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = "Cập nhập chấm công lỗi!";
            }
            return(Json(msg));
        }
Example #4
0
        public JsonResult Add(SStaffTimeKeepingModel obj, IFormFile picture)
        {
            var msg = new JMessage {
                Error = false, Title = ""
            };

            try
            {
                if (obj.Action != "NOTWORK")
                {
                    var model = new StaffTimetableWorking
                    {
                        UserId     = obj.UserId,
                        Action     = obj.Action,
                        ActionTime = !string.IsNullOrEmpty(obj.ActionTime) ? DateTime.ParseExact(obj.ActionTime, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now,
                        Note       = obj.Note,
                    };
                    _context.StaffTimetableWorkings.Add(model);
                }
                else
                {
                    var model = new StaffTimetableWorking
                    {
                        UserId     = obj.UserId,
                        Action     = obj.Action,
                        ActionTime = !string.IsNullOrEmpty(obj.ActionTime) ? DateTime.ParseExact(obj.ActionTime, "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.Now,
                        ActionTo   = !string.IsNullOrEmpty(obj.ActionTo) ? DateTime.ParseExact(obj.ActionTo, "dd/MM/yyyy", CultureInfo.InvariantCulture) : (DateTime?)null,
                        Note       = obj.Note,
                    };
                    _context.StaffTimetableWorkings.Add(model);
                }
                _context.SaveChanges();
                msg.Title = "Chấm công thành công!";
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = "Chấm công lỗi!";
            }
            return(Json(msg));
        }