public ProfitsForProduct GetProfitForProduct(Guid productId, Expression <Func <Transaction, bool> > TransactionPredicate = null) { Product Product = ProductRepo.Get(x => x.Id == productId); ProfitsForProduct ProfitRecords = new ProfitsForProduct(); ProfitRecords.Product = Product; 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> > ProfitsPerYear = new Dictionary <int, Dictionary <Month, double> >(); ProfitsPerYear = GroupProfitsPerYear(TransactionsForProduct); foreach (var item in ProfitsPerYear) { int Year = item.Key; Dictionary <Month, double> ProfitsPerMonth = item.Value; ProfitRecords.ProfitsForProductInYear.Add(new ProfitsForProductInYear() { Year = Year, ProfitsPerMonth = ProfitsPerMonth, }); } return(ProfitRecords); }
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); }
/// <summary> /// Updates Transaction View /// </summary> private void UpdateView() { using (var repo = new TransactionRepo()) { transactionViewSource.Source = repo.GetAll(); } }
public ActionResult Index() { ViewBag.profits = ProfitLogic.GetProfitForProducts(x => x.StoreId == LoggedInUser.StoreId).Sum(x => x.ProfitsForProductInYear.Sum(y => y.ProfitsPerMonth.Sum(z => z.Value))); ViewBag.sales = SalesL.GetSalesForProducts(x => x.StoreId == LoggedInUser.StoreId).Sum(x => x.TransactionsForProductInYear.Sum(y => y.TransactionsPerMonth.Sum(z => z.Value))); ViewBag.transactions = TransactionRepo.GetAll(x => x.Batch.Product.StoreId == LoggedInUser.StoreId).Count(); ViewBag.products = ProductRepo.GetAll(x => x.StoreId == LoggedInUser.StoreId).Count(); ProfitLogic.GetProfitForProducts(x => x.StoreId == LoggedInUser.StoreId); return(View()); }
public List <Transaction> FetchCompletedAuctionTransactionsForBatch(Guid productInStoreId) { IEnumerable <Transaction> AllRecords = TransactionRepo.GetAll(x => x.BatchId == productInStoreId && x.TransactionType == TransactionType.Auction); List <Transaction> CompletedTransactions = new List <Transaction>(); foreach (var item in AllRecords) { AuctionTransactionStatus StateRecord = AuctionTransactionStatusRepo.Get(x => x.TransactionId == item.Id); if (StateRecord.Status == AuctionState.Compleete) { CompletedTransactions.Add(item); } } return(CompletedTransactions); }
public void Withdraw_AmountWithdrawn_TransactionShowsInRepo(int amount, string transactionDate) { var mockDateProvider = new Mock <IDateProvider>(); mockDateProvider.Setup(m => m.TodayToString()).Returns(transactionDate); var transactionRepo = new TransactionRepo(mockDateProvider.Object); var subject = GetTestSubject(transactionRepo); subject.Withdraw(amount); var transactions = transactionRepo.GetAll(); Assert.AreEqual(1, transactions.Count); var actual = transactions[0].Amount; Assert.AreEqual(amount, actual); var actualDate = transactions[0].Date; Assert.AreEqual(transactionDate, actualDate); }
public Transaction[] TransactionForProductByCriteria(Expression <Func <Transaction, bool> > TransactionPredicate = null) { return(TransactionRepo.GetAll().Where(TransactionPredicate).ToArray()); }
public List <Transaction> GetTransactionsForProduct(Guid productId) { return(TransactionRepo.GetAll(x => x.Batch.ProductId == productId).ToList()); }
public IQueryable <Transaction> ViewQueryableAuctionTransactionforProductBatch(Guid productInStoreId) => TransactionRepo.GetAll(x => x.BatchId == productInStoreId && x.TransactionType == TransactionType.Auction);