public async Task <IList <Domain.Product> > Products([Parent] Domain.Catalog catalog, [Service] Domain.DataAccess.IProductRepository productRepository) { var products = new List <Domain.Product>(); foreach (var productID in catalog.Products) { var referencedProduct = await productRepository.GetProductById(productID); products.Add(referencedProduct); } return(products); }
public async Task <Result <Guid> > Handle(CreateCatalogCommand request, CancellationToken token) { using (var transaction = await _context.BeginTransactionAsync(token)) { var catalogs = await _context.Catalogs .Where(c => c.Producer.Id == request.RequestUser.Id) .ToListAsync(token); if (request.Kind == CatalogKind.Consumers && catalogs.Any(c => c.Kind == CatalogKind.Consumers)) { return(Failure <Guid>("Le catalogue pour les particuliers existe déjà.")); } var producer = await _context.Producers.SingleAsync(e => e.Id == request.ProducerId, token); var entity = new Domain.Catalog(producer, request.Kind, Guid.NewGuid(), request.Name); entity.SetIsAvailable(request.IsAvailable); entity.SetIsDefault(request.IsDefault); if (request.IsDefault && catalogs.Any(c => c.IsDefault && c.Kind == CatalogKind.Stores)) { var actualDefaultCatalog = catalogs.Single(c => c.IsDefault && c.Kind == CatalogKind.Stores); actualDefaultCatalog.SetIsDefault(false); } await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); var result = await _mediatr.Process( new AddOrUpdateProductsToCatalogCommand(request.RequestUser) { CatalogId = entity.Id, Products = request.Products }, token); if (!result.Succeeded) { return(Failure <Guid>(result)); } await transaction.CommitAsync(token); return(Success(entity.Id)); } }
public async Task <Result <Guid> > Handle(CloneCatalogCommand request, CancellationToken token) { using (var transaction = await _context.BeginTransactionAsync(token)) { var catalog = await _context.Catalogs.SingleAsync(e => e.Id == request.CatalogId, token); var entity = new Domain.Catalog(catalog.Producer, catalog.Kind, Guid.NewGuid(), request.Name); await _context.AddAsync(entity, token); await _context.SaveChangesAsync(token); var catalogProducts = await _context.Products .Where(p => p.CatalogsPrices.Any(cp => cp.CatalogId == request.CatalogId)) .ToListAsync(token); var products = catalogProducts.Select(p => new ProductPriceInputDto { ProductId = p.Id, WholeSalePricePerUnit = p.CatalogsPrices.Single(c => c.CatalogId == request.CatalogId).WholeSalePricePerUnit * (1 + (request.Percent / 100) ?? 0) }); var result = await _mediatr.Process( new AddOrUpdateProductsToCatalogCommand(request.RequestUser) { CatalogId = entity.Id, Products = products }, token); if (!result.Succeeded) { return(Failure <Guid>(result)); } await transaction.CommitAsync(token); return(Success(entity.Id)); } }
public string Name([Parent] Domain.Catalog catalog) { return(catalog.Name); }
public Guid ID([Parent] Domain.Catalog catalog) { return(catalog.ID); }
public LastNameReport(Domain.Catalog catalog) : base(catalog) { }
public BirthdateReport(Domain.Catalog catalog) : base(catalog) { }
public async Task <Result <Guid> > Handle(CreatePurchaseOrderCommand request, CancellationToken token) { var producer = await _context.Producers.SingleAsync(e => e.Id == request.ProducerId, token); var client = await _context.Users.SingleAsync(e => e.Id == request.ClientId, token); var deliveryMode = await _context.DeliveryModes.SingleAsync( d => d.Id == request.DeliveryModeId && d.ProducerId == producer.Id, token); if (client.Kind == ProfileKind.Consumer) { return(Failure <Guid>( "Cette fonction ne peux être utilisée que pour créer des commandes pour les professionels.")); } if (request.Products == null || !request.Products.Any()) { return(Failure <Guid>( "Vous devez ajouter des produits à votre commande.")); } if (request.Products.Any(p => p.Quantity <= 0)) { return(Failure <Guid>( "Un ou plusieurs produits possèdent une quantité inférieure ou égale à 0.")); } if (request.ExpectedDeliveryDate < DateTimeOffset.UtcNow) { return(Failure <Guid>( "La date de livraison ne peut être inférieure à aujourd'hui.")); } if (request.From > request.To) { return(Failure <Guid>( "L'heure de début ne peut être supérieure à l'heure de fin.")); } var productsQuantity = new List <KeyValuePair <Domain.Product, int> >(); var productIds = request.Products.Select(p => p.Id).Distinct(); var products = await _context.Products .Where(p => productIds.Contains(p.Id) && p.ProducerId == producer.Id) .ToListAsync(token); Domain.Catalog catalog = null; var agreement = await _context.Agreements.SingleAsync( a => a.StoreId == client.Id && a.ProducerId == producer.Id && a.Status == AgreementStatus.Accepted, token); if (agreement != null) { catalog = agreement.Catalog; } catalog ??= await _context.Catalogs.SingleAsync( c => c.ProducerId == producer.Id && c.Kind == CatalogKind.Stores && c.Available && c.IsDefault, token); foreach (var product in products) { var quantity = request.Products.Where(p => p.Id == product.Id).Sum(p => p.Quantity); productsQuantity.Add(new KeyValuePair <Domain.Product, int>(product, quantity ?? 0)); } var resultIdentifier = await _identifierService.GetNextPurchaseOrderReferenceAsync(request.ProducerId, token); if (!resultIdentifier.Succeeded) { return(Failure <Guid>(resultIdentifier)); } var purchaseOrder = new Domain.PurchaseOrder(Guid.NewGuid(), resultIdentifier.Data, PurchaseOrderStatus.Accepted, request.ExpectedDeliveryDate, request.From, request.To, deliveryMode, producer, client, productsQuantity, catalog, request.SkipNotification, request.Comment); await _context.AddAsync(purchaseOrder, token); await _context.SaveChangesAsync(token); if (deliveryMode.MaxPurchaseOrdersPerTimeSlot.HasValue) { await _tableService.IncreaseProducerDeliveryCountAsync(producer.Id, deliveryMode.Id, request.ExpectedDeliveryDate, request.From, request.To, deliveryMode.MaxPurchaseOrdersPerTimeSlot.Value, token); } return(Success(purchaseOrder.Id)); }
public Report(Domain.Catalog catalog) { this.catalog = catalog; }