Exemple #1
0
        public dynamic Insert(GeneralLeave model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.GeneralLeave, 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 = _generalLeaveService.CreateObject(model);
            }
            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
            }));
        }
Exemple #2
0
        public dynamic GetDefaultInfo()
        {
            GeneralLeave model = new GeneralLeave();

            try
            {
                model = _generalLeaveService.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.StartDate,
                model.EndDate,
                model.Remark,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
 public GeneralLeave VHasStartDate(GeneralLeave generalLeave)
 {
     if (generalLeave.StartDate == null || generalLeave.StartDate.Equals(DateTime.FromBinary(0)))
     {
         generalLeave.Errors.Add("StartDate", "Tidak valid");
     }
     return(generalLeave);
 }
Exemple #4
0
 public GeneralLeave VHasRemark(GeneralLeave generalLeave)
 {
     if (String.IsNullOrEmpty(generalLeave.Remark) || generalLeave.Remark.Trim() == "")
     {
         generalLeave.Errors.Add("Remark", "Tidak boleh kosong");
     }
     return(generalLeave);
 }
Exemple #5
0
 public GeneralLeave VHasEndDate(GeneralLeave generalLeave)
 {
     if (generalLeave.EndDate == null || generalLeave.EndDate.Equals(DateTime.FromBinary(0)))
     {
         generalLeave.Errors.Add("EndDate", "Tidak valid");
     }
     else if (generalLeave.EndDate.Date < generalLeave.StartDate.Date)
     {
         generalLeave.Errors.Add("EndDate", "Harus lebih besar atau sama dengan Start Date");
     }
     return(generalLeave);
 }
Exemple #6
0
        public string PrintError(GeneralLeave 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);
        }
Exemple #7
0
 public bool ValidCreateObject(GeneralLeave generalLeave)
 {
     VHasRemark(generalLeave);
     if (!isValid(generalLeave))
     {
         return(false);
     }
     VHasStartDate(generalLeave);
     if (!isValid(generalLeave))
     {
         return(false);
     }
     VHasEndDate(generalLeave);
     return(isValid(generalLeave));
 }
Exemple #8
0
        public dynamic Update(GeneralLeave model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.GeneralLeave, 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 = _generalLeaveService.GetObjectById(model.Id);
                data.StartDate = model.StartDate;
                data.EndDate   = model.EndDate;
                data.Remark    = model.Remark;
                model          = _generalLeaveService.UpdateObject(data);
            }
            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
            }));
        }
Exemple #9
0
        public bool isValid(GeneralLeave obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }
Exemple #10
0
 public bool ValidDeleteObject(GeneralLeave generalLeave)
 {
     generalLeave.Errors.Clear();
     return(isValid(generalLeave));
 }
Exemple #11
0
 public bool ValidUpdateObject(GeneralLeave generalLeave)
 {
     generalLeave.Errors.Clear();
     ValidCreateObject(generalLeave);
     return(isValid(generalLeave));
 }
Exemple #12
0
 public bool isValid(GeneralLeave obj)
 {
     //   bool isValid = !obj.Errors.Any();
     return(true);
 }
 public GeneralLeave SoftDeleteObject(GeneralLeave generalLeave)
 {
     return(generalLeave = _validator.ValidDeleteObject(generalLeave) ?
                           _repository.SoftDeleteObject(generalLeave) : generalLeave);
 }
 public GeneralLeave UpdateObject(GeneralLeave generalLeave)
 {
     return(generalLeave = _validator.ValidUpdateObject(generalLeave) ? _repository.UpdateObject(generalLeave) : generalLeave);
 }
 public GeneralLeave CreateObject(GeneralLeave generalLeave)
 {
     generalLeave.Errors = new Dictionary <String, String>();
     return(_validator.ValidCreateObject(generalLeave) ? _repository.CreateObject(generalLeave) : generalLeave);
 }