Exemple #1
0
        private WorkflowHistoryDto CreateWaitingApprovalRecord(GetByFormNumberInput input)
        {
            var newRecord = new WorkflowHistoryDto();

            newRecord.FORM_NUMBER = input.FormNumber;
            if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval2)
            {
                newRecord.ACTION = Enums.ActionType.WaitingForApproval2;
            }
            else
            {
                newRecord.ACTION = Enums.ActionType.WaitingForApproval;
            }



            string displayUserId = "";

            if (input.IsRejected)
            {
                displayUserId  = input.RejectedBy;
                newRecord.ROLE = Enums.UserRole.POA;
            }
            else
            {
                if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval || input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval2)
                {
                    List <POADto> listPoa;
                    if (input.FormType == Enums.FormType.PBCK1)
                    {
                        listPoa = _poaBll.GetPoaByNppbkcIdAndMainPlant(input.NppbkcId).Distinct().ToList();
                        if (listPoa.Count > 0)
                        {
                            listPoa = listPoa.Where(c => c.POA_ID != input.DocumentCreator).Distinct().ToList();
                        }
                        displayUserId = listPoa.Aggregate("", (current, poaDto) => current + (poaDto.POA_ID + ","));
                    }
                    else
                    {
                        var isPoaCreatedUser = _poaBll.GetActivePoaById(input.DocumentCreator);
                        if (isPoaCreatedUser != null)
                        {
                            //created user is poa, let's get poa list in one Nppbkc
                            listPoa = _poaBll.GetPoaActiveByNppbkcId(input.NppbkcId).Distinct().ToList();
                            if (listPoa.Count > 0)
                            {
                                listPoa = listPoa.Where(c => c.POA_ID != isPoaCreatedUser.POA_ID).Distinct().ToList();
                            }
                        }
                        else
                        {
                            listPoa = !string.IsNullOrEmpty(input.PlantId) ? _poaBll.GetPoaActiveByPlantId(input.PlantId).Distinct().ToList()
                            : _poaBll.GetPoaActiveByNppbkcId(input.NppbkcId).Distinct().ToList();
                        }

                        //old code
                        //displayUserId = listPoa.Aggregate("", (current, poaMapDto) => current + (poaMapDto.POA_ID + ","));
                    }

                    //add delegate poa
                    List <string> listUser        = listPoa.Select(c => c.POA_ID).ToList();
                    var           listPoaDelegate =
                        _poaDelegationServices.GetListPoaDelegateByDate(listUser, DateTime.Now);
                    listUser.AddRange(listPoaDelegate);

                    displayUserId = string.Join(",", listUser.Distinct());

                    //if (displayUserId.Length > 0)
                    //    displayUserId = displayUserId.Substring(0, displayUserId.Length - 1);

                    newRecord.ROLE = Enums.UserRole.POA;
                }
                else if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApprovalController)
                {
                    //get action by poa
                    //var poaId = GetPoaByDocumentNumber(input.FormNumber);
                    //displayUserId = _poaBll.GetManagerIdByPoaId(poaId);
                    var controllerList = _userBll.GetControllers();
                    displayUserId = string.Join(",", controllerList.Select(c => c.USER_ID).Distinct());

                    newRecord.ROLE = Enums.UserRole.Controller;
                }
            }



            newRecord.UserId = displayUserId;


            return(newRecord);
        }