示例#1
0
        public IHttpActionResult EditAssignOrder(AssignOrderVM model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (model == null)
            {
                return(NotFound());
            }
            var         UserName = HttpContext.Current.User.Identity.Name;
            AssignOrder request  = hrUnitOfWork.LeaveRepository.GetAssignOrderByiD(model.Id);

            AutoMapperParm parms = new Models.AutoMapperParm()
            {
                Source = model, Destination = request, Version = 0, ObjectName = "AssignOrders", Options = null, Transtype = TransType.Update
            };

            AutoMapper(parms);

            if (model.Id != 0)
            {
                hrUnitOfWork.TrainingRepository.AddTrail(new AddTrailViewModel()
                {
                    ColumnName  = "ApprovalStatus",
                    CompanyId   = model.CompanyId,
                    ObjectName  = "AssignOrders",
                    SourceId    = request.Id.ToString(),
                    UserName    = UserName,
                    Version     = 0,
                    ValueAfter  = MsgUtils.Instance.Trls("Submit"),
                    ValueBefore = MsgUtils.Instance.Trls("Darft")
                });

                request.CompanyId      = model.CompanyId;
                request.ModifiedUser   = UserName;
                request.ModifiedTime   = DateTime.Now;
                request.ApprovalStatus = 6;
                request.EmpId          = model.EmpId;
                request.Duration       = model.Duration;
                request.AssignDate     = model.AssignDate;
                request.CalcMethod     = model.CalcMethod;
                request.LeaveTypeId    = model.LeaveTypeId;
                request.ExpiryDate     = model.ExpiryDate;
                request.TaskDesc       = model.TaskDesc;
                request.ManagerId      = model.ManagerId;
                hrUnitOfWork.LeaveRepository.AttachAssignOrder(request);
                hrUnitOfWork.LeaveRepository.EntryAssignOrder(request).State = EntityState.Modified;

                var Errors = SaveChanges(model.language);
                if (Errors.Count > 0)
                {
                    return(StatusCode(HttpStatusCode.Forbidden));
                }

                if (request.CalcMethod == 1) //monetary
                {
                    WfViewModel wf = new WfViewModel()
                    {
                        Source         = "AssignOrder1",
                        SourceId       = request.CompanyId,
                        DocumentId     = request.Id,
                        RequesterEmpId = request.EmpId,
                        ApprovalStatus = 6,
                        CreatedUser    = UserName,
                    };
                    var wfTrans = hrUnitOfWork.LeaveRepository.AddWorkFlow(wf, model.language);
                    if (wfTrans == null && wf.WorkFlowStatus != "Success")
                    {
                        request.ApprovalStatus = 1;

                        hrUnitOfWork.LeaveRepository.AttachAssignOrder(request);
                        hrUnitOfWork.LeaveRepository.EntryAssignOrder(request).State = EntityState.Modified;
                    }
                    else if (wfTrans != null)
                    {
                        hrUnitOfWork.LeaveRepository.Add(wfTrans);
                    }
                }
                else if (request.CalcMethod == 2) //time compensation
                {
                    WfViewModel wf = new WfViewModel()
                    {
                        Source         = "AssignOrder2",
                        SourceId       = request.CompanyId,
                        DocumentId     = request.Id,
                        RequesterEmpId = request.EmpId,
                        ApprovalStatus = 6,
                        CreatedUser    = UserName,
                    };
                    var wfTrans = hrUnitOfWork.LeaveRepository.AddWorkFlow(wf, model.language);
                    if (wfTrans == null && wf.WorkFlowStatus != "Success")
                    {
                        request.ApprovalStatus = 1;
                        hrUnitOfWork.LeaveRepository.AttachAssignOrder(request);
                        hrUnitOfWork.LeaveRepository.EntryAssignOrder(request).State = EntityState.Modified;
                    }
                    else if (wfTrans != null)
                    {
                        hrUnitOfWork.LeaveRepository.Add(wfTrans);
                    }
                }
                Errors = SaveChanges(model.language);
                if (Errors.Count > 0)
                {
                    return(StatusCode(HttpStatusCode.NotModified));
                }
            }
            return(Ok(model));
        }
