public IHttpActionResult GetLeave(int id = 0)
        {
            var LeaveTypes = _hrUnitOfWork.LeaveRepository.GetEmpLeaveTypes(1054, User.Identity.GetDefaultCompany(), User.Identity.GetLanguage()).Select(t => new { id = t.Id, name = t.Name });
            var Employees  = _hrUnitOfWork.PeopleRepository.GetActiveEmployees(User.Identity.GetDefaultCompany(), User.Identity.GetLanguage()).Where(e => e.id != User.Identity.GetEmpId()).ToList();
            var ReqReasons = _hrUnitOfWork.LookUpRepository.GetLookUpCode(User.Identity.GetLanguage(), "LeaveReason");
            var Calender   = _hrUnitOfWork.LeaveRepository.GetHolidays(User.Identity.GetDefaultCompany()); //for Calender

            LeaveReqViewModel request;
            LeaveType         CalcOptions = null;

            if (id == 0)
            {
                request = new LeaveReqViewModel();
            }
            else
            {
                request     = _hrUnitOfWork.LeaveRepository.GetRequest(id, User.Identity.GetLanguage());
                CalcOptions = _hrUnitOfWork.LeaveRepository.GetLeaveType(request.TypeId); //for Calender
            }
            if (request == null)
            {
                return(NotFound());
            }

            return(Ok(new { request = request, LeaveTypes = LeaveTypes, Employees = Employees, ReqReasons = ReqReasons, Calender = Calender, CalcOptions = CalcOptions }));
        }
Beispiel #2
0
        public ActionResult Details(int id = 0, byte Version = 0)
        {
            if (!_hrUnitOfWork.LeaveRepository.CheckAutoCompleteColumn("LeaveRequest", CompanyId, Version, "EmpId"))
            {
                ViewBag.Employees = _hrUnitOfWork.PeopleRepository.GetActiveEmployees(CompanyId, Language);
            }

            ViewBag.Calender = _hrUnitOfWork.LeaveRepository.GetHolidays(CompanyId); //for Calender
            ViewBag.isSSMenu = Request.QueryString["SSMenu"] != null?bool.Parse(Request.QueryString["SSMenu"].ToString()) : false;

            if (id == 0)
            {
                if (ViewBag.isSSMenu)
                {
                    fillViewBags(User.Identity.GetEmpId(), DateTime.Today);
                }
                else
                {
                    ViewBag.LeaveTypes = _hrUnitOfWork.LeaveRepository.GetLeaveTypesList(CompanyId, Language);
                }

                return(View(new LeaveReqViewModel()
                {
                    CompanyId = CompanyId
                }));
            }

            LeaveReqViewModel request = _hrUnitOfWork.LeaveRepository.GetRequest(id, Language);

            request.NofDays     = (int)request.NofDays;
            ViewBag.CalcOptions = _hrUnitOfWork.LeaveRepository.GetLeaveType(request.TypeId); //for Calender
            fillViewBags(request.EmpId, request.StartDate);

            return(request == null ? (ActionResult)HttpNotFound() : View(request));
        }
Beispiel #3
0
        public ActionResult AcceptedLeaveDetails(int Id, byte Version)
        {
            LeaveReqViewModel request = _hrUnitOfWork.LeaveRepository.GetRequest(Id, Language);

            ViewBag.Employees     = _hrUnitOfWork.LeaveRepository.GetReplaceEmpList(request.EmpId, Language);
            ViewBag.CanselReasons = _hrUnitOfWork.LookUpRepository.GetLookUpCodes("LeaveCancelReason", Language).Select(a => new { id = a.CodeId, name = a.Title });

            return(View(request));
        }
Beispiel #4
0
        public ActionResult FollowupDetails(int Id, byte Version)
        {
            LeaveReqViewModel request = _hrUnitOfWork.LeaveRepository.GetRequest(Id, Language);

            ViewBag.Employees   = _hrUnitOfWork.LeaveRepository.GetReplaceEmpList(request.EmpId, Language);
            ViewBag.CalcOptions = _hrUnitOfWork.LeaveRepository.GetLeaveType(request.TypeId); //for Calender
            ViewBag.Calender    = _hrUnitOfWork.LeaveRepository.GetHolidays(CompanyId);       //for Calender

            int MenuId = Request.QueryString["MenuId"] != null?int.Parse(Request.QueryString["MenuId"].ToString()) : 0;

            ViewBag.isSSMenu = _hrUnitOfWork.Repository <Model.Domain.Menu>().Where(a => a.Id == MenuId).Select(a => a.SSMenu).FirstOrDefault();

            return(View(request));
        }
