Beispiel #1
0
        public async Task <SendMessageResponse> UpdateProcessTaskAssign(TaskItemAssignDto dto)
        {
            SendMessageResponse sendMessage = new SendMessageResponse();

            try
            {
                using (var scope = _dbContextScopeFactory.Create())
                {
                    List <AttachmentDto> attachmentDtos = dto.Attachments.ToList();
                    dto.Attachments = null;
                    TaskItemAssign entity = _objectRepository.GetAll().Where(e => e.Id == dto.Id).FirstOrDefault();
                    if (entity != null)
                    {
                        TaskItem taskEntity = _taskItemRepository.GetAll().Where(e => e.Id == entity.TaskItemId).FirstOrDefault();
                        if (!dto.IsFullControl && taskEntity.AssignBy != dto.ModifiedBy && entity.AssignTo != dto.ModifiedBy)
                        {
                            sendMessage = SendMessageResponse.CreateFailedResponse("AccessDenied");
                            return(sendMessage);
                        }
                        if (DateTime.TryParseExact(dto.ExtendDateText, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime extendDate))
                        {
                            dto.ExtendDate = extendDate;
                        }
                        else
                        {
                            dto.ExtendDate = null;
                        }
                        entity.AppraiseProcess = dto.AppraiseProcess;
                        entity.AppraiseStatus  = dto.AppraiseStatus;
                        entity.FinishedDate    = dto.FinishedDate;
                        entity.FromDate        = dto.FromDate;
                        entity.IsDeleted       = dto.IsDeleted;
                        entity.ModifiedDate    = dto.ModifiedDate;
                        entity.Problem         = dto.Problem;
                        entity.Solution        = dto.Solution;
                        entity.ToDate          = dto.ToDate;
                        if (entity.AssignTo == dto.ModifiedBy && !dto.IsAssignBy)
                        {
                            switch (dto.ActionText)
                            {
                            case "Process":
                                dto.TaskItemStatusId = TaskItemStatusId.InProcess;
                                dto.ActionId         = ActionId.Process;
                                entity.PercentFinish = dto.PercentFinish;
                                break;

                            case "Report":
                                if (taskEntity.IsReport == false)
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.Finished;
                                    dto.ActionId         = ActionId.Finish;
                                }
                                else
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.Report;
                                    dto.ActionId         = ActionId.Report;
                                }
                                entity.PercentFinish = dto.PercentFinish;
                                break;

                            case "Extend":
                                entity.IsExtend      = true;
                                entity.ExtendDate    = dto.ExtendDate;
                                dto.ActionId         = ActionId.Extend;
                                entity.PercentFinish = dto.PercentFinish;

                                break;

                            case "ReturnReport":
                                dto.TaskItemStatusId = TaskItemStatusId.ReportReturn;
                                dto.ActionId         = ActionId.Return;
                                break;

                            default:
                                break;
                            }
                            if (entity.TaskType != TaskType.Primary)
                            {
                                dto.TaskItemStatusId = TaskItemStatusId.Read;
                            }
                            entity.LastResult = dto.Description;
                            //entity.IsExtend = dto.IsExtend;
                            //entity.ExtendDate = dto.ExtendDate;
                        }
                        if (taskEntity.AssignBy == dto.ModifiedBy && dto.IsAssignBy)
                        {
                            switch (dto.ActionText)
                            {
                            case "Appraise":
                                dto.ActionId = ActionId.Appraise;

                                if (entity.TaskItemStatusId == TaskItemStatusId.Extend)
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.InProcess;
                                }
                                else if (entity.TaskItemStatusId == TaskItemStatusId.Report)
                                {
                                    dto.TaskItemStatusId         = TaskItemStatusId.Finished;
                                    entity.AppraisePercentFinish = dto.AppraisePercentFinish;
                                    entity.PercentFinish         = dto.AppraisePercentFinish;
                                    dto.ActionId = ActionId.Finish;
                                }
                                else if (entity.TaskItemStatusId == TaskItemStatusId.ReportReturn)
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.Cancel;
                                }
                                break;

                            case "Return":
                                dto.TaskItemStatusId         = TaskItemStatusId.InProcess;
                                entity.AppraisePercentFinish = dto.AppraisePercentFinish;
                                entity.PercentFinish         = dto.AppraisePercentFinish;
                                dto.ActionId = ActionId.Return;
                                break;

                            case "AppraiseExtend":
                                entity.ExtendDate = dto.ExtendDate;
                                taskEntity.ToDate = dto.ExtendDate;
                                entity.IsExtend   = false;
                                dto.ActionId      = ActionId.Appraise;
                                break;

                            case "ReturnExtend":
                                entity.ExtendDate = null;
                                entity.IsExtend   = false;
                                dto.ActionId      = ActionId.Return;
                                break;

                            default:
                                break;
                            }
                            entity.AppraiseResult = dto.Description;
                        }

                        entity.TaskItemStatusId = dto.TaskItemStatusId;
                        TaskItemProcessHistory taskAssignHistory = new TaskItemProcessHistory
                        {
                            Id               = Guid.NewGuid(),
                            ProjectId        = entity.ProjectId,
                            ActionId         = dto.ActionId,
                            CreatedBy        = dto.ModifiedBy,
                            PercentFinish    = entity.PercentFinish,
                            CreatedDate      = dto.ModifiedDate,
                            TaskItemId       = entity.TaskItemId,
                            TaskItemAssignId = entity.Id,
                            TaskItemStatusId = entity.TaskItemStatusId,
                            ProcessResult    = dto.Description
                        };
                        if (entity.TaskType == TaskType.Primary || dto.IsAssignBy)
                        {
                            //TaskItemProcessHistory taskHistory = new TaskItemProcessHistory
                            //{
                            //    Id = Guid.NewGuid(),
                            //    ProjectId = entity.ProjectId,
                            //    ActionId = dto.ActionId,
                            //    CreatedBy = dto.ModifiedBy,
                            //    PercentFinish = dto.PercentFinish,
                            //    CreatedDate = dto.ModifiedDate,
                            //    TaskItemId = entity.TaskItemId,
                            //    TaskItemStatusId = entity.TaskItemStatusId,
                            //    ProcessResult = dto.Description
                            //};
                            taskEntity.TaskItemStatusId = entity.TaskItemStatusId;
                            taskEntity.PercentFinish    = entity.PercentFinish;
                            //_taskItemProcessHistoryRepository.Add(taskHistory);
                        }

                        _objectRepository.Modify(entity);
                        //_taskItemRepository.Modify(taskEntity);
                        _taskItemProcessHistoryRepository.Add(taskAssignHistory);
                        foreach (AttachmentDto attachDto in attachmentDtos)
                        {
                            attachDto.ProjectId = entity.ProjectId;
                            attachDto.ItemId    = entity.Id;
                            Attachment attach = _mapper.Map <Attachment>(attachDto);
                            _attachmentRepository.Add(attach);
                        }
                        if (dto.AttachDelIds != null)
                        {
                            if (dto.AttachDelIds.Any())
                            {
                                List <Attachment> attachDels = _attachmentRepository.GetAll().Where(e => dto.AttachDelIds.Contains(e.Id)).ToList();
                                _attachmentRepository.DeleteRange(attachDels);
                            }
                        }
                        await scope.SaveChangesAsync();

                        var param = new List <SqlParameter>();
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.UniqueIdentifier,
                            ParameterName = "@ProjectId",
                            IsNullable    = false,
                            Value         = dto.ProjectId
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.UniqueIdentifier,
                            ParameterName = "@TaskId",
                            IsNullable    = false,
                            Value         = taskEntity.Id
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.DateTime,
                            ParameterName = "@FromDate",
                            IsNullable    = false,
                            Value         = taskEntity.FromDate
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.DateTime,
                            ParameterName = "@ToDate",
                            IsNullable    = false,
                            Value         = taskEntity.ToDate
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.Bit,
                            ParameterName = "@IsUpdateStatus",
                            IsNullable    = true,
                            Value         = 1
                        });
                        await _objectRepository.SqlQueryAsync(typeof(ProjectDto), "[dbo].[SP_UPDATE_TASK_RANGE_DATE] @ProjectId, @TaskId, @FromDate, @ToDate, @IsUpdateStatus", param.ToArray());
                    }
                }
                sendMessage = SendMessageResponse.CreateSuccessResponse(string.Empty);
                return(sendMessage);
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                sendMessage = SendMessageResponse.CreateFailedResponse(string.Empty);
                return(sendMessage);
            }
        }