示例#2
0
        public IHttpActionResult PostAssignOrder(AssignOrderVM model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (model == null)
            {
                return(NotFound());
            }
            var         UserName = HttpContext.Current.User.Identity.Name;
            AssignOrder request;
            //= hrUnitOfWork.LeaveRepository.GetAssignOrderByiD(model.Id);
            var isRequired = hrUnitOfWork.Repository <Workflow>().Where(w => w.Source == "AssignOrder" + model.CalcMethod && w.CompanyId == model.CompanyId).Select(a => a.IsRequired).FirstOrDefault();

            request = new AssignOrder();
            AutoMapperParm parms = new Models.AutoMapperParm()
            {
                Source = model, Destination = request, Version = 0, ObjectName = "AssignOrders", Options = null, Transtype = TransType.Insert
            };

            AutoMapper(parms);

            request.CompanyId      = model.CompanyId;
            request.CreatedUser    = UserName;
            request.CreatedTime    = DateTime.Now;
            request.ApprovalStatus = (byte)(isRequired ? 1 : 6);
            request.EmpId          = model.EmpId;
            request.Duration       = model.Duration;
            request.AssignDate     = model.AssignDate;
            request.CalcMethod     = model.CalcMethod;
            request.LeaveTypeId    = model.LeaveTypeId;
            request.ExpiryDate     = model.ExpiryDate;
            request.TaskDesc       = model.TaskDesc;
            request.ManagerId      = model.ManagerId;
            hrUnitOfWork.LeaveRepository.AddAssignOrder(request);

            var Errors = SaveChanges(model.language);

            if (Errors.Count > 0)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            if (!isRequired && model.CalcMethod == 2 && model.Id == 0)
            {
                var error = hrUnitOfWork.LeaveRepository.AddAssignOrdersLeaveTrans(request, UserName, model.language);
            }

            if (isRequired)
            {
                if (request.CalcMethod == 1) //monetary
                {
                    WfViewModel wf = new WfViewModel()
                    {
                        Source         = "AssignOrder1",
                        SourceId       = request.CompanyId,
                        DocumentId     = request.Id,
                        RequesterEmpId = request.EmpId,
                        ApprovalStatus = 6,
                        CreatedUser    = UserName,
                    };
                    var wfTrans = hrUnitOfWork.LeaveRepository.AddWorkFlow(wf, model.language);
                    if (wfTrans == null && wf.WorkFlowStatus != "Success")
                    {
                        request.ApprovalStatus = 1;

                        hrUnitOfWork.LeaveRepository.AttachAssignOrder(request);
                        hrUnitOfWork.LeaveRepository.EntryAssignOrder(request).State = EntityState.Modified;
                    }
                    else if (wfTrans != null)
                    {
                        hrUnitOfWork.LeaveRepository.Add(wfTrans);
                    }
                }
                else if (request.CalcMethod == 2) //time compensation
                {
                    WfViewModel wf = new WfViewModel()
                    {
                        Source         = "AssignOrder2",
                        SourceId       = request.CompanyId,
                        DocumentId     = request.Id,
                        RequesterEmpId = request.EmpId,
                        ApprovalStatus = 6,
                        CreatedUser    = UserName,
                    };
                    var wfTrans = hrUnitOfWork.LeaveRepository.AddWorkFlow(wf, model.language);
                    if (wfTrans == null && wf.WorkFlowStatus != "Success")
                    {
                        request.ApprovalStatus = 1;
                        hrUnitOfWork.LeaveRepository.AttachAssignOrder(request);
                        hrUnitOfWork.LeaveRepository.EntryAssignOrder(request).State = EntityState.Modified;
                    }
                    else if (wfTrans != null)
                    {
                        hrUnitOfWork.LeaveRepository.Add(wfTrans);
                    }
                }
            }

            Errors = SaveChanges(model.language);
            if (Errors.Count > 0)
            {
                return(StatusCode(HttpStatusCode.NotModified));
            }
            model.Id = request.Id;
            return(Created(new Uri(Request.RequestUri + "/" + model.Id), model));
        }