public static RecallMailerModel GetNotificationData(this Domain.Recall recall, string recallId, string url, string comment, string username) { return(new RecallMailerModel { ProducerName = recall.Producer.Name, User = username, Comment = comment, Batches = recall.Batches?.Select(b => new BatchMailerModel { Number = b.Batch.Number, DDM = b.Batch.DDM, DLC = b.Batch.DLC, }).ToList() ?? new List <BatchMailerModel>(), Products = recall.Products?.Select(b => new ProductMailerModel { Name = b.Name, Reference = b.Reference }).ToList() ?? new List <ProductMailerModel>(), CreatedOn = recall.CreatedOn, SaleEndedOn = recall.SaleEndedOn, SaleStartedOn = recall.SaleStartedOn, RecallId = recallId, PortalUrl = $"{url}/#/public/recalls/{recallId}?refresh={Guid.NewGuid():N}" }); }
public async Task <Result <Guid> > Handle(CreateRecallCommand request, CancellationToken token) { var batches = request.BatchIds != null ? await _context.Batches .Where(b => request.BatchIds.Contains(b.Id)) .ToListAsync(token) : new List <Domain.Batch>(); var products = request.ProductIds != null ? await _context.Products .Where(b => request.ProductIds.Contains(b.Id)) .ToListAsync(token) : new List <Domain.Product>(); var clientIds = await _context.PurchaseOrders .Where(po => po.Picking.PreparedProducts.Any(pp => pp.PurchaseOrderId == po.Id && request.ProductIds.Contains(pp.ProductId)) || po.Picking.PreparedProducts.Any(pp => pp.PurchaseOrderId == po.Id && pp.Batches.Any(b => request.BatchIds.Contains(b.BatchId)))) .Select(po => po.ClientId) .ToListAsync(token); var clients = await _context.Users .Where(u => clientIds.Contains(u.Id)) .ToListAsync(token); var producer = await _context.Producers.SingleOrDefaultAsync(p => p.Id == request.ProducerId, token); var entity = new Domain.Recall(Guid.NewGuid(), request.Name, request.SaleStartedOn, request.SaleEndedOn, request.Comment, producer, products); entity.SetBatches(batches); entity.SetClients(clients); await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); return(Success(entity.Id)); }
public static StringContent GetNotificationContent(this Domain.Recall recall, string recallId, string url, string username) { return(new StringContent(JsonConvert.SerializeObject(recall.GetNotificationData(recallId, url, null, username)), Encoding.UTF8, "application/json")); }