Beispiel #5
0
        public ActionResult CheckGroup(LeaveReqViewModel model, int[] grid1)
        {
            //grid1 = Depts

            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.LeaveRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "GroupLeave",
                        TableName    = "LeaveRequests",
                        Columns      = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }
                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            List <ErrorMessage> Msgs;
            var grid = _hrUnitOfWork.LeaveRepository.CheckGroupLeaveGrid(model, grid1, CompanyId, Language, out Msgs);

            if (grid == null && Msgs.Count > 0)
            {
                return(Json(Msgs.Select(a => new { Field = a.field, Message = a.message })));
            }

            return(Json("OK," + (new JavaScriptSerializer().Serialize(grid))));
        }
        public IHttpActionResult GetAcceptedLeave(int id)
        {
            LeaveReqViewModel request = _hrUnitOfWork.LeaveRepository.GetRequest(id, User.Identity.GetLanguage());
            var CanselReasons         = _hrUnitOfWork.LookUpRepository.GetLookUpCode(User.Identity.GetLanguage(), "LeaveCancelReason");
            //  List<string> columns = _hrUnitOfWork.LeaveRepository.GetAutoCompleteColumns("LeaveReqFollowUpForm", User.Identity.GetDefaultCompany(), Version);
            //if (columns.FirstOrDefault(fc => fc == "ReplaceEmpId") == null)
            //    ViewBag.Employees = _hrUnitOfWork.PeopleRepository.GetActiveEmployees(User.Identity.GetDefaultCompany(), User.Identity.GetLanguage());
            List <FormList> ApprovelStytes = ApprovelStutesList();
            var             LeaveTypes     = _hrUnitOfWork.LeaveRepository.GetEmpLeaveTypes(User.Identity.GetEmpId(), User.Identity.GetDefaultCompany(), User.Identity.GetLanguage()).Select(t => new { id = t.Id, name = t.Name });
            var             ReqReasons     = _hrUnitOfWork.LookUpRepository.GetLookUpCode(User.Identity.GetLanguage(), "LeaveReason");
            var             Employees      = _hrUnitOfWork.PeopleRepository.GetActiveEmployees(User.Identity.GetDefaultCompany(), User.Identity.GetLanguage());
            var             CalcOptions    = _hrUnitOfWork.LeaveRepository.GetLeaveType(request.TypeId);
            var             Calender       = _hrUnitOfWork.LeaveRepository.GetHolidays(User.Identity.GetDefaultCompany());

            return(Ok(new { request = request, Calender = Calender, CalcOptions = CalcOptions, Employees = Employees,
                            LeaveTypes = LeaveTypes, ReqReasons = ReqReasons, ApprovalStutes = ApprovelStytes, CanselReasonLst = CanselReasons }));
        }
        public IHttpActionResult GetLeaveFollowUp(int id = 0)
        {
            string Language = User.Identity.GetLanguage();

            var LeaveTypes    = _hrUnitOfWork.LeaveRepository.GetEmpLeaveTypes(1054, User.Identity.GetDefaultCompany(), User.Identity.GetLanguage()).Select(t => new { id = t.Id, name = t.Name });
            var Employees     = _hrUnitOfWork.PeopleRepository.GetActiveEmployees(User.Identity.GetDefaultCompany(), User.Identity.GetLanguage()).Where(e => e.id != User.Identity.GetEmpId()).ToList();
            var ReqReasons    = _hrUnitOfWork.LookUpRepository.GetLookUpCode(User.Identity.GetLanguage(), "LeaveReason");
            var Calender      = _hrUnitOfWork.LeaveRepository.GetHolidays(User.Identity.GetDefaultCompany()); //for Calender
            var Mangers       = _hrUnitOfWork.EmployeeRepository.GetManagers(User.Identity.GetDefaultCompany(), Language).Select(m => new { id = m.Id, name = m.Name });
            var CanselReasons = _hrUnitOfWork.LookUpRepository.GetLookUpCodes("LeaveCancelReason", Language).Select(a => new { id = a.CodeId, name = a.Title });

            var LeaveRejectLst        = _hrUnitOfWork.LookUpRepository.GetLookUpCode(Language, "LeaveRejectReason");
            LeaveReqViewModel request = _hrUnitOfWork.LeaveRepository.GetRequest(id, Language);

            var CalcOptions = _hrUnitOfWork.LeaveRepository.GetLeaveType(request.TypeId);  //for Calender

            return(Ok(new { request = request, LeaveTypesLst = LeaveTypes, ReqReasonsLst = ReqReasons,
                            EmpLst = Employees, LeaveRejectLst = LeaveRejectLst, MangerLst = Mangers,
                            CanselReasonLst = CanselReasons }));
        }
        public IHttpActionResult FollowupDetails(LeaveReqViewModel model)
        {
            List <Model.ViewModel.Error> errors = new List <Model.ViewModel.Error>();
            string message = "Ok";

            if (!ModelState.IsValid)
            {
                return(Json(Utils.ParseFormError(ModelState)));
            }
            LeaveRequest request = _hrUnitOfWork.LeaveRepository.Get(model.Id);

            model.PeriodId = request.PeriodId;
            AutoMapperParm parms = new AutoMapperParm()
            {
                Source = model, Destination = request
            };

            AutoMapper(parms);
            if (request.ApprovalStatus != 9)
            {
                request.RejectDesc   = null;
                request.RejectReason = null;
            }

            if (request.ApprovalStatus != 5)
            {
                request.ActualStartDate = null;
                request.ActualNofDays   = null;
                request.ActualEndDate   = null;
            }
            request.ModifiedTime = DateTime.Now;
            request.ModifiedUser = User.Identity.Name;

            if (request.ApprovalStatus == 5 || request.ApprovalStatus == 9) //Accepted or Rejected
            {
                string msg = AddWFTrans(request, null, null);

                // change here to 6
                if (request.ApprovalStatus == 6)
                {
                    //if msg == Success => msg = null || Error
                    if (msg == "Success")
                    {
                        msg = ChangeAssignmentStatus(request);
                    }
                    if (!string.IsNullOrEmpty(msg))
                    {
                        return(Json(msg)); //ApprovalStatus = 5 because not SaveChanges yet
                    }
                    _hrUnitOfWork.LeaveRepository.AddAcceptLeaveTrans(request, User.Identity.Name);
                }
            }

            _hrUnitOfWork.LeaveRepository.Attach(request);
            _hrUnitOfWork.LeaveRepository.Entry(request).State = EntityState.Modified;

            var Errors = SaveChanges(User.Identity.GetLanguage());

            if (Errors.Count > 0)
            {
                message = Errors.First().errors.First().message;
            }
            return(Ok(message));
        }
        public IHttpActionResult SaveLeave(LeaveReqViewModel model)
        {
            List <Model.ViewModel.Error> errors = new List <Model.ViewModel.Error>();

            if (!ModelState.IsValid)
            {
                return(Json(Utils.ParseFormError(ModelState)));
            }


            model.EmpId = User.Identity.GetEmpId();
            LeaveRequest request = _hrUnitOfWork.LeaveRepository.Get(model.Id);
            var          type    = _hrUnitOfWork.LeaveRepository.GetLeaveType(model.TypeId);

            if (model.ReqReason == null && type.MustAddCause == true)
            {
                ModelState.AddModelError("ReqReason", MsgUtils.Instance.Trls("Required"));
                return(Ok(ModelState));
            }

            string message = "Ok";

            ///Save
            if (model.Id == 0)
            { /// New
                request = new LeaveRequest();
                AutoMapperParm parms = new AutoMapperParm()
                {
                    Source = model, Destination = request
                };
                AutoMapper(parms);
                request.PeriodId       = _hrUnitOfWork.LeaveRepository.GetLeaveRequestPeriod(type.CalendarId, request.StartDate, User.Identity.GetLanguage(), out message);
                request.ApprovalStatus = (byte)(model.submit == true ? 2 : 1); //1- New, 2- Submit
                request.CreatedUser    = User.Identity.Name;
                request.CreatedTime    = DateTime.Now;
                _hrUnitOfWork.LeaveRepository.Add(request);
            }
            else
            { /// Edit
                AutoMapperParm parms = new AutoMapperParm()
                {
                    Source = model, Destination = request
                };                                                                                     //, ObjectName = "LeaveRequest"
                AutoMapper(parms);

                if (model.submit)
                {
                    _hrUnitOfWork.TrainingRepository.AddTrail(new AddTrailViewModel()
                    {
                        ColumnName  = "ApprovalStatus",
                        CompanyId   = User.Identity.GetDefaultCompany(),
                        ObjectName  = "LeaveRequest",
                        SourceId    = request.Id.ToString(),
                        UserName    = User.Identity.Name,
                        ValueAfter  = MsgUtils.Instance.Trls("Submit"),
                        ValueBefore = MsgUtils.Instance.Trls("Darft")
                    });
                }

                request.ApprovalStatus = (byte)(model.submit == true ? 2 : model.ApprovalStatus); //1- New, 2- Submit
                request.ModifiedUser   = User.Identity.Name;
                request.ModifiedTime   = DateTime.Now;
                _hrUnitOfWork.LeaveRepository.Attach(request);
                _hrUnitOfWork.LeaveRepository.Entry(request).State = EntityState.Modified;
            }

            var Errors = SaveChanges(User.Identity.GetLanguage());

            if (Errors.Count > 0)
            {
                message = Errors.First().errors.First().message;
                return(Ok(message));
            }

            if (model.submit)
            {
                WfViewModel wf = new WfViewModel()
                {
                    Source         = "Leave",
                    SourceId       = request.TypeId,
                    DocumentId     = request.Id,
                    RequesterEmpId = request.EmpId,
                    ApprovalStatus = 2,
                    CreatedUser    = User.Identity.Name,
                };
                var wfTrans = _hrUnitOfWork.LeaveRepository.AddWorkFlow(wf, User.Identity.GetLanguage());
                if (wfTrans == null && wf.WorkFlowStatus != "Success")
                {
                    request.ApprovalStatus = 1;
                    message += "," + (new JavaScriptSerializer()).Serialize(new { model = request, error = wf.WorkFlowStatus });

                    _hrUnitOfWork.LeaveRepository.Attach(request);
                    _hrUnitOfWork.LeaveRepository.Entry(request).State = EntityState.Modified;
                }
                else if (wfTrans != null)
                {
                    _hrUnitOfWork.LeaveRepository.Add(wfTrans);
                }
            }

            Errors = SaveChanges(User.Identity.GetLanguage());
            if (Errors.Count > 0)
            {
                message = Errors.First().errors.First().message;
            }


            return(Ok(message));
        }
