public async Task <StatusCodes> UpdateItemAsync(Role entity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - RolesRepo_UpdateItemAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.RoleListId
                };

                // Create Json object for SharePoint create list item
                dynamic itemFieldsJson = new JObject();
                itemFieldsJson.AdGroupName     = entity.AdGroupName.Trim();
                itemFieldsJson.Role            = entity.DisplayName.Trim();
                itemFieldsJson.TeamsMembership = entity.TeamsMembership.Name.ToString();
                itemFieldsJson.Permissions     = JsonConvert.SerializeObject(entity.Permissions, Formatting.Indented);

                await _graphSharePointAppService.UpdateListItemAsync(siteList, entity.Id, itemFieldsJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - RolesRepo_UpdateItemAsync finished creating SharePoint list item.");

                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - RolesRepo_UpdateItemAsync error: {ex}");
                throw;
            }
        }
        public async Task <StatusCodes> UpdateItemAsync(Groups entity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - GroupsRepo_UpdateItemAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.GroupsListId
                };

                dynamic itemFieldsJson = new JObject();
                dynamic itemJson       = new JObject();
                itemFieldsJson.GroupName = entity.GroupName;
                itemFieldsJson.Title     = entity.Id;
                itemFieldsJson.Process   = JsonConvert.SerializeObject(entity.Processes, Formatting.Indented);
                itemJson.fields          = itemFieldsJson;

                await _graphSharePointAppService.UpdateListItemAsync(siteList, entity.Id, itemJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - GroupsRepo_UpdateItemAsync finished creating SharePoint list item.");

                await CacheTryGetGroupsListAsync(requestId);

                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - GroupsRepo_UpdateItemAsync error: {ex}");
                throw;
            }
        }
        public async Task <StatusCodes> UpdateItemAsync(MetaData entity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - MetaDataRepo_UpdateItemAsync called.");

            try
            {
                // Create Json object for SharePoint create list item
                dynamic itemFieldsJson = new JObject();
                itemFieldsJson.FieldName = entity.DisplayName;
                itemFieldsJson.FieldType = entity.FieldType.Name.ToString();
                if (entity.FieldType.Name == FieldType.DropDown.Name)
                {
                    itemFieldsJson.FieldValue = JsonConvert.SerializeObject(entity.Values, Formatting.Indented);
                }
                else
                {
                    itemFieldsJson.FieldValue = entity.Values;
                }
                itemFieldsJson.FieldScreen = entity.Screen;

                await _graphSharePointAppService.UpdateListItemAsync(siteList, entity.Id, itemFieldsJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - MetaDataRepo_UpdateItemAsync finished creating SharePoint list item.");

                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - MetaDataRepo_UpdateItemAsync error: {ex}");
                throw;
            }
        }
Esempio n. 4
0
        public async Task <StatusCodes> UpdateItemAsync(Tasks entity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - TasksRepo_UpdateItemAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.TasksListId
                };

                // Create Json object for SharePoint create list item
                dynamic itemJson = new JObject();
                itemJson.Title = entity.Id;
                itemJson.Name  = entity.Name;

                var result = await _graphSharePointAppService.UpdateListItemAsync(siteList, entity.Id, itemJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - TasksRepo_UpdateItemAsync finished creating SharePoint list item.");

                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - TasksRepo_UpdateItemAsync error: {ex}");
                throw;
            }
        }
Esempio n. 5
0
        public async Task <StatusCodes> UpdateOpportunityAsync(Dashboard dashboard, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync called.");
            Guard.Against.Null(dashboard, nameof(dashboard), requestId);
            Guard.Against.NullOrEmpty(dashboard.OpportunityId, nameof(dashboard.OpportunityId), requestId);

            try
            {
                _logger.LogInformation($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync SharePoint List for dashboard.");

                dynamic dashboardJson = new JObject();


                dashboardJson.Status               = dashboard.Status;
                dashboardJson.StartDate            = dashboard.StartDate;
                dashboardJson.OpportunityName      = dashboard.OpportunityName;
                dashboardJson.TargetCompletionDate = dashboard.TargetCompletionDate ?? String.Empty;
                dashboardJson.OpportunityID        = dashboard.OpportunityId;
                dashboardJson.TotalNoOfDays        = dashboard.TotalNoOfDays;

                dashboardJson.ProcessNoOfDays = JsonConvert.SerializeObject(dashboard.ProcessList, Formatting.Indented);

                dashboardJson.ProcessEndDates = JsonConvert.SerializeObject(dashboard.ProcessEndDateList, Formatting.Indented);

                dashboardJson.ProcessLoanOfficers = JsonConvert.SerializeObject(dashboard.ProcessLoanOfficerNames, Formatting.Indented);

                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.DashboardListId
                };

                var result = await _graphSharePointAppService.UpdateListItemAsync(siteList, dashboard.Id, dashboardJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync finished SharePoint List for dashboard.");
                //For DashBoard---
                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync Service Exception: {ex}");
            }
        }
Esempio n. 6
0
        public async Task <StatusCodes> UpdateItemAsync(Opportunity opportunity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync called.");
            Guard.Against.Null(opportunity, nameof(opportunity), requestId);
            Guard.Against.NullOrEmpty(opportunity.Id, nameof(opportunity.Id), requestId);

            try
            {
                // TODO: This section will be replaced with a workflow
                _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync SharePoint List for opportunity.");

                //Granular Access : Start
                var access = await CheckAccessAsync(PermissionNeededTo.WritePartial, PermissionNeededTo.Write, PermissionNeededTo.WriteAll, requestId);

                var currentUser = (_userContext.User.Claims).ToList().Find(x => x.Type == "preferred_username")?.Value;
                if (!access.haveSuperAcess && !access.haveAccess && !access.havePartial)
                {
                    // This user is not having any write permissions, so he won't be able to update
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                }
                else if (!access.haveSuperAcess)
                {
                    if (!(opportunity.Content.TeamMembers).ToList().Any
                            (teamMember => teamMember.Fields.UserPrincipalName == currentUser))
                    {
                        // This user is not having any write permissions, so he won't be able to update
                        _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                        throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    }
                }
                //Granular Access : End

                // Workflow processor
                opportunity = await _opportunityFactory.UpdateWorkflowAsync(opportunity, requestId);

                //Get loan officer & relationship manager values
                var loanOfficerId          = String.Empty;
                var relationshipManagerId  = String.Empty;
                var loanOfficerUpn         = String.Empty;
                var relationshipManagerUpn = String.Empty;
                foreach (var item in opportunity.Content.TeamMembers)
                {
                    if (item.AssignedRole.DisplayName == "LoanOfficer" && !String.IsNullOrEmpty(item.Id))
                    {
                        loanOfficerId  = item.Id;
                        loanOfficerUpn = item.Fields.UserPrincipalName;
                    }
                    if (item.AssignedRole.DisplayName == "RelationshipManager" && !String.IsNullOrEmpty(item.Id))
                    {
                        relationshipManagerId  = item.Id;
                        relationshipManagerUpn = item.Fields.UserPrincipalName;
                    }
                }


                var opportunityJObject = JObject.FromObject(opportunity);

                // Create Json object for SharePoint create list item
                dynamic opportunityJson = new JObject();
                opportunityJson.OpportunityId       = opportunity.Id;
                opportunityJson.OpportunityState    = opportunity.Metadata.OpportunityState.Name;
                opportunityJson.OpportunityObject   = JsonConvert.SerializeObject(opportunity, Formatting.Indented);
                opportunityJson.LoanOfficer         = loanOfficerId;
                opportunityJson.RelationshipManager = relationshipManagerId;
                opportunityJson.Reference           = opportunity.Reference ?? String.Empty;

                var opportunitySiteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.OpportunitiesListId
                };
                var result = await _graphSharePointAppService.UpdateListItemAsync(opportunitySiteList, opportunity.Id, opportunityJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync finished SharePoint List for opportunity.");
                //For DashBoard---
                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync Service Exception: {ex}");
            }
        }
        public async Task <StatusCodes> UpdateItemAsync(Opportunity opportunity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync called.");
            Guard.Against.Null(opportunity, nameof(opportunity), requestId);
            Guard.Against.NullOrEmpty(opportunity.Id, nameof(opportunity.Id), requestId);

            try
            {
                // TODO: This section will be replaced with a workflow
                _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync SharePoint List for opportunity.");

                // Check access
                var checkAccess = await _opportunityFactory.CheckAccessAnyAsync(opportunity, requestId);

                if (!checkAccess)
                {
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync CheckAccessAny");
                }

                // Workflow processor
                opportunity = await _opportunityFactory.UpdateWorkflowAsync(opportunity, requestId);

                //Get loan officer & relationship manager values
                var loanOfficerId          = String.Empty;
                var relationshipManagerId  = String.Empty;
                var loanOfficerUpn         = String.Empty;
                var relationshipManagerUpn = String.Empty;
                foreach (var item in opportunity.Content.TeamMembers)
                {
                    if (item.AssignedRole.DisplayName == "LoanOfficer" && !String.IsNullOrEmpty(item.Id))
                    {
                        loanOfficerId  = item.Id;
                        loanOfficerUpn = item.Fields.UserPrincipalName;
                    }
                    if (item.AssignedRole.DisplayName == "RelationshipManager" && !String.IsNullOrEmpty(item.Id))
                    {
                        relationshipManagerId  = item.Id;
                        relationshipManagerUpn = item.Fields.UserPrincipalName;
                    }
                }


                var opportunityJObject = JObject.FromObject(opportunity);

                // Create Json object for SharePoint create list item
                dynamic opportunityJson = new JObject();
                opportunityJson.OpportunityId = opportunity.Id;
                //opportunityJson.Name = opportunity.DisplayName; TODO: In wave 1 nme can't be changed
                opportunityJson.OpportunityState  = opportunity.Metadata.OpportunityState.Name;
                opportunityJson.OpportunityObject = JsonConvert.SerializeObject(opportunity, Formatting.Indented);
                //opportunityJson.OpportunityObject = opportunityJObject.ToString();
                opportunityJson.LoanOfficer         = loanOfficerId;
                opportunityJson.RelationshipManager = relationshipManagerId;

                var opportunitySiteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.OpportunitiesListId
                };
                var result = await _graphSharePointAppService.UpdateListItemAsync(opportunitySiteList, opportunity.Id, opportunityJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync finished SharePoint List for opportunity.");


                // Update entry in Opportunities public sub site
                var opportunitySubSiteList = new SiteList
                {
                    SiteId = _appOptions.OpportunitiesSubSiteId,
                    ListId = _appOptions.PublicOpportunitiesListId
                };


                // Create Json object for SharePoint create list item
                dynamic pubOpportunityFieldsJson = new JObject();
                pubOpportunityFieldsJson.Title               = opportunity.DisplayName;
                pubOpportunityFieldsJson.LoanOfficer         = loanOfficerUpn;
                pubOpportunityFieldsJson.RelationshipManager = relationshipManagerUpn;
                pubOpportunityFieldsJson.State               = opportunity.Metadata.OpportunityState.Name;

                var options = new List <QueryParam>();
                options.Add(new QueryParam("filter", $"startswith(fields/Title,'{opportunity.DisplayName}')"));

                try
                {
                    var json = await _graphSharePointAppService.GetListItemAsync(opportunitySubSiteList, options, "All", requestId);

                    Guard.Against.Null(json, "OpportunityRepository_UpdateItemAsync GetListItemAsync Null", requestId);
                    dynamic jsonDyn       = json;
                    string  opportunityId = jsonDyn.value[0].fields.id.ToString();
                    if (!String.IsNullOrEmpty(opportunityId))
                    {
                        var resultPub = await _graphSharePointAppService.UpdateListItemAsync(opportunitySubSiteList, opportunityId, pubOpportunityFieldsJson.ToString(), requestId);
                    }
                }
                catch (Exception ex)
                {
                    // Dont brak the opportunity creation of entry can't be updated to subsite (public)
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync SubsiteOpportunity Service Exception: {ex}");
                }

                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - OpportunityRepository_UpdateItemAsync Service Exception: {ex}");
            }
        }
Esempio n. 8
0
        public async Task <StatusCodes> UpdateOpportunityAsync(Dashboard dashboard, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync called.");
            Guard.Against.Null(dashboard, nameof(dashboard), requestId);
            Guard.Against.NullOrEmpty(dashboard.OpportunityId, nameof(dashboard.OpportunityId), requestId);

            try
            {
                _logger.LogInformation($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync SharePoint List for dashboard.");

                dynamic dashboardJson = new JObject();

                dashboardJson.Title             = dashboard.Id;
                dashboardJson.Status            = dashboard.Status;
                dashboardJson.StatusChangedDate = dashboard.StatusChangedDate;

                if (dashboard.TargetCompletionDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.TargetCompletionDate = dashboard.TargetCompletionDate;
                }
                if (dashboard.RiskAssesmentCompletionDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.RiskAssesmentCompletionDate = dashboard.RiskAssesmentCompletionDate;
                }
                if (dashboard.RiskAssesmentStartDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.RiskAssesmentStartDate = dashboard.RiskAssesmentStartDate;
                }
                if (dashboard.CreditCheckCompletionDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.CreditCheckCompletionDate = dashboard.CreditCheckCompletionDate;
                }
                if (dashboard.CreditCheckStartDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.CreditCheckStartDate = dashboard.CreditCheckStartDate;
                }
                if (dashboard.ComplianceReviewComplteionDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.ComplianceRewiewCompletionDate = dashboard.ComplianceReviewComplteionDate;
                }
                if (dashboard.ComplianceReviewStartDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.ComplianceRewiewStartDate = dashboard.ComplianceReviewStartDate;
                }
                if (dashboard.FormalProposalCompletionDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.FormalProposalEndDateDate = dashboard.FormalProposalCompletionDate;
                }
                if (dashboard.FormalProposalStartDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.FormalProposalStartDate = dashboard.FormalProposalStartDate;
                }
                if (dashboard.OpportunityEndDate != DateTimeOffset.MinValue)
                {
                    dashboardJson.OpportunityEndDate = dashboard.OpportunityEndDate;
                }

                if (!string.IsNullOrEmpty(dashboard.LoanOfficer))
                {
                    dashboardJson.LoanOfficer = dashboard.LoanOfficer;
                }
                if (!string.IsNullOrEmpty(dashboard.RelationshipManager))
                {
                    dashboardJson.RelationshipManager = dashboard.RelationshipManager;
                }

                dashboardJson.TotalNoOfDays            = dashboard.TotalNoOfDays;
                dashboardJson.CreditCheckNoOfDays      = dashboard.CreditCheckNoOfDays;
                dashboardJson.ComplianceReviewNoOfDays = dashboard.ComplianceReviewNoOfDays;
                dashboardJson.FormalProposalNoOfDays   = dashboard.FormalProposalNoOfDays;
                dashboardJson.RiskAssessmentNoOfDays   = dashboard.RiskAssessmentNoOfDays;

                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.DashboardListId
                };

                var result = await _graphSharePointAppService.UpdateListItemAsync(siteList, dashboard.Id, dashboardJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync finished SharePoint List for dashboard.");
                //For DashBoard---
                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - DashBoard_UpdateOpportunityAsync Service Exception: {ex}");
            }
        }