public dynamic Insert(EmployeeWorkingTime model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.EmployeeWorkingTime, 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 = _employeeWorkingTimeService.CreateObject(model, _workingTimeService, _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()
        {
            EmployeeWorkingTime model = new EmployeeWorkingTime();

            try
            {
                model = _employeeWorkingTimeService.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.WorkingTimeId,
                model.EmployeeId,
                EmployeeNIK = model.Employee.NIK,
                EmployeeName = model.Employee.Name,
                Title = model.Employee.TitleInfo.Name,
                Division = model.Employee.Division.Name,
                model.StartDate,
                model.EndDate,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
 public EmployeeWorkingTime VHasEndDate(EmployeeWorkingTime employeeWorkingTime)
 {
     if (employeeWorkingTime.EndDate == null || employeeWorkingTime.EndDate.Equals(DateTime.FromBinary(0)))
     {
         //  employeeWorkingTime.Errors.Add("EndDate", "Tidak valid");
     }
     return(employeeWorkingTime);
 }
예제 #4
0
        public EmployeeWorkingTime VHasEmployee(EmployeeWorkingTime employeeWorkingTime, EmployeeService _employeeService)
        {
            Employee employee = _employeeService.GetObjectById(employeeWorkingTime.EmployeeId);

            if (employee == null)
            {
                //  employeeWorkingTime.Errors.Add("Employee", "Tidak valid");
            }
            return(employeeWorkingTime);
        }
예제 #5
0
        public EmployeeWorkingTime VHasWorkingTime(EmployeeWorkingTime employeeWorkingTime, IWorkingTimeService _workingTimeService)
        {
            WorkingTime workingTime = _workingTimeService.GetObjectById(employeeWorkingTime.WorkingTimeId);

            if (workingTime == null)
            {
                //  employeeWorkingTime.Errors.Add("WorkingTime", "Tidak valid");
            }
            return(employeeWorkingTime);
        }
예제 #6
0
        void EmployeeWorkingTime_validation()
        {
            it["validates_employeeWorkingTime"] = () =>
            {
                d.ewt1.Errors.Count().should_be(0);
            };

            it["employeeWorkingTime_with_no_workingTime"] = () =>
            {
                EmployeeWorkingTime obj = new EmployeeWorkingTime()
                {
                    StartDate = DateTime.Today,
                    EndDate   = DateTime.Today.AddDays(1),
                };
                obj = d._employeeWorkingTimeService.CreateObject(obj, d._workingTimeService, d._employeeService);
                obj.Errors.Count().should_not_be(0);
            };

            it["employeeWorkingTime_with_no_startdate"] = () =>
            {
                EmployeeWorkingTime obj = new EmployeeWorkingTime()
                {
                    WorkingTimeId = d.wt1.Id,
                    EndDate       = DateTime.Today.AddDays(1),
                };
                obj = d._employeeWorkingTimeService.CreateObject(obj, d._workingTimeService, d._employeeService);
                obj.Errors.Count().should_not_be(0);
            };

            it["employeeWorkingTime_with_no_enddate"] = () =>
            {
                EmployeeWorkingTime obj = new EmployeeWorkingTime()
                {
                    WorkingTimeId = d.wt1.Id,
                    StartDate     = DateTime.Today,
                };
                obj = d._employeeWorkingTimeService.CreateObject(obj, d._workingTimeService, d._employeeService);
                obj.Errors.Count().should_not_be(0);
            };

            it["update_employeeWorkingTime_with_no_workingtime"] = () =>
            {
                d.ewt1.WorkingTimeId = 0;
                d._employeeWorkingTimeService.UpdateObject(d.ewt1, d._workingTimeService, d._employeeService);
                d.ewt1.Errors.Count().should_not_be(0);
            };

            it["delete_employeeWorkingTime_having_employees"] = () =>
            {
                d._employeeWorkingTimeService.SoftDeleteObject(d.ewt1, d._employeeService);
                d.ewt1.Errors.Count().should_not_be(0);
            };
        }
예제 #7
0
        public string PrintError(EmployeeWorkingTime 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);
        }
예제 #8
0
        //public EmployeeWorkingTime VDontHaveEmployees(EmployeeWorkingTime employeeWorkingTime, IEmployeeService _employeeService)
        //{
        //    IList<Employee> employees = _employeeService.GetObjectsByEmployeeWorkingTimeId(employeeWorkingTime.Id);
        //    if (employees.Any())
        //    {
        //        employeeWorkingTime.Errors.Add("Generic", "Tidak boleh masih terasosiasi dengan Employees");
        //    }
        //    return employeeWorkingTime;
        //}

        public bool ValidCreateObject(EmployeeWorkingTime employeeWorkingTime, IWorkingTimeService _workingTimeService, EmployeeService _employeeService)
        {
            VHasWorkingTime(employeeWorkingTime, _workingTimeService);
            if (!isValid(employeeWorkingTime))
            {
                return(false);
            }
            VHasEmployee(employeeWorkingTime, _employeeService);
            if (!isValid(employeeWorkingTime))
            {
                return(false);
            }
            VHasStartDate(employeeWorkingTime);
            if (!isValid(employeeWorkingTime))
            {
                return(false);
            }
            VHasEndDate(employeeWorkingTime);
            return(isValid(employeeWorkingTime));
        }
        public dynamic Update(EmployeeWorkingTime model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.EmployeeWorkingTime, 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 = _employeeWorkingTimeService.GetObjectById(model.Id);
                data.WorkingTimeId = model.WorkingTimeId;
                data.EmployeeId    = model.EmployeeId;
                //data.IsEnabled = model.IsEnabled;
                //data.IsShiftable = model.IsShiftable;
                data.StartDate = model.StartDate;
                data.EndDate   = model.EndDate;
                model          = _employeeWorkingTimeService.UpdateObject(data, _workingTimeService, _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(EmployeeWorkingTime model)
        {
            try
            {
                if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.EmployeeWorkingTime, 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 = _employeeWorkingTimeService.GetObjectById(model.Id);
                model = _employeeWorkingTimeService.SoftDeleteObject(data, _employeeService);
            }

            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
            }));
        }
예제 #11
0
 public EmployeeWorkingTime SoftDeleteObject(EmployeeWorkingTime employeeWorkingTime, EmployeeService _employeeService)
 {
     return(employeeWorkingTime = _validator.ValidDeleteObject(employeeWorkingTime, _employeeService) ?
                                  _repository.SoftDeleteObject(employeeWorkingTime) : employeeWorkingTime);
 }
예제 #12
0
 public EmployeeWorkingTime UpdateObject(EmployeeWorkingTime employeeWorkingTime, IWorkingTimeService _workingTimeService, EmployeeService _employeeService)
 {
     return(employeeWorkingTime = _validator.ValidUpdateObject(employeeWorkingTime, _workingTimeService, _employeeService) ? _repository.UpdateObject(employeeWorkingTime) : employeeWorkingTime);
 }
예제 #13
0
 public EmployeeWorkingTime CreateObject(EmployeeWorkingTime employeeWorkingTime, IWorkingTimeService _workingTimeService, EmployeeService _employeeService)
 {
     // employeeWorkingTime.Errors = new Dictionary<String, String>();
     return(_validator.ValidCreateObject(employeeWorkingTime, _workingTimeService, _employeeService) ? _repository.CreateObject(employeeWorkingTime) : employeeWorkingTime);
 }
예제 #14
0
 public bool isValid(EmployeeWorkingTime obj)
 {
     //  bool isValid = !obj.Errors.Any();
     return(true);
 }
예제 #15
0
 public bool ValidDeleteObject(EmployeeWorkingTime employeeWorkingTime, EmployeeService _employeeService)
 {
     //  employeeWorkingTime.Errors.Clear();
     //VDontHaveEmployees(employeeWorkingTime, _employeeService);
     return(isValid(employeeWorkingTime));
 }
예제 #16
0
 public bool ValidUpdateObject(EmployeeWorkingTime employeeWorkingTime, IWorkingTimeService _workingTimeService, EmployeeService _employeeService)
 {
     //  employeeWorkingTime.Errors.Clear();
     ValidCreateObject(employeeWorkingTime, _workingTimeService, _employeeService);
     return(isValid(employeeWorkingTime));
 }