public dynamic GetDefaultInfo() { PPH21SPT model = new PPH21SPT(); try { model = _pph21sptService.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.Index, model.Code, model.Percent, model.MinAmount, model.IsInfiniteMaxAmount, model.MaxAmount, model.Description, model.Errors }, JsonRequestBehavior.AllowGet)); }
public dynamic Insert(PPH21SPT model) { try { if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.PPH21SPT, 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 = _pph21sptService.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 PPH21SPT VHasMinAmount(PPH21SPT pph21spt) { if (pph21spt.MinAmount < 0) { pph21spt.Errors.Add("MinAmount", "Harus lebih besar atau sama dengan 0"); } return(pph21spt); }
public PPH21SPT VHasMaxAmount(PPH21SPT pph21spt) { if (pph21spt.MaxAmount < pph21spt.MinAmount && !pph21spt.IsInfiniteMaxAmount) { pph21spt.Errors.Add("MaxAmount", "Harus lebih besar atau sama dengan MinAmount"); } return(pph21spt); }
public PPH21SPT VHasUniqueCode(PPH21SPT pph21spt, IPPH21SPTService _pph21sptService) { if (String.IsNullOrEmpty(pph21spt.Code) || pph21spt.Code.Trim() == "") { pph21spt.Errors.Add("Code", "Tidak boleh kosong"); } else if (_pph21sptService.IsCodeDuplicated(pph21spt)) { pph21spt.Errors.Add("Code", "Tidak boleh ada duplikasi"); } return(pph21spt); }
public PPH21SPT UpdateObject(PPH21SPT pph21spt) { if (_validator.ValidUpdateObject(pph21spt, this)) { if (pph21spt.IsInfiniteMaxAmount) { pph21spt.MaxAmount = 0; } _repository.UpdateObject(pph21spt); } return(pph21spt); }
public string PrintError(PPH21SPT 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 PPH21SPT CreateObject(string Code, decimal MinAmount, bool IsInfiniteMax, decimal MaxAmount, decimal Percent, string Desc) { PPH21SPT pph21spt = new PPH21SPT { Code = Code, MinAmount = MinAmount, IsInfiniteMaxAmount = IsInfiniteMax, MaxAmount = MaxAmount, Percent = Percent, Description = Desc, }; return(CreateObject(pph21spt)); }
public PPH21SPT CreateObject(PPH21SPT pph21spt) { pph21spt.Errors = new Dictionary <String, String>(); if (_validator.ValidCreateObject(pph21spt, this)) { //pph21spt.Index = GetQueryable().Count() + 1; if (pph21spt.IsInfiniteMaxAmount) { pph21spt.MaxAmount = 0; } _repository.CreateObject(pph21spt); } return(pph21spt); }
public bool ValidCreateObject(PPH21SPT pph21spt, IPPH21SPTService _pph21sptService) { VHasUniqueCode(pph21spt, _pph21sptService); if (!isValid(pph21spt)) { return(false); } VHasPercent(pph21spt); if (!isValid(pph21spt)) { return(false); } VHasMinAmount(pph21spt); if (!isValid(pph21spt)) { return(false); } VHasMaxAmount(pph21spt); return(isValid(pph21spt)); }
public dynamic Update(PPH21SPT model) { try { if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.PPH21SPT, 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 = _pph21sptService.GetObjectById(model.Id); data.Code = model.Code; data.Percent = model.Percent; data.MinAmount = model.MinAmount; data.MaxAmount = model.MaxAmount; data.IsInfiniteMaxAmount = model.IsInfiniteMaxAmount; data.Description = model.Description; model = _pph21sptService.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 dynamic Delete(PPH21SPT model) { try { if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.PPH21SPT, 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 = _pph21sptService.GetObjectById(model.Id); model = _pph21sptService.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 })); }
public bool IsCodeDuplicated(PPH21SPT pph21spt) { IQueryable <PPH21SPT> pph21spts = _repository.FindAll(x => x.Code == pph21spt.Code && !x.IsDeleted && x.Id != pph21spt.Id); return(pph21spts.Count() > 0 ? true : false); }
public bool isValid(PPH21SPT obj) { bool isValid = !obj.Errors.Any(); return(isValid); }
public bool ValidUpdateObject(PPH21SPT pph21spt, IPPH21SPTService _pph21sptService) { pph21spt.Errors.Clear(); ValidCreateObject(pph21spt, _pph21sptService); return(isValid(pph21spt)); }
public bool ValidDeleteObject(PPH21SPT pph21spt) { pph21spt.Errors.Clear(); return(isValid(pph21spt)); }
public PPH21SPT SoftDeleteObject(PPH21SPT pph21spt) { return(pph21spt = _validator.ValidDeleteObject(pph21spt) ? _repository.SoftDeleteObject(pph21spt) : pph21spt); }