Beispiel #10
0
        public ActionResult FollowupDetails(LeaveReqViewModel model, OptionsViewModel moreInfo)
        {
            List <Error> Errors  = new List <Error>();
            LeaveRequest request = _hrUnitOfWork.LeaveRepository.Get(model.Id);

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    Errors = _hrUnitOfWork.LeaveRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "LeaveReqFollowUpForm",
                        TableName    = "LeaveRequests",
                        Columns      = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });

                    if (Errors.Count() > 0)
                    {
                        foreach (var e in Errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }
                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            AutoMapper(new Models.AutoMapperParm
            {
                Destination = request,
                Source      = model,
                ObjectName  = "LeaveRequest",
                Options     = moreInfo,
                Transtype   = TransType.Update
            });

            if (request.ApprovalStatus != 9)
            {
                request.RejectDesc   = null;
                request.RejectReason = null;
            }

            if (request.ApprovalStatus == 5)
            {
                request.ActualStartDate = request.StartDate;
                request.ActualNofDays   = request.NofDays;
                request.ActualEndDate   = request.EndDate;
            }
            request.ModifiedTime = DateTime.Now;
            request.ModifiedUser = UserName;

            if (request.ApprovalStatus == 5 || request.ApprovalStatus == 9) //Accepted or Rejected
            {
                string msg = AddWFTrans(request, null, null);

                // change here to 6
                if (request.ApprovalStatus == 6)
                {
                    //if msg == Success => msg = null || Error
                    if (msg == "Success")
                    {
                        msg = ChangeAssignmentStatus(request);
                    }
                    if (!string.IsNullOrEmpty(msg))
                    {
                        return(Json(msg)); //ApprovalStatus = 5 because not SaveChanges yet
                    }
                    _hrUnitOfWork.LeaveRepository.AddAcceptLeaveTrans(request, UserName);
                }
            }

            _hrUnitOfWork.LeaveRepository.Attach(request);
            _hrUnitOfWork.LeaveRepository.Entry(request).State = EntityState.Modified;

            Errors = SaveChanges(Language);
            if (Errors.Count > 0)
            {
                var message = Errors.First().errors.First().message;
                return(Json(message));
            }

            return(Json("OK"));
        }
