Ejemplo n.º 1
0
        public async Task <OpportunityViewModel> OpportunityToViewModelAsync(Opportunity entity, string requestId = "")
        {
            var oppId = entity.Id;

            try
            {
                //var entityDto = TinyMapper.Map<OpportunityViewModel>(entity);
                var viewModel = new OpportunityViewModel
                {
                    Id                   = entity.Id,
                    DisplayName          = entity.DisplayName,
                    Reference            = entity.Reference,
                    Version              = entity.Version,
                    OpportunityState     = OpportunityStateModel.FromValue(entity.Metadata.OpportunityState.Value),
                    OpportunityChannelId = entity.Metadata.OpportunityChannelId,
                    //TODO
                    TemplateLoaded = entity.TemplateLoaded,

                    //TODO : WAVE-4 GENERIC ACCELERATOR Change : start
                    MetaDataFields = entity.Metadata.Fields.Select(
                        field => new OpportunityMetaDataFields()
                    {
                        DisplayName = field.DisplayName,
                        FieldType   = field.FieldType,
                        Screen      = field.Screen,
                        Values      = field.Values
                    }
                        ).ToList(),
                    //TODO : WAVE-4 GENERIC ACCELERATOR Change : end
                    Customer = new CustomerModel
                    {
                        DisplayName = entity.Metadata.Customer.DisplayName,
                        Id          = entity.Metadata.Customer.Id,
                        ReferenceId = entity.Metadata.Customer.ReferenceId
                    },
                    TeamMembers = new List <TeamMemberModel>(),
                    Notes       = new List <NoteModel>(),
                    Checklists  = new List <ChecklistModel>()
                };

                //DealType
                var dealTypeFlag = false;
                dealTypeFlag = entity.Content.Template is null || entity.Content.Template.Id is null;
                if (!dealTypeFlag)
                {
                    viewModel.Template = await _templateHelpers.MapToViewModel(entity.Content.Template);

                    //DealType Processes
                    var checklistPass = false;
                    foreach (var item in entity.Content.Template.ProcessList)
                    {
                        if (item.ProcessType.ToLower() == "checklisttab" && checklistPass == false)
                        {
                            viewModel = await _checkListProcessService.MapToModelAsync(entity, viewModel, requestId);

                            checklistPass = true;
                        }
                        if (item.ProcessType.ToLower() == "customerdecisiontab")
                        {
                            viewModel = await _customerDecisionProcessService.MapToModelAsync(entity, viewModel, requestId);
                        }
                        if (item.ProcessType.ToLower() == "customerfeedbacktab")
                        {
                            viewModel = await _customerFeedbackProcessService.MapToModelAsync(entity, viewModel, requestId);
                        }
                        if (item.ProcessType.ToLower() == "proposalstatustab")
                        {
                            viewModel = await _proposalStatusProcessService.MapToModelAsync(entity, viewModel, requestId);
                        }
                    }
                }


                // TeamMembers
                foreach (var item in entity.Content.TeamMembers.ToList())
                {
                    var memberModel = new TeamMemberModel();
                    memberModel.RoleId            = item.RoleId; //await _userProfileHelpers.RoleToViewModelAsync(item.AssignedRole, requestId);
                    memberModel.Id                = item.Id;
                    memberModel.DisplayName       = item.DisplayName;
                    memberModel.Mail              = item.Fields.Mail;
                    memberModel.UserPrincipalName = item.Fields.UserPrincipalName;
                    memberModel.Title             = item.Fields.Title ?? String.Empty;
                    memberModel.ProcessStep       = item.ProcessStep;
                    memberModel.Permissions       = new List <PermissionModel>();
                    memberModel.AdGroupName       = await _graphUserAppService.GetAdGroupName(item.RoleId, requestId);

                    memberModel.RoleName = item.RoleName;
                    foreach (var permission in item.Fields.Permissions)
                    {
                        memberModel.Permissions.Add(new PermissionModel {
                            Id = permission.Id, Name = permission.Name
                        });
                    }
                    memberModel.TeamsMembership = new TeamsMembershipModel()
                    {
                        Value = item.TeamsMembership.Value,
                        Name  = item.TeamsMembership.Name.ToString()
                    };
                    viewModel.TeamMembers.Add(memberModel);
                }

                // Notes
                foreach (var item in entity.Content.Notes.ToList())
                {
                    var note = new NoteModel();
                    note.Id = item.Id;

                    var userProfile = new UserProfileViewModel();
                    userProfile.Id                = item.CreatedBy.Id;
                    userProfile.DisplayName       = item.CreatedBy.DisplayName;
                    userProfile.Mail              = item.CreatedBy.Fields.Mail;
                    userProfile.UserPrincipalName = item.CreatedBy.Fields.UserPrincipalName;
                    userProfile.UserRoles         = await _userProfileHelpers.RolesToViewModelAsync(item.CreatedBy.Fields.UserRoles, requestId);

                    note.CreatedBy       = userProfile;
                    note.NoteBody        = item.NoteBody;
                    note.CreatedDateTime = item.CreatedDateTime;

                    viewModel.Notes.Add(note);
                }

                // DocumentAttachments
                viewModel.DocumentAttachments = new List <DocumentAttachmentModel>();
                if (entity.DocumentAttachments != null)
                {
                    foreach (var itm in entity.DocumentAttachments)
                    {
                        var doc = new DocumentAttachmentModel();
                        doc.Id            = itm.Id ?? String.Empty;
                        doc.FileName      = itm.FileName ?? String.Empty;
                        doc.Note          = itm.Note ?? String.Empty;
                        doc.Tags          = itm.Tags ?? String.Empty;
                        doc.Category      = new CategoryModel();
                        doc.Category.Id   = itm.Category.Id;
                        doc.Category.Name = itm.Category.Name;
                        doc.DocumentUri   = itm.DocumentUri;

                        viewModel.DocumentAttachments.Add(doc);
                    }
                }

                return(viewModel);
            }
            catch (Exception ex)
            {
                // TODO: _logger.LogError("MapToViewModelAsync error: " + ex);
                throw new ResponseException($"RequestId: {requestId} - OpportunityToViewModelAsync oppId: {oppId} - failed to map opportunity: {ex}");
            }
        }
