public async Task <Result <Guid> > Handle(QueueExportBillingsCommand request, CancellationToken token) { var sender = await _context.Users.SingleAsync(e => e.Id == request.UserId, token); if (sender.Id != request.RequestUser.Id) { return(Failure <Guid>("Vous n'êtes pas autorisé à accéder à cette ressource.")); } if (request.DeliveryIds == null || !request.DeliveryIds.Any()) { return(Failure <Guid>("Vous devez selectionner les livraisons à exporter.")); } var command = new ExportBillingsCommand(request.RequestUser) { JobId = Guid.NewGuid(), DeliveryIds = request.DeliveryIds }; var entity = new Domain.Job(command.JobId, JobKind.ExportUserBillings, request.Name ?? $"Export comptabilité spécifique", sender, command); await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); _mediatr.Post(command); return(Success(entity.Id)); }
public async Task <Result <Guid> > Handle(QueueExportTimeRangedBillingsCommand request, CancellationToken token) { var sender = await _context.Users.SingleAsync(e => e.Id == request.UserId, token); if (sender.Id != request.RequestUser.Id) { return(Failure <Guid>("Vous n'êtes pas autorisé à accéder à cette ressource.")); } var command = new ExportTimeRangedBillingsCommand(request.RequestUser) { JobId = Guid.NewGuid(), From = request.From, To = request.To, Kinds = request.Kinds }; var entity = new Domain.Job(command.JobId, JobKind.ExportUserBillingsTimeRange, request.Name ?? $"Export comptabilité du {request.From:dd/MM/yyyy} au {request.To:dd/MM/yyyy}", sender, command); await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); _mediatr.Post(command); return(Success(entity.Id)); }
public async Task <Result <Guid> > Handle(QueueImportProductsCommand request, CancellationToken token) { var producer = await _context.Producers.SingleAsync(e => e.Id == request.ProducerId, token); var command = new ImportProductsCommand(request.RequestUser) { JobId = Guid.NewGuid(), NotifyOnUpdates = request.NotifyOnUpdates }; var entity = new Domain.Job(command.JobId, JobKind.ImportProducts, $"Import produits", producer, command); var response = await _blobService.UploadImportProductsFileAsync(request.ProducerId, entity.Id, request.FileStream, token); if (!response.Succeeded) { return(Failure <Guid>(response)); } await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); _mediatr.Post(command); return(Success(entity.Id)); }
public async Task <Result <IEnumerable <Guid> > > Handle(QueueSendRecallsCommand request, CancellationToken token) { var recalls = await _context.Recalls.Where(b => request.RecallIds.Contains(b.Id)).ToListAsync(token); if (recalls == null || !recalls.Any()) { return(Failure <IEnumerable <Guid> >("La campagne de rappel est introuvable.")); } var jobIds = new List <Guid>(); string error = null; foreach (var recall in recalls) { if (recall.Status != RecallStatus.Waiting) { error = "La campagne de rappel n'est pas en attente."; break; } if (recall.ProducerId != request.RequestUser.Id) { error = "Vous n'êtes pas autorisé à accéder à cette ressource."; break; } var command = new SendRecallCommand(request.RequestUser) { JobId = Guid.NewGuid(), RecallId = recall.Id }; var entity = new Domain.Job(command.JobId, JobKind.SendRecalls, $"Envoi campagne de rappel", recall.Producer, command); recall.SetAsReady(); await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); _mediatr.Post(command); jobIds.Add(entity.Id); } if (!string.IsNullOrEmpty(error)) { return(Failure <IEnumerable <Guid> >(error)); } return(Success <IEnumerable <Guid> >(jobIds)); }
public async Task <Result <Guid> > Handle(QueueExportUserDataCommand request, CancellationToken token) { var sender = await _context.Users.SingleAsync(e => e.Id == request.UserId, token); if (sender.Id != request.RequestUser.Id) { return(Failure <Guid>("Vous n'êtes pas autorisé à accéder à cette ressource.")); } var command = new ExportUserDataCommand(request.RequestUser) { JobId = Guid.NewGuid() }; var entity = new Domain.Job(command.JobId, JobKind.ExportUserData, $"Export RGPD", sender, command); await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); _mediatr.Post(command); return(Success(entity.Id)); }