Beispiel #11
0
        public ActionResult SaveGroup(LeaveReqViewModel model, IEnumerable <GroupLeaveViewModel> grid1, int[] grid2, OptionsViewModel moreInfo)
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.LeaveRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "GroupLeave",
                        TableName    = "LeaveRequests",
                        Columns      = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }
                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            string              message = "OK";
            LeaveType           type    = _hrUnitOfWork.LeaveRepository.GetLeaveType(model.TypeId);
            int                 PeriodId;
            List <ErrorMessage> Errors = _hrUnitOfWork.LeaveRepository.CheckGroupLeave(model, type, Language, out PeriodId);

            if (Errors.Count() > 0)
            {
                return(Json(Errors.Select(a => new { Field = a.field, Message = a.message })));
            }

            byte version;

            byte.TryParse(Request.Form["version"], out version);

            if (grid1 != null)
            {
                GroupLeave groupLeave = new GroupLeave();

                AutoMapper(new AutoMapperParm()
                {
                    Source = model, Destination = groupLeave, Version = version, ObjectName = "GroupLeave", Options = moreInfo
                });
                groupLeave.PeriodId       = PeriodId;
                groupLeave.ApprovalStatus = 6; //Approved
                groupLeave.CompanyId      = CompanyId;
                groupLeave.CreatedUser    = UserName;
                groupLeave.CreatedTime    = DateTime.Now;
                _hrUnitOfWork.LeaveRepository.Add(groupLeave);

                foreach (var item in grid1)
                {
                    GroupLeaveLog leaveLog = new GroupLeaveLog();
                    leaveLog.GroupLeave = groupLeave;
                    leaveLog.EmpId      = item.EmpId;
                    leaveLog.Approved   = item.Approve;
                    leaveLog.Success    = item.Success;
                    leaveLog.ReasonCode = item.ReasonCode;
                    leaveLog.Reason     = item.Reason;

                    _hrUnitOfWork.LeaveRepository.Add(leaveLog);

                    if (item.Approve)
                    {//Leave Trans
                        LeaveRequest request = new LeaveRequest {
                            EmpId = item.EmpId, TypeId = model.TypeId, PeriodId = PeriodId, CompanyId = CompanyId, ActualStartDate = model.StartDate, ActualNofDays = model.NofDays
                        };
                        _hrUnitOfWork.LeaveRepository.AddAcceptLeaveTrans(request, UserName);
                    }
                }

                errors = SaveChanges(Language);
                if (errors.Count > 0)
                {
                    message = errors.First().errors.First().message;
                }
            }
            return(Json(message));
        }
