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 })); }
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)); }
public GeneralLeave VHasStartDate(GeneralLeave generalLeave) { if (generalLeave.StartDate == null || generalLeave.StartDate.Equals(DateTime.FromBinary(0))) { generalLeave.Errors.Add("StartDate", "Tidak valid"); } return(generalLeave); }
public GeneralLeave VHasRemark(GeneralLeave generalLeave) { if (String.IsNullOrEmpty(generalLeave.Remark) || generalLeave.Remark.Trim() == "") { generalLeave.Errors.Add("Remark", "Tidak boleh kosong"); } return(generalLeave); }
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); }
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); }
public bool ValidCreateObject(GeneralLeave generalLeave) { VHasRemark(generalLeave); if (!isValid(generalLeave)) { return(false); } VHasStartDate(generalLeave); if (!isValid(generalLeave)) { return(false); } VHasEndDate(generalLeave); return(isValid(generalLeave)); }
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 })); }
public bool isValid(GeneralLeave obj) { bool isValid = !obj.Errors.Any(); return(isValid); }
public bool ValidDeleteObject(GeneralLeave generalLeave) { generalLeave.Errors.Clear(); return(isValid(generalLeave)); }
public bool ValidUpdateObject(GeneralLeave generalLeave) { generalLeave.Errors.Clear(); ValidCreateObject(generalLeave); return(isValid(generalLeave)); }
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); }