Ejemplo n.º 2
0
        public async Task <OpportunityViewModel> OpportunityToViewModelAsync(Opportunity entity, string requestId = "")
        {
            var oppId = entity.Id;

            try
            {
                //var entityDto = TinyMapper.Map<OpportunityViewModel>(entity);
                var viewModel = new OpportunityViewModel
                {
                    Id               = entity.Id,
                    DisplayName      = entity.DisplayName,
                    Reference        = entity.Reference,
                    Version          = entity.Version,
                    OpportunityState = OpportunityStateModel.FromValue(entity.Metadata.OpportunityState.Value),
                    DealSize         = entity.Metadata.DealSize,
                    AnnualRevenue    = entity.Metadata.AnnualRevenue,
                    OpenedDate       = entity.Metadata.OpenedDate,
                    //For DashBoard
                    TargetDate = entity.Metadata.TargetDate,
                    Industry   = new IndustryModel
                    {
                        Name = entity.Metadata.Industry.Name,
                        Id   = entity.Metadata.Industry.Id
                    },
                    Region = new RegionModel
                    {
                        Name = entity.Metadata.Region.Name,
                        Id   = entity.Metadata.Region.Id
                    },
                    Margin               = entity.Metadata.Margin,
                    Rate                 = entity.Metadata.Rate,
                    DebtRatio            = entity.Metadata.DebtRatio,
                    Purpose              = entity.Metadata.Purpose,
                    DisbursementSchedule = entity.Metadata.DisbursementSchedule,
                    CollateralAmount     = entity.Metadata.CollateralAmount,
                    Guarantees           = entity.Metadata.Guarantees,
                    RiskRating           = entity.Metadata.RiskRating,
                    OpportunityChannelId = entity.Metadata.OpportunityChannelId,
                    Customer             = new CustomerModel
                    {
                        DisplayName = entity.Metadata.Customer.DisplayName,
                        Id          = entity.Metadata.Customer.Id,
                        ReferenceId = entity.Metadata.Customer.ReferenceId
                    },
                    TeamMembers = new List <TeamMemberModel>(),
                    Notes       = new List <NoteModel>(),
                    Checklists  = new List <ChecklistModel>()
                };

                //DealType
                var dealTypeFlag = false;
                dealTypeFlag = entity.Content.DealType is null || entity.Content.DealType.Id is null;
                if (!dealTypeFlag)
                {
                    viewModel.DealType = await _templateHelpers.MapToViewModel(entity.Content.DealType);

                    //DealType Processes
                    var checklistPass = false;
                    foreach (var item in entity.Content.DealType.ProcessList)
                    {
                        if (item.ProcessType.ToLower() == "checklisttab" && checklistPass == false)
                        {
                            viewModel = await _checkListProcessService.MapToModelAsync(entity, viewModel, requestId);

                            checklistPass = true;
                        }
                        if (item.ProcessType.ToLower() == "customerdecisiontab")
                        {
                            viewModel = await _customerDecisionProcessService.MapToModelAsync(entity, viewModel, requestId);
                        }
                        if (item.ProcessType.ToLower() == "proposalstatustab")
                        {
                            viewModel = await _proposalStatusProcessService.MapToModelAsync(entity, viewModel, requestId);
                        }
                    }
                }



                // TeamMembers
                foreach (var item in entity.Content.TeamMembers.ToList())
                {
                    var memberModel = new TeamMemberModel();
                    memberModel.AssignedRole = await _userProfileHelpers.RoleToViewModelAsync(item.AssignedRole, requestId);

                    memberModel.Id                = item.Id;
                    memberModel.DisplayName       = item.DisplayName;
                    memberModel.Mail              = item.Fields.Mail;
                    memberModel.UserPrincipalName = item.Fields.UserPrincipalName;
                    memberModel.Title             = item.Fields.Title ?? String.Empty;
                    memberModel.ProcessStep       = item.ProcessStep;

                    viewModel.TeamMembers.Add(memberModel);
                }

                // Notes
                foreach (var item in entity.Content.Notes.ToList())
                {
                    var note = new NoteModel();
                    note.Id = item.Id;

                    var userProfile = new UserProfileViewModel();
                    userProfile.Id                = item.CreatedBy.Id;
                    userProfile.DisplayName       = item.CreatedBy.DisplayName;
                    userProfile.Mail              = item.CreatedBy.Fields.Mail;
                    userProfile.UserPrincipalName = item.CreatedBy.Fields.UserPrincipalName;
                    userProfile.UserRoles         = await _userProfileHelpers.RolesToViewModelAsync(item.CreatedBy.Fields.UserRoles, requestId);

                    note.CreatedBy       = userProfile;
                    note.NoteBody        = item.NoteBody;
                    note.CreatedDateTime = item.CreatedDateTime;

                    viewModel.Notes.Add(note);
                }

                // DocumentAttachments
                viewModel.DocumentAttachments = new List <DocumentAttachmentModel>();
                if (entity.DocumentAttachments != null)
                {
                    foreach (var itm in entity.DocumentAttachments)
                    {
                        var doc = new DocumentAttachmentModel();
                        doc.Id            = itm.Id ?? String.Empty;
                        doc.FileName      = itm.FileName ?? String.Empty;
                        doc.Note          = itm.Note ?? String.Empty;
                        doc.Tags          = itm.Tags ?? String.Empty;
                        doc.Category      = new CategoryModel();
                        doc.Category.Id   = itm.Category.Id;
                        doc.Category.Name = itm.Category.Name;
                        doc.DocumentUri   = itm.DocumentUri;

                        viewModel.DocumentAttachments.Add(doc);
                    }
                }

                return(viewModel);
            }
            catch (Exception ex)
            {
                // TODO: _logger.LogError("MapToViewModelAsync error: " + ex);
                throw new ResponseException($"RequestId: {requestId} - OpportunityToViewModelAsync oppId: {oppId} - failed to map opportunity: {ex}");
            }
        }