/// <summary> /// Get list of transactions /// </summary> /// <returns>Transaction index list view</returns> public ActionResult Index() { using (var context = dataContextFactory.CreateByUser()) { //Eager loading Transaction var transactionQuery = (from x in context.Transactions orderby x.CreatedDateTime select x) .Include(x => x.TransactionItems.Select(s => s.Sku)) .Include(x => x.TransactionItems.Select(s => s.License)); var viewModel = new TransactionIndexViewModel(transactionQuery.OrderByDescending(x => x.CreatedDateTime).ToList()); return(View(viewModel)); } }
public async Task <ActionResult> Index() { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); var userTransactions = _db.Transactions.Include(transaction => transaction.Checkouts).Where(entry => entry.User.Id == currentUser.Id).ToList(); var transactionIds = userTransactions.Select(txn => txn.TransactionId); var userCheckouts = _db.Checkouts.Include(checkout => checkout.Copy).Where(checkout => transactionIds.Contains(checkout.TransactionId)).ToList(); var copies = _db.Copies.Include(copy => copy.Book).ToList(); TransactionIndexViewModel model = new TransactionIndexViewModel() { Transactions = userTransactions, Books = copies, Checkouts = userCheckouts }; // var userCopies = userTransactions.Select() return(View(model)); }
public TransactionIndexViewModel BuildTransactionIndexViewModel(int userId, int?projectId) { var transactions = _dbContext.Transactions.Where(x => x.CreatorID == userId); if (projectId.HasValue) { transactions = transactions.Where(x => x.ProjectID == projectId.Value); } var items = Mapper.Map <IList <TransactionIndexItemViewModel> >(transactions); var model = new TransactionIndexViewModel { Items = items }; return(model); }
public IActionResult IndexPost(TransactionIndexViewModel model) { if (_transactionManager.ActiveTransaction != null) { return(RedirectToAction("List", "Transaction")); } ProfileData customer = _dataContext.ProfileData.FirstOrDefault(q => q.Id == model.CustomerId); if (customer == null) { ModelState.AddModelError(nameof(model.CustomerId), "Onbekende klant id"); return(View("Index")); } _transactionManager.StartTransaction(customer); return(RedirectToAction("AddProduct")); }