Exemplo n.º 1
0
        public dynamic DeleteDetail(THRDetail model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.THR, Core.Constants.Constant.MenuGroupName.Utility))
                {
                    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 = _thrDetailService.GetObjectById(model.Id);
                model = _thrDetailService.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,
            }));
        }
Exemplo n.º 2
0
        public dynamic GetInfoDetail(int Id)
        {
            THRDetail model = new THRDetail();

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

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

            return(Json(new
            {
                model.Id,
                model.THRId,
                model.EmployeeId,
                EmployeeNIK = model.Employee.NIK,
                EmployeeName = model.Employee.Name,
                EmployeeReligion = model.Employee.Religion,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public dynamic InsertDetail(THRDetail model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.THR, Core.Constants.Constant.MenuGroupName.Utility))
                {
                    Dictionary <string, string> Errors = new Dictionary <string, string>();
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }
                model = _thrDetailService.CreateObject(model, _thrService, _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,
            }));
        }
Exemplo n.º 4
0
        public THRDetail VHasTHR(THRDetail thrDetail, ITHRService _thrService)
        {
            THR thr = _thrService.GetObjectById(thrDetail.THRId);

            if (thr == null)
            {
                thrDetail.Errors.Add("THR", "Tidak ada");
            }
            return(thrDetail);
        }
Exemplo n.º 5
0
        //public THRDetail VHasAmount(THRDetail thrDetail)
        //{
        //    if (thrDetail.Amount < 0)
        //    {
        //        thrDetail.Errors.Add("Amount", "Harus lebih besar atau sama dengan 0");
        //    }
        //    return thrDetail;
        //}

        public bool ValidCreateObject(THRDetail thrDetail, ITHRService _thrService, IEmployeeService _employeeService, ITHRDetailService _thrDetailService)
        {
            VHasTHR(thrDetail, _thrService);
            if (!isValid(thrDetail))
            {
                return(false);
            }
            VHasEmployee(thrDetail, _employeeService, _thrDetailService);
            //if (!isValid(thrDetail)) { return false; }
            //VHasAmount(thrDetail);
            return(isValid(thrDetail));
        }
Exemplo n.º 6
0
        public string PrintError(THRDetail 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);
        }
Exemplo n.º 7
0
        public THRDetail VHasEmployee(THRDetail thrDetail, IEmployeeService _employeeService, ITHRDetailService _thrDetailService)
        {
            Employee employee = _employeeService.GetObjectById(thrDetail.EmployeeId);

            if (employee == null)
            {
                thrDetail.Errors.Add("Employee", "Tidak ada");
            }
            else
            {
                THRDetail thrDetail2 = _thrDetailService.GetObjectByEmployeeIdAndTHRId(thrDetail.EmployeeId, thrDetail.THRId);
                if (thrDetail2 != null)
                {
                    thrDetail.Errors.Add("Employee", "Sudah ada");
                }
            }
            return(thrDetail);
        }
Exemplo n.º 8
0
        public dynamic InsertManyDetails(int id, List <int> selIDs)
        {
            Dictionary <string, string> Errors = new Dictionary <string, string>();

            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.THR, Core.Constants.Constant.MenuGroupName.Utility))
                {
                    Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        Errors
                    }, JsonRequestBehavior.AllowGet));
                }
                THRDetail model = null;
                foreach (var eid in selIDs)
                {
                    model = new THRDetail
                    {
                        EmployeeId = eid,
                        THRId      = id,
                    };
                    model = _thrDetailService.CreateObject(model, _thrService, _employeeService);
                }
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                Errors.Add("Generic", "Error " + ex);

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

            return(Json(new
            {
                Errors,
            }));
        }
Exemplo n.º 9
0
 public THRDetail SoftDeleteObject(THRDetail thrDetail)
 {
     return(thrDetail = _validator.ValidDeleteObject(thrDetail) ?
                        _repository.SoftDeleteObject(thrDetail) : thrDetail);
 }
Exemplo n.º 10
0
 public THRDetail UpdateObject(THRDetail thrDetail, ITHRService _thrService, IEmployeeService _employeeService)
 {
     return(thrDetail = _validator.ValidUpdateObject(thrDetail, _thrService, _employeeService, this) ? _repository.UpdateObject(thrDetail) : thrDetail);
 }
Exemplo n.º 11
0
 public THRDetail CreateObject(THRDetail thrDetail, ITHRService _thrService, IEmployeeService _employeeService)
 {
     thrDetail.Errors = new Dictionary <String, String>();
     return(_validator.ValidCreateObject(thrDetail, _thrService, _employeeService, this) ? _repository.CreateObject(thrDetail) : thrDetail);
 }
Exemplo n.º 12
0
        public bool isValid(THRDetail obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }
Exemplo n.º 13
0
 public bool ValidDeleteObject(THRDetail thrDetail)
 {
     thrDetail.Errors.Clear();
     return(isValid(thrDetail));
 }
Exemplo n.º 14
0
 public bool ValidUpdateObject(THRDetail thrDetail, ITHRService _thrService, IEmployeeService _employeeService, ITHRDetailService _thrDetailService)
 {
     thrDetail.Errors.Clear();
     ValidCreateObject(thrDetail, _thrService, _employeeService, _thrDetailService);
     return(isValid(thrDetail));
 }