Beispiel #12
0
        public ActionResult Details(LeaveReqViewModel model, OptionsViewModel moreInfo, bool clear)
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.CompanyRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "LeaveRequest",
                        TableName    = "LeaveRequests",
                        Columns      = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }
                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            LeaveRequest request = _hrUnitOfWork.LeaveRepository.Get(model.Id);
            var          type    = _hrUnitOfWork.LeaveRepository.GetLeaveType(model.TypeId);

            byte version;

            byte.TryParse(Request.Form["version"], out version);
            string message = "OK";

            if (type.AllowFraction && model.DayFraction != 0)
            {
                switch (model.DayFraction)
                {
                case 1:
                case 3: model.NofDays = 0.25f; break;

                case 2:
                case 4: model.NofDays = 0.5f; break;
                }
            }

            ///Save
            if (model.Id == 0)
            { /// New
                request             = new LeaveRequest();
                model.BalanceBefore = model.BalBefore;

                AutoMapperParm parms = new AutoMapperParm()
                {
                    Source = model, Destination = request, Version = version, ObjectName = "LeaveRequest", Options = moreInfo, Transtype = TransType.Insert
                };
                AutoMapper(parms);
                request.CompanyId      = CompanyId;
                request.PeriodId       = _hrUnitOfWork.LeaveRepository.GetLeaveRequestPeriod(type.CalendarId, request.StartDate, Language, out message);
                request.ApprovalStatus = (byte)(model.submit ? (type.ExWorkflow ? 6 : 2) : 1); //ApprovalStatus 1- New, 2- Submit 6- Approved //AbsenceType 8- Casual
                model.CompanyId        = request.CompanyId;
                model.PeriodId         = request.PeriodId;
                model.ApprovalStatus   = request.ApprovalStatus;

                if (type.ExWorkflow && model.submit)
                {
                    request.ActualStartDate = request.StartDate;
                    request.ActualEndDate   = request.EndDate;
                    request.ActualNofDays   = request.NofDays;
                    model.ActualStartDate   = request.StartDate;
                    model.ActualEndDate     = request.EndDate;
                    model.ActualNofDays     = request.NofDays;
                }

                request.CreatedUser = UserName;
                request.CreatedTime = DateTime.Now;
                _hrUnitOfWork.LeaveRepository.Add(request);

                if (!type.ExWorkflow && !clear && request.ApprovalStatus == 1)
                {
                    model.ForceUpload = _hrUnitOfWork.Repository <RequestWf>().Where(a => a.Source == "Leave" && a.SourceId == type.Id).Select(a => a.ForceUpload).FirstOrDefault() ? 1 : 0;
                }
            }
            else
            { /// Edit
                AutoMapperParm parms = new AutoMapperParm()
                {
                    Source = model, Destination = request, Version = version, ObjectName = "LeaveRequest", Options = moreInfo, Transtype = TransType.Update
                };
                AutoMapper(parms);

                if (model.submit)
                {
                    _hrUnitOfWork.TrainingRepository.AddTrail(new AddTrailViewModel()
                    {
                        ColumnName  = "ApprovalStatus",
                        CompanyId   = CompanyId,
                        ObjectName  = "LeaveRequest",
                        SourceId    = request.Id.ToString(),
                        UserName    = UserName,
                        Version     = Convert.ToByte(Request.Form["Version"]),
                        ValueAfter  = MsgUtils.Instance.Trls("Submit"),
                        ValueBefore = MsgUtils.Instance.Trls("Darft"),
                        Transtype   = (byte)TransType.Update
                    });
                }

                request.ApprovalStatus = (byte)(model.submit ? (type.ExWorkflow ? 6 : 2) : model.ApprovalStatus); //1- New, 2- Submit 6- Approved //AbsenceType 8- Casual
                model.ApprovalStatus   = request.ApprovalStatus;
                request.ModifiedUser   = UserName;
                request.ModifiedTime   = DateTime.Now;
                if (type.ExWorkflow && model.submit)
                {
                    request.ActualStartDate = request.StartDate;
                    request.ActualEndDate   = request.EndDate;
                    request.ActualNofDays   = request.NofDays;
                    model.ActualStartDate   = request.StartDate;
                    model.ActualEndDate     = request.EndDate;
                    model.ActualNofDays     = request.NofDays;
                }

                _hrUnitOfWork.LeaveRepository.Attach(request);
                _hrUnitOfWork.LeaveRepository.Entry(request).State = EntityState.Modified;
            }

            if (model.submit && type.ExWorkflow && request.ApprovalStatus == 1)
            {
                _hrUnitOfWork.LeaveRepository.AddAcceptLeaveTrans(request, UserName);
            }

            // update using transactions
            var trans = _hrUnitOfWork.BeginTransaction();

            // #First save changes
            var Errors = SaveChanges(Language);

            if (Errors.Count > 0)
            {
                message = Errors.First().errors.First().message;
                trans.Rollback();
                trans.Dispose();

                // return string error message
                return(Json(message));
            }

            model.Id = request.Id;
            if (model.submit) //Casual  && type.AbsenceType != 8
            {
                WfViewModel wf = new WfViewModel()
                {
                    Source         = "Leave",
                    SourceId       = request.TypeId,
                    DocumentId     = request.Id,
                    RequesterEmpId = request.EmpId,
                    ApprovalStatus = 2,
                    CreatedUser    = UserName,
                };

                var wfTrans = _hrUnitOfWork.LeaveRepository.AddWorkFlow(wf, Language);
                if (wfTrans == null && wf.WorkFlowStatus != "Success")
                {
                    request.ApprovalStatus = 1;
                    message += "," + (new JavaScriptSerializer()).Serialize(new { model = request, error = wf.WorkFlowStatus });

                    _hrUnitOfWork.LeaveRepository.Attach(request);
                    _hrUnitOfWork.LeaveRepository.Entry(request).State = EntityState.Modified;
                }
                else if (wfTrans != null)
                {
                    _hrUnitOfWork.LeaveRepository.Add(wfTrans);
                }

                // #Second Save changes
                Errors = Save(Language);
                if (Errors.Count > 0)
                {
                    message = Errors.First().errors.First().message;
                    trans.Rollback();
                    trans.Dispose();

                    // return string error message
                    return(Json(message));
                }
            }

            if (clear)
            {
                model = new LeaveReqViewModel();
            }

            if (message == "OK")
            {
                // send OK,model
                message += "," + ((new JavaScriptSerializer()).Serialize(new { model = model }));
                trans.Commit();
            }

            return(Json(message));
        }