Beispiel #1
0
        public virtual async Task <IApplicationResult> CreateAsync(TDto dto)
        {
            return(await ExecuteAsync(async() =>
            {
                var isAdmin = await _roleService.IsAdminAsync(_inventAppContext.UserEmail);
                if (!isAdmin)
                {
                    throw new UnauthorizedAccessException($"Access Denied. Check permissions for User '{_inventAppContext.UserEmail}'");
                }

                await _duplicateValidator.ValidateAsync(dto);

                var aggregate = _factory.Create(dto);

                await _unitOfWork.GetRepository <TAggregateRoot>().AddAsync(aggregate);

                _auditService.AuditAsync(new Audit
                {
                    Application = "InventApp",
                    Environment = _appSettingsService.Environment.Name,
                    User = _inventAppContext.UserEmail,
                    EntityId = aggregate.Id.ToString(),
                    EntityName = aggregate.GetType().Name,
                    Entity = JsonConvert.SerializeObject(aggregate),
                    Action = AuditAction.Create
                });

                return new OkApplicationResult <Guid>
                {
                    Data = aggregate.Id
                };
            }));
        }
Beispiel #2
0
        /// <inheritdoc/>
        public async Task QueueContractEmailReminderMessage(Contract contract)
        {
            _logger.LogInformation($"Queuing email reminder for contract [{contract.ContractNumber}].");

            var message = new ContractReminderMessage()
            {
                ContractId = contract.Id
            };
            IDictionary <string, string> properties = new Dictionary <string, string>()
            {
                { "messageType", ContractReminderMessage.MessageProcessor_ContractReminderMessage }
            };

            await _sbMessagingService.SendAsBinaryXmlMessageAsync(message, properties);

            await _auditService.AuditAsync(
                new Pds.Audit.Api.Client.Models.Audit
            {
                Severity = 0,
                Action   = Audit.Api.Client.Enumerations.ActionType.ContractEmailReminderQueued,
                Ukprn    = contract.Ukprn,
                Message  = $"Email reminder has been queued for contract with Id [{contract.Id}].",
                User     = Audit_User_System
            });
        }
Beispiel #3
0
        public async Task <string> GetAsync(string requestQueryString, RequestType requestType)
        {
            using (var clientProxy = new HttpClient())
            {
                clientProxy.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _subscriptionKey);
                clientProxy.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header

                var requestRoute = requestType == RequestType.search ? $"{requestType.ToString()}?" : string.Empty;
                var fullRequest  = $"{_endpoint}/{requestRoute}{requestQueryString}";
                logger.Trace($"Getting API data for request :'{fullRequest}'");

                var response = await clientProxy.GetAsync(fullRequest);

                var responseContent = await response.Content?.ReadAsStringAsync();

                await auditService.AuditAsync(responseContent, requestQueryString);

                if (!response.IsSuccessStatusCode)
                {
                    logger.Error($"Error status {response.StatusCode},  Getting API data for request :'{fullRequest}' \nResponse : {responseContent}", null);
                    //this will throw an exception as is not a success code
                    await response.EnsureSuccessStatusCodeAsync();
                }
                return(responseContent);
            }
        }
        public async Task DeleteOrphanedAvsAsync()
        {
            logger.Info("Getting orphaned apprenticeship vacancies");
            var orphanedApprenticeshipVacancies = await apprenticeshipVacancyRepository.GetOrphanedApprenticeshipVacanciesAsync();

            await auditService.AuditAsync($"Got {orphanedApprenticeshipVacancies.Count()} orphaned apprenticeship vacancies");

            foreach (OrphanedVacancySummary o in orphanedApprenticeshipVacancies)
            {
                await auditService.AuditAsync($"Got orphaned apprenticeship deleting vacancies id= {o.Id} published = {o.PublicationDate.ToString()} title = {o.Title} vacancyId = {o.VacancyId}");

                await apprenticeshipVacancyRepository.DeleteByIdAsync(o.Id);
            }

            logger.Info("Completed deleting orphaned apprenticeship vacancies");
        }
Beispiel #5
0
        /// <inheritdoc/>
        public async Task ProcessMessage(ContractApprovedMessage message)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            _logger.LogInformation($"Sending approved contract notification for {message.ContractNumber}.");

            await Post(_configuration.ApiContractApproverEndpoint, message);

            try
            {
                await _audit.AuditAsync(new Audit.Api.Client.Models.Audit()
                {
                    Action   = ActionType.ContractApprovedMessageSentToFCS,
                    Severity = 0,
                    User     = ContractApproverUser,
                    Ukprn    = message.Ukprn,
                    Message  = $"Notified FCS of approved contract [{message.ContractNumber}] Version [{message.ContractVersionNumber}]."
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error when attempting to create an audit entry.");
            }
        }
Beispiel #6
0
        private async Task <PagedOdataResult <T> > GetInternalAsync(Uri requestUri, bool shouldAudit)
        {
            using (var client = await GetHttpClientAsync())
            {
                var resultMessage = await client.GetAsync(requestUri);

                if (resultMessage.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    throw new UnauthorizedAccessException(resultMessage.ReasonPhrase);
                }

                var result = await client.GetStringAsync(requestUri);

                logger.Info($"Requested with url - '{requestUri}'.");
                if (shouldAudit)
                {
                    await auditService.AuditAsync($"{requestUri} | {result}");
                }

                return(JsonConvert.DeserializeObject <PagedOdataResult <T> >(result));
            }
        }
Beispiel #7
0
        private async Task NotifyAsync <T>(T message, Contract contract, string component)
        {
            IDictionary <string, string> properties = new Dictionary <string, string>()
            {
                { "messageType", typeof(T).FullName }
            };

            await _serviceBusMessagingService.SendAsBinaryXmlMessageAsync(message, properties);

            await _auditService.AuditAsync(
                new Pds.Audit.Api.Client.Models.Audit
            {
                Severity = 0,
                Action   = Audit.Api.Client.Enumerations.ActionType.ContractNotificationForwarded,
                Ukprn    = contract.Ukprn,
                User     = Constants.Audit_User_System,
                Message  = Constants.ContractNotificationForwardedMessage
                           .ReplaceTokens(contract)
                           .ReplaceTokens(new Dictionary <string, string> {
                    { Constants.Component, component }
                })
            });
        }