public IActionResult Add(OpsStageAssignedEditModel model)
        {
            string message = string.Empty;

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (opsStageAssignedService.Any(x => x.JobId == model.JobId && x.StageId == model.StageId && x.MainPersonInCharge == model.MainPersonInCharge))
            {
                message = stringLocalizer[OperationLanguageSub.MSG_STAGE_ASSIGNED_EXISTED].Value;
                return(BadRequest(new ResultHandle {
                    Status = false, Message = message
                }));
            }
            var hs = opsStageAssignedService.Add(model);

            message = HandleError.GetMessage(hs, Crud.Insert);
            ResultHandle result = new ResultHandle {
                Status = hs.Success, Message = stringLocalizer[message].Value
            };

            if (!hs.Success)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
        public IActionResult Update(OpsStageAssignedEditModel model)
        {
            var          hs      = opsStageAssignedService.Update(model);
            var          message = HandleError.GetMessage(hs, Crud.Update);
            ResultHandle result  = new ResultHandle {
                Status = hs.Success, Message = stringLocalizer[message].Value
            };

            if (!hs.Success)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
예제 #3
0
        public HandleState Add(OpsStageAssignedEditModel model)
        {
            var assignedItem = mapper.Map <OpsStageAssigned>(model);

            assignedItem.Id                 = Guid.NewGuid();
            assignedItem.Status             = OperationConstants.InSchedule;
            assignedItem.RealPersonInCharge = assignedItem.MainPersonInCharge;
            assignedItem.DatetimeCreated    = assignedItem.DatetimeModified = DateTime.Now;
            //assignedItem.UserCreated = currentUser.UserID;
            var orderNumberProcess = DataContext.Count(x => x.JobId == model.JobId);

            assignedItem.OrderNumberProcessed = orderNumberProcess + 1;
            var hs = DataContext.Add(assignedItem);

            return(hs);
        }
예제 #4
0
        public HandleState Update(OpsStageAssignedEditModel model)
        {
            var assigned = mapper.Map <OpsStageAssigned>(model);

            assigned.UserModified     = currentUser.UserID;
            assigned.DatetimeModified = DateTime.Now;
            var stageAssigneds   = DataContext.Get(x => x.JobId == model.JobId);
            var job              = opsTransRepository.First(x => x.Id == model.JobId);
            var jobCsTransaction = csTransactionReporsitory.First(x => x.Id == model.JobId);

            if (job == null)
            {
                if (jobCsTransaction.CurrentStatus != OperationConstants.Deleted && jobCsTransaction.CurrentStatus != OperationConstants.Finish)
                {
                    if (assigned.Status?.Trim() == DataTypeEx.GetStageStatus(StageEnum.Overdue))
                    {
                        jobCsTransaction.CurrentStatus = OperationConstants.Overdue;
                    }
                    if (assigned.Status.Contains(DataTypeEx.GetStageStatus(StageEnum.Done)))
                    {
                        var others = stageAssigneds.Where(x => x.Id != model.Id);
                        if (others.All(x => x.Status.Contains(OperationConstants.Done)))
                        {
                            jobCsTransaction.CurrentStatus = OperationConstants.Finish;
                        }
                    }
                    if (jobCsTransaction.CurrentStatus?.Trim() == OperationConstants.InSchedule && assigned.Status.Trim() == OperationConstants.Processing)
                    {
                        jobCsTransaction.CurrentStatus = OperationConstants.Processing;
                    }
                }
            }
            else
            {
                if (job.CurrentStatus != OperationConstants.Deleted && job.CurrentStatus != OperationConstants.Finish)
                {
                    if (assigned.Status?.Trim() == DataTypeEx.GetStageStatus(StageEnum.Overdue))
                    {
                        job.CurrentStatus = OperationConstants.Overdue;
                    }
                    if (assigned.Status.Contains(DataTypeEx.GetStageStatus(StageEnum.Done)))
                    {
                        var others = stageAssigneds.Where(x => x.Id != model.Id);
                        if (others.All(x => x.Status.Contains(OperationConstants.Done)))
                        {
                            job.CurrentStatus = OperationConstants.Finish;
                        }
                    }
                    if (job.CurrentStatus?.Trim() == OperationConstants.InSchedule && assigned.Status.Trim() == OperationConstants.Processing)
                    {
                        job.CurrentStatus = OperationConstants.Processing;
                    }
                }
            }
            var result = new HandleState();

            try
            {
                result = DataContext.Update(assigned, x => x.Id == assigned.Id, false);
                SubmitChanges();
                if (result.Success)
                {
                    if (job == null)
                    {
                        csTransactionReporsitory.Update(jobCsTransaction, x => x.Id == jobCsTransaction.Id);
                        csTransactionReporsitory.SubmitChanges();
                    }
                    else
                    {
                        opsTransRepository.Update(job, x => x.Id == job.Id);
                        opsTransRepository.SubmitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new HandleState(ex.Message);
            }
            return(result);
        }