public async Task <Opportunity> CreateWorkflowAsync(Opportunity opportunity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - CreateDashBoardEntryAsync called.");
            try
            {
                var targetDate = opportunity.Metadata.Fields.ToList().Find(x => x.DisplayName.Equals("Target Date", StringComparison.OrdinalIgnoreCase))?.Values;
                var openedDate = opportunity.Metadata.Fields.ToList().Find(x => x.DisplayName.Equals("Opened Date", StringComparison.OrdinalIgnoreCase))?.Values;

                if (targetDate != null && openedDate != null)
                {
                    var entity = new Dashboard();
                    entity.CustomerName    = opportunity.Metadata.Customer.DisplayName;
                    entity.Status          = opportunity.Metadata.OpportunityState.Name;
                    entity.StartDate       = openedDate ?? String.Empty;
                    entity.OpportunityName = opportunity.DisplayName;
                    entity.OpportunityId   = opportunity.Id;
                    entity.Id                      = String.Empty;
                    entity.TotalNoOfDays           = 0;
                    entity.ProcessList             = new List <DashboardProcessList>();
                    entity.ProcessEndDateList      = new List <DashboradProcessEndDateList>();
                    entity.ProcessLoanOfficerNames = new List <DashboardLoanOfficers>();

                    var processList = (await _processRepository.GetAllAsync(requestId)).ToList().Where(x => x.ProcessType.Equals("checklisttab", StringComparison.OrdinalIgnoreCase));

                    foreach (var process in processList)
                    {
                        entity.ProcessList.Add(new DashboardProcessList
                        {
                            ProcessName      = process.Channel.ToLower(),
                            ProcessEndDate   = string.Empty,
                            ProcessStartDate = string.Empty,
                            NoOfDays         = 0
                        });

                        entity.ProcessEndDateList.Add(new DashboradProcessEndDateList
                        {
                            Process = process.Channel.ToLower() + "enddate",
                            EndDate = string.Empty
                        });
                    }

                    var loanOfficerAdgroup = opportunity.Content.TeamMembers.FirstOrDefault(mem => mem.Fields.Permissions.Any(per => per.Name.Equals("opportunity_readwrite_dealtype", StringComparison.OrdinalIgnoreCase)));
                    entity.ProcessLoanOfficerNames.Add(new DashboardLoanOfficers
                    {
                        AdGroupName = loanOfficerAdgroup != null ? loanOfficerAdgroup.RoleName : string.Empty,
                        OfficerName = loanOfficerAdgroup != null ? loanOfficerAdgroup.DisplayName : string.Empty
                    });

                    await _dashboardRepository.CreateOpportunityAsync(entity, requestId);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - CreateDashBoardEntryAsync Service Exception: {ex}");
            }

            return(opportunity);
        }
Esempio n. 2
0
        public async Task <StatusCodes> CreateOpportunityAsync(DashboardModel modelObject, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - DashboardSvc_CreateOpportunityAsync called.");

            Guard.Against.Null(modelObject, nameof(modelObject), requestId);
            Guard.Against.NullOrEmpty(modelObject.CustomerName, nameof(modelObject.CustomerName), requestId);
            try
            {
                var entityObject = MapToEntity(modelObject, requestId);

                var result = await _dashboardRepository.CreateOpportunityAsync(entityObject, requestId);

                Guard.Against.NotStatus200OK(result, "DashboardSvc_CreateOpportunityAsync", requestId);

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