public async Task AddNotificationAudit(Audit notificationAudit) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationAudit.NotificationId); this.context.NotificationAudit.Add(notificationAudit); await this.context.SaveChangesAsync(); }
public async Task <NumberOfShipmentsHistory> GetOriginalNumberOfShipments(Guid notificationId) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationId); return(await context.NumberOfShipmentsHistories.Where(x => x.NotificationId == notificationId) .OrderBy(x => x.DateChanged) .FirstOrDefaultAsync()); }
public async Task GetAllSharedUsersChecksAuthorization() { var shared = new SharedUser(notification.Id, sharedUser.Id, DateTimeOffset.Now); context.SharedUser.Add(shared); await context.SaveChangesAsync(); await repository.GetAllSharedUsers(notification.Id); A.CallTo(() => authorization.EnsureAccessAsync(notification.Id)).MustHaveHappened(); }
public async Task <NotificationDatesSummary> GetById(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); var assessment = await notificationAssessmentRepository.GetByNotificationId(notificationId); var notification = await notificationApplicationRepository.GetById(notificationId); var paymentReceived = await transactionCalculator.PaymentReceivedDate(notificationId) ?? await transactionCalculator.LatestPayment(notificationId); DateTime?paymentReceivedDate = null; if (paymentReceived != null) { paymentReceivedDate = paymentReceived.Date; } return(NotificationDatesSummary.Load( assessment.Status, assessment.Dates.NotificationReceivedDate, notificationId, paymentReceivedDate, await transactionCalculator.IsPaymentComplete(notificationId), assessment.Dates.CommencementDate, assessment.Dates.NameOfOfficer, assessment.Dates.CompleteDate, assessment.Dates.TransmittedDate, assessment.Dates.AcknowledgedDate, await decisionRequiredBy.GetDecisionRequiredByDate(notification, assessment), assessment.Dates.FileClosedDate, assessment.Dates.ArchiveReference)); }
public async Task <Consultation> GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context .Consultations .SingleOrDefaultAsync(c => c.NotificationId == notificationId)); }
public async Task <MeansOfTransport> GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context .MeansOfTransports .SingleOrDefaultAsync(x => x.NotificationId == notificationId)); }
public async Task <NotificationApplicationOverview> GetById(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); var query = from notification in db.NotificationApplications where notification.Id == notificationId from wasteRecovery //left join waste recovery, if it exists in db.WasteRecoveries .Where(wr => wr.NotificationId == notification.Id) .DefaultIfEmpty() from assessment //left join assessment, if it exists in db.NotificationAssessments .Where(na => na.NotificationApplicationId == notification.Id) .DefaultIfEmpty() from wasteDiposal in db.WasteDisposals .Where(wd => wd.NotificationId == notification.Id) .DefaultIfEmpty() from exporter in db.Exporters .Where(e => e.NotificationId == notification.Id) .DefaultIfEmpty() from importer in db.Importers .Where(i => i.NotificationId == notification.Id) .DefaultIfEmpty() from shipmentInfo in db.ShipmentInfos .Where(si => si.NotificationId == notification.Id) .DefaultIfEmpty() select new { Notification = notification, WasteRecovery = wasteRecovery, WasteDisposal = wasteDiposal, NotificationAssessment = assessment, ShipmentInfo = shipmentInfo, Exporter = exporter, Importer = importer }; var data = await query.SingleAsync(); return(NotificationApplicationOverview.Load( data.Notification, data.NotificationAssessment, data.WasteRecovery, data.WasteDisposal, data.Exporter, data.Importer, decimal.ToInt32(await chargeCalculator.GetValue(notificationId)), progressService.GetNotificationProgressInfo(notificationId))); }
public async Task <FileData> HandleAsync(GetFile message) { await authorization.EnsureAccessAsync(message.NotificationId); var file = await fileRepository.Get(message.FileId); return(new FileData { Name = file.Name, Type = file.Type, Content = file.Content }); }
public async Task <IList <NotificationAssessmentDecision> > GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); var assessment = await context.NotificationAssessments.SingleOrDefaultAsync(n => n.NotificationApplicationId == notificationId); var consent = await context.Consents.SingleOrDefaultAsync(n => n.NotificationApplicationId == notificationId); var result = new List <NotificationAssessmentDecision>(); if (assessment.Dates.ConsentedDate != null) { result.Add(new NotificationAssessmentDecision(notificationId, assessment.Dates.ConsentedDate.GetValueOrDefault(), consent.ConsentRange.From, consent.ConsentRange.To, NotificationStatus.Consented)); } if (assessment.Dates.WithdrawnDate != null) { result.Add(new NotificationAssessmentDecision(notificationId, assessment.Dates.WithdrawnDate.GetValueOrDefault(), null, null, NotificationStatus.Withdrawn)); } if (assessment.Dates.ObjectedDate != null) { result.Add(new NotificationAssessmentDecision(notificationId, assessment.Dates.ObjectedDate.GetValueOrDefault(), null, null, NotificationStatus.Objected)); } if (assessment.Dates.ConsentWithdrawnDate != null) { result.Add(new NotificationAssessmentDecision(notificationId, assessment.Dates.ConsentWithdrawnDate.GetValueOrDefault(), null, null, NotificationStatus.ConsentWithdrawn)); } return(result.OrderByDescending(r => r.Date).ToList()); }
public async Task <Guid?> HandleAsync(GetNotificationIdByNumber message) { var id = await notificationApplicationRepository.GetIdOrDefault(FormatNotificationNumber(message.NotificationNumber)); if (id != null) { try { await notificationApplicationAuthorization.EnsureAccessAsync(id.Value); } catch (Exception) { return(null); } } return(id); }
public async Task <Exporter> GetByNotificationId(Guid notificationId) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationId); return(await context.Exporters.SingleAsync(e => e.NotificationId == notificationId)); }
public async Task <ProducerCollection> GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context.Producers.SingleAsync(x => x.NotificationId == notificationId)); }
public async Task <NotificationAssessment> GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context.NotificationAssessments.SingleAsync(p => p.NotificationApplicationId == notificationId)); }
public async Task <NotificationApplication> GetById(Guid id) { await notificationApplicationAuthorization.EnsureAccessAsync(id); return(await context.NotificationApplications.SingleAsync(n => n.Id == id)); }
public async Task <TransportRoute> GetByNotificationId(Guid notificationId) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationId); return(await context.TransportRoutes.SingleOrDefaultAsync(p => p.NotificationId == notificationId)); }
public async Task <ShipmentInfo> GetByNotificationId(Guid notificationId) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationId); return(await context.ShipmentInfos.SingleOrDefaultAsync(si => si.NotificationId == notificationId)); }
public async Task <IEnumerable <SharedUser> > GetAllSharedUsers(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context.SharedUser.Where(x => x.NotificationId == notificationId).ToArrayAsync()); }
public async Task <WasteDisposal> GetByNotificationId(Guid notificationId) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationId); return(await context.WasteDisposals.SingleOrDefaultAsync(i => i.NotificationId == notificationId)); }
public async Task <FinancialGuaranteeCollection> GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context.FinancialGuarantees.SingleAsync(fg => fg.NotificationId == notificationId)); }
public async Task <NotificationMovementsSummary> GetById(Guid notificationId) { await notificationAuthorization.EnsureAccessAsync(notificationId); var summaryData = await context.NotificationApplications .GroupJoin( context.ShipmentInfos, notification => notification.Id, shipment => shipment.NotificationId, (notification, shipments) => new { Notification = notification, Shipment = shipments.FirstOrDefault() }) .Join(context.NotificationAssessments, x => x.Notification.Id, na => na.NotificationApplicationId, (x, na) => new { x.Notification, x.Shipment, NotificationAssessment = na }) .Select(x => new { NotificationId = x.Notification.Id, x.Notification.NotificationType, x.Notification.NotificationNumber, NumberOfShipments = x.Shipment == null ? 0 : x.Shipment.NumberOfShipments, Quantity = x.Shipment == null ? 0 : x.Shipment.Quantity, Units = x.Shipment == null ? ShipmentQuantityUnits.Tonnes : x.Shipment.Units, NotificationStatus = x.NotificationAssessment.Status, x.Notification.CompetentAuthority }) .SingleAsync(x => x.NotificationId == notificationId); var totalMovements = await context.Movements .Where(m => m.NotificationId == notificationId) .CountAsync(); var currentActiveLoads = await context.Movements .Where(m => m.NotificationId == notificationId && (m.Status == MovementStatus.Submitted || m.Status == MovementStatus.Received || m.Status == MovementStatus.New || m.Status == MovementStatus.Captured || m.Status == MovementStatus.PartiallyRejected) && m.Date <= SystemTime.UtcNow) .CountAsync(); var financialGuaranteeCollection = await context.FinancialGuarantees.SingleAsync(x => x.NotificationId == notificationId); var financialGuarantee = financialGuaranteeCollection.GetCurrentApprovedFinancialGuarantee() ?? financialGuaranteeCollection.GetLatestFinancialGuarantee(); var averageShipmentInfo = await quantity.AveragePerShipment(notificationId, summaryData.NumberOfShipments); return(NotificationMovementsSummary.Load(summaryData.NotificationId, summaryData.NotificationNumber, summaryData.NotificationType, summaryData.NumberOfShipments, totalMovements, financialGuarantee == null ? 0 : financialGuarantee.ActiveLoadsPermitted.GetValueOrDefault(), currentActiveLoads, summaryData.Quantity, (await quantity.Received(notificationId)).Quantity, summaryData.Units, financialGuarantee == null ? FinancialGuaranteeStatus.AwaitingApplication : financialGuarantee.Status, summaryData.CompetentAuthority, summaryData.NotificationStatus, averageShipmentInfo)); }
public async Task <FacilityCollection> GetByNotificationId(Guid notificationId) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationId); return(await context.Facilities.SingleAsync(f => f.NotificationId == notificationId)); }
public async Task Add(MovementAudit audit) { await notificationApplicationAuthorization.EnsureAccessAsync(audit.NotificationId); context.MovementAudits.Add(audit); }
public async Task <WasteRecovery> GetByNotificationId(Guid notificationId) { await notificationApplicationAuthorization.EnsureAccessAsync(notificationId); return(await context.WasteRecoveries.SingleOrDefaultAsync(ri => ri.NotificationId == notificationId)); }
public async Task EnsureAccessAsync(Guid movementId) { var notificationId = (await repository.GetById(movementId)).NotificationId; await notificationAuthorization.EnsureAccessAsync(notificationId); }
public async Task GetNotificationByIdChecksAuthorization() { var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery, UKCompetentAuthority.England, 20181); context.NotificationApplications.Add(notification); context.SaveChanges(); var notificationId = notification.Id; var repository = new NotificationApplicationRepository(context, notificationApplicationAuthorization); await repository.GetById(notificationId); A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened(); context.DeleteOnCommit(notification); await context.SaveChangesAsync(); }
public async Task <IEnumerable <Movement> > GetMovementsByStatus(Guid notificationId, MovementStatus status) { await notificationAuthorization.EnsureAccessAsync(notificationId); return(await context.Movements .Where(m => m.NotificationId == notificationId && m.Status == status) .ToArrayAsync()); }
public async Task <CarrierCollection> GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context.Carriers.SingleAsync(c => c.NotificationId == notificationId)); }
public async Task <Consent> GetByNotificationId(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context.Consents.SingleAsync(c => c.NotificationApplicationId == notificationId)); }
public async Task <IList <NotificationTransaction> > GetTransactions(Guid notificationId) { await authorization.EnsureAccessAsync(notificationId); return(await context.NotificationTransactions.Where(n => n.NotificationId == notificationId).ToListAsync()); }