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 })); }
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)); }
public SPKL VHasStartTime(SPKL spkl) { if (spkl.StartTime == null || spkl.StartTime.Equals(DateTime.FromBinary(0))) { spkl.Errors.Add("StartTime", "Tidak valid"); } return(spkl); }
public SPKL VHasRemark(SPKL spkl) { if (String.IsNullOrEmpty(spkl.Remark) || spkl.Remark.Trim() == "") { spkl.Errors.Add("Remark", "Tidak boleh kosong"); } return(spkl); }
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); }
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); }
public SPKL VHasEmployee(SPKL spkl, IEmployeeService _employeeService) { Employee employee = _employeeService.GetObjectById(spkl.EmployeeId); if (employee == null) { spkl.Errors.Add("Employee", "Tidak ada"); } return(spkl); }
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); }
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); }
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)); }
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 })); }
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 })); }
public SPKL SoftDeleteObject(SPKL spkl) { return(spkl = _validator.ValidDeleteObject(spkl) ? _repository.SoftDeleteObject(spkl) : spkl); }
public bool isValid(SPKL obj) { bool isValid = !obj.Errors.Any(); return(isValid); }
public bool ValidDeleteObject(SPKL spkl) { spkl.Errors.Clear(); return(isValid(spkl)); }
public bool ValidUpdateObject(SPKL spkl, IEmployeeService _employeeService) { spkl.Errors.Clear(); ValidCreateObject(spkl, _employeeService); return(isValid(spkl)); }