public ProductViewModel() { InStoreRecords = new List <Batch>(); ToBeAuctionedRecords = new List <ProductToBeAuctioned>(); AuctionRecords = new List <Auction>(); Sales = new TransactionsForProduct(); }
public TransactionsForProduct GetTransactionsForProduct(Guid productId, out Dictionary <int, Dictionary <Month, double> > TurnoverPerYear, Expression <Func <Transaction, bool> > TransactionPredicate = null) { Product Product = ProductRepo.Get(x => x.Id == productId); TransactionsForProduct TransactionsRecords = new TransactionsForProduct(); Batch[] ProductInStoreRecords = BatchRepo.GetAll(x => x.ProductId == productId).ToArray(); Guid[] ProductInStoreIds = ProductInStoreRecords.Select(x => x.Id).ToArray(); Transaction[] TransactionsForProduct = TransactionPredicate == null?TransactionRepo.GetAll(x => x.Batch.ProductId == productId).OrderBy(x => x.DateOfTransaction).ToArray() : TransactionRepo.GetAll(x => x.Batch.ProductId == productId).Where(TransactionPredicate).OrderBy(x => x.DateOfTransaction).ToArray(); Dictionary <int, Dictionary <Month, double> > TransactionsPerYear = new Dictionary <int, Dictionary <Month, double> >(); TransactionsPerYear = GroupTransactionsPerYear(TransactionsForProduct, out TurnoverPerYear); if (TransactionsPerYear != null) { foreach (var item in TransactionsPerYear) { int Year = item.Key; Dictionary <Month, double> TransactionsPerMonth = item.Value; TransactionsRecords.TransactionsForProductInYear.Add(new TransactionsForProductInYear() { Year = Year, TransactionsPerMonth = TransactionsPerMonth }); } TransactionsRecords.Product = Product; return(TransactionsRecords); } return(null); }
public double GetSaleQuantityForProduct(Guid productId, int year = 0, Month month = Month.None) { Dictionary <int, Dictionary <Month, double> > TurnoverReport = new Dictionary <int, Dictionary <Month, double> >(); TransactionsForProduct SalesRecords = GetTransactionsForProduct(productId, out TurnoverReport); TransactionsForProductInYear SalesRecordForYear = SalesRecords.TransactionsForProductInYear.FirstOrDefault(x => x.Year == year); return(year == 0 ? SalesRecords.TransactionsForProductInYear.Sum(x => x.TransactionsPerMonth.Sum(y => y.Value)) : (month == Month.None ? SalesRecordForYear.TransactionsPerMonth.Sum(x => x.Value) : SalesRecordForYear.TransactionsPerMonth[month])); }
public Dictionary <string, double> SalesForProduct(Guid productId) { Dictionary <int, Dictionary <Month, double> > TurnoverRecords; Dictionary <string, double> Report = new Dictionary <string, double>(); TransactionsForProduct SalesRecords = SalesLogic.GetSalesForProduct(productId, out TurnoverRecords); if (SalesRecords != null) { SalesRecords.TransactionsForProductInYear.ForEach(x => { Report.Add(x.Year.ToString(), x.TransactionsPerMonth.Sum(y => y.Value)); }); } return(Report); }
public Dictionary <string, double> AuctionsForProduct(Guid productId) { Dictionary <string, double> Report = new Dictionary <string, double>(); try { TransactionsForProduct Auctionrecords = AuctionLogic.GetAuctionsForProduct(productId); Auctionrecords.TransactionsForProductInYear.ForEach(x => { Report.Add(x.Year.ToString(), x.TransactionsPerMonth.Sum(y => y.Value)); }); } catch { } return(Report); }
public void CompileMonthlySalesAuctionRatio(ref SalesAuctionViewModel monthlyRatioRecord, TransactionsForProduct salesRecords, TransactionsForProduct auctionRecords, Month month) { int Year = monthlyRatioRecord.Year; double SalesQuantity = salesRecords.TransactionsForProductInYear.FirstOrDefault(x => x.Year == Year).TransactionsPerMonth[month]; double AuctionQuantity = auctionRecords.TransactionsForProductInYear.FirstOrDefault(x => x.Year == Year).TransactionsPerMonth[month]; monthlyRatioRecord.Record.Add(new SalesAuctionMonthlyViewModel() { Month = Month.February, AuctionQuantity = AuctionQuantity, SalesQuantity = SalesQuantity, }); }
public List <SalesAuctionViewModel> GetSalesToAuctionRatio(Guid id) { List <SalesAuctionViewModel> TotalRatioRecords = new List <SalesAuctionViewModel>(); Dictionary <int, Dictionary <Month, double> > TurnoverReport = new Dictionary <int, Dictionary <Month, double> >(); TransactionsForProduct SalesRecord = GetTransactionsForProduct(id, out TurnoverReport, x => x.TransactionType == TransactionType.Sale); TransactionsForProduct AuctionRecords = GetTransactionsForProduct(id, out TurnoverReport, x => x.TransactionType == TransactionType.Auction); if (SalesRecord != null && AuctionRecords != null) { int StartYear = SalesRecord.StartYear < AuctionRecords.StartYear ? SalesRecord.StartYear : AuctionRecords.StartYear; int EndYear = SalesRecord.EndYear > AuctionRecords.EndYear ? SalesRecord.EndYear : AuctionRecords.EndYear; for (int i = StartYear; i <= EndYear; i++) { SalesAuctionViewModel YearlyRatioRecord = new SalesAuctionViewModel() { Year = i, }; for (Month j = Month.January; j <= Month.December; ++j) { switch (j) { case Month.January: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.January); break; case Month.February: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.February); break; case Month.March: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.March); break; case Month.April: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.April); break; case Month.May: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.May); break; case Month.June: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.June); break; case Month.July: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.July); break; case Month.August: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.August); break; case Month.September: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.September); break; case Month.October: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.October); break; case Month.November: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.November); break; case Month.December: CompileMonthlySalesAuctionRatio(ref YearlyRatioRecord, SalesRecord, AuctionRecords, Month.December); break; } } TotalRatioRecords.Add(YearlyRatioRecord); } } return(TotalRatioRecords.Count > 0 ? TotalRatioRecords : null); }