Пример #1
0
        public dynamic Insert(SPKL model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.SPKL, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Add record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                model = _spklService.CreateObject(model, _employeeService);
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Пример #2
0
        public dynamic GetDefaultInfo()
        {
            SPKL model = new SPKL();

            try
            {
                model = _spklService.GetQueryable().FirstOrDefault();
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Id,
                model.EmployeeId,
                EmployeeNIK = model.Employee.NIK,
                EmployeeName = model.Employee.Name,
                model.StartTime,
                model.EndTime,
                model.OverTimeInterval,
                model.Remark,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
 public SPKL VHasStartTime(SPKL spkl)
 {
     if (spkl.StartTime == null || spkl.StartTime.Equals(DateTime.FromBinary(0)))
     {
         spkl.Errors.Add("StartTime", "Tidak valid");
     }
     return(spkl);
 }
Пример #4
0
 public SPKL VHasRemark(SPKL spkl)
 {
     if (String.IsNullOrEmpty(spkl.Remark) || spkl.Remark.Trim() == "")
     {
         spkl.Errors.Add("Remark", "Tidak boleh kosong");
     }
     return(spkl);
 }
Пример #5
0
 public SPKL UpdateObject(SPKL spkl, IEmployeeService _employeeService)
 {
     if (_validator.ValidUpdateObject(spkl, _employeeService))
     {
         spkl.OverTimeInterval = (decimal)spkl.EndTime.Subtract(spkl.StartTime).TotalMinutes;
         _repository.UpdateObject(spkl);
     }
     return(spkl);
 }
Пример #6
0
 public SPKL CreateObject(SPKL spkl, IEmployeeService _employeeService)
 {
     spkl.Errors = new Dictionary <String, String>();
     if (_validator.ValidCreateObject(spkl, _employeeService))
     {
         spkl.OverTimeInterval = (decimal)spkl.EndTime.Subtract(spkl.StartTime).TotalMinutes;
         _repository.CreateObject(spkl);
     }
     return(spkl);
 }
Пример #7
0
        public SPKL VHasEmployee(SPKL spkl, IEmployeeService _employeeService)
        {
            Employee employee = _employeeService.GetObjectById(spkl.EmployeeId);

            if (employee == null)
            {
                spkl.Errors.Add("Employee", "Tidak ada");
            }
            return(spkl);
        }
Пример #8
0
 public SPKL VHasEndTime(SPKL spkl)
 {
     if (spkl.EndTime == null || spkl.EndTime.Equals(DateTime.FromBinary(0)))
     {
         spkl.Errors.Add("EndTime", "Tidak valid");
     }
     else if (spkl.EndTime.Date < spkl.StartTime.Date)
     {
         spkl.Errors.Add("EndTime", "Harus lebih besar atau sama dengan Start Time");
     }
     return(spkl);
 }
Пример #9
0
        public string PrintError(SPKL obj)
        {
            string erroroutput = "";
            KeyValuePair <string, string> first = obj.Errors.ElementAt(0);

            erroroutput += first.Key + "," + first.Value;
            foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1))
            {
                erroroutput += Environment.NewLine;
                erroroutput += pair.Key + "," + pair.Value;
            }
            return(erroroutput);
        }
Пример #10
0
 public bool ValidCreateObject(SPKL spkl, IEmployeeService _employeeService)
 {
     VHasEmployee(spkl, _employeeService);
     if (!isValid(spkl))
     {
         return(false);
     }
     VHasRemark(spkl);
     if (!isValid(spkl))
     {
         return(false);
     }
     VHasStartTime(spkl);
     if (!isValid(spkl))
     {
         return(false);
     }
     VHasEndTime(spkl);
     return(isValid(spkl));
 }
Пример #11
0
        public dynamic Update(SPKL model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.SPKL, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _spklService.GetObjectById(model.Id);
                data.EmployeeId = model.EmployeeId;
                data.StartTime  = model.StartTime;
                data.EndTime    = model.EndTime;
                //data.OverTimeInterval = model.OverTimeInterval;
                data.Remark = model.Remark;
                model       = _spklService.UpdateObject(data, _employeeService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Пример #12
0
        public dynamic Delete(SPKL model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.SPKL, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Delete Record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _spklService.GetObjectById(model.Id);
                model = _spklService.SoftDeleteObject(data);
            }

            catch (Exception ex)
            {
                LOG.Error("Delete Failed", ex);
                Dictionary <string, string> Errors = new Dictionary <string, string>();
                Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    Errors
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Errors
            }));
        }
Пример #13
0
 public SPKL SoftDeleteObject(SPKL spkl)
 {
     return(spkl = _validator.ValidDeleteObject(spkl) ?
                   _repository.SoftDeleteObject(spkl) : spkl);
 }
Пример #14
0
        public bool isValid(SPKL obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }
Пример #15
0
 public bool ValidDeleteObject(SPKL spkl)
 {
     spkl.Errors.Clear();
     return(isValid(spkl));
 }
Пример #16
0
 public bool ValidUpdateObject(SPKL spkl, IEmployeeService _employeeService)
 {
     spkl.Errors.Clear();
     ValidCreateObject(spkl, _employeeService);
     return(isValid(spkl));
 }