public async Task CalculateProperties(IList <ItemSale> itemSales)
        {
            if (!itemSales.Any())
            {
                ExecuteValidation(new ItemSaleValidation(), new ItemSale());
                return;
            }

            foreach (var itemSale in itemSales)
            {
                var vinylDisc = await _vinylDiscDapperRepository.GetById(itemSale.VinylDiscId);

                if (!VinylDisc.Exists(vinylDisc))
                {
                    Notify($"VinylDiscId: {itemSale.VinylDiscId} not exists");
                    return;
                }

                itemSale.SetValue(itemSale.Quantity, vinylDisc.Value);
                itemSale.SetCashback(itemSale.Value, await _configCashbackService.GetPercentage(vinylDisc.MusicGenreId));

                if (!ExecuteValidation(new ItemSaleValidation(), itemSale))
                {
                    return;
                }
            }
        }
        private static Sale MapSaleDapperQuery(IDictionary <int, Sale> saleDictionary, Sale sale,
                                               ItemSale itemSale, VinylDisc vinylDisc)
        {
            if (!saleDictionary.TryGetValue(sale.SaleId, out var saleEntry))
            {
                saleEntry = sale;
                saleDictionary.Add(saleEntry.SaleId, saleEntry);
            }

            itemSale.SetVinylDisc(vinylDisc);
            saleEntry.AddItemSale(itemSale);

            return(saleEntry);
        }
Ejemplo n.º 3
0
 public void SetVinylDisc(VinylDisc vinylDisc)
 {
     VinylDisc = vinylDisc;
 }