예제 #1
0
        public async Task <Opportunity> CreateWorkflowAsync(Opportunity opportunity, string requestId = "")
        {
            try
            {
                _logger.LogError($"RequestId: {requestId} - Opportunityfactory_CreateWorkflowAsync CheckAccess CreateItemAsync");

                // Set initial opportunity state
                opportunity.Metadata.OpportunityState = OpportunityState.Creating;

                if (opportunity.Content.Template != null)
                {
                    if (opportunity.Content.Template.ProcessList != null)
                    {
                        if (opportunity.Content.Template.ProcessList.Count() > 1)
                        {
                            if (!opportunity.TemplateLoaded)
                            {
                                opportunity = await _teamChannelService.CreateWorkflowAsync(opportunity, requestId);

                                opportunity.Metadata.OpportunityState = OpportunityState.InProgress;
                            }
                            opportunity = await _memberService.CreateWorkflowAsync(opportunity, requestId);
                        }

                        bool checklistPass = false;
                        foreach (var item in opportunity.Content.Template.ProcessList)
                        {
                            if (item.ProcessType.ToLower() == "checklisttab" && checklistPass == false)
                            {
                                opportunity = await _checkListProcessService.CreateWorkflowAsync(opportunity, requestId);

                                checklistPass = true;
                            }
                            else if (item.ProcessType.ToLower() == "customerdecisiontab")
                            {
                                opportunity = await _customerDecisionProcessService.CreateWorkflowAsync(opportunity, requestId);
                            }
                            else if (item.ProcessType.ToLower() == "customerfeedbacktab")
                            {
                                opportunity = await _customerFeedbackProcessService.CreateWorkflowAsync(opportunity, requestId);
                            }
                            else if (item.ProcessType.ToLower() == "proposalstatustab")
                            {
                                opportunity = await _proposalStatusProcessService.CreateWorkflowAsync(opportunity, requestId);
                            }
                            else if (item.ProcessStep.ToLower() == "start process")
                            {
                                opportunity = await _startProcessService.CreateWorkflowAsync(opportunity, requestId);
                            }
                        }
                    }
                }
                else
                {
                    _logger.LogError($"RequestId: {requestId} - CreateWorkflowAsync Service Exception");
                    throw new AccessDeniedException($"RequestId: {requestId} - CreateWorkflowAsync Service Exception");
                }

                try
                {
                    opportunity = await _notesService.CreateWorkflowAsync(opportunity, requestId);

                    opportunity = await _dashboardService.CreateWorkflowAsync(opportunity, requestId);
                }
                catch
                {
                    _logger.LogError($"RequestId: {requestId} - CreateWorkflowAsync Service Exception");
                }

                return(opportunity);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - CreateWorkflowAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - CreateWorkflowAsync Service Exception: {ex}");
            }
        }