// GET: CheckingAccounts/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CheckingAccount checkingAccount = db.CheckingAccounts.Find(id); if (checkingAccount == null) { return(HttpNotFound()); } CheckingAccountDetailsViewModel model = new CheckingAccountDetailsViewModel { CheckingAccountID = id, CheckingAccount = checkingAccount, Transactions = checkingAccount.Transactions }; ViewBag.Count = checkingAccount.Transactions.Count(); ViewBag.TransactionTypes = new SelectList(Utilities.Utility.TranscationTypes); return(View(model)); }
public ActionResult Details(CheckingAccountDetailsViewModel model, String TransactionNumber, String DateRange, String Description, String TransactionType, String PriceRange, String RangeFrom, String RangeTo, SortBy TransactionNumberSort, SortBy TransactionTypeSort, SortBy DescriptionSort, SortBy AmountSort, SortBy DateSort) { int?id = model.CheckingAccountID; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CheckingAccount checkingAccount = db.CheckingAccounts.Find(id); CheckingAccountDetailsViewModel modelToPass = new CheckingAccountDetailsViewModel { CheckingAccountID = id, CheckingAccount = checkingAccount, Transactions = checkingAccount.Transactions }; if (checkingAccount == null) { return(HttpNotFound()); } var query = from t in checkingAccount.Transactions select t; if (TransactionNumber != null && TransactionNumber != "") { Int32 number; try { number = Convert.ToInt32(TransactionNumber); query = query.Where(t => t.TransactionID.Equals(number)); } catch { ViewBag.TransactionNumberValidation = "Enter a whole number"; ViewBag.Count = checkingAccount.Transactions.Count(); ViewBag.TransactionTypes = new SelectList(Utilities.Utility.TranscationTypes); return(View(modelToPass)); } } query = query.Where(t => t.Description.Contains(Description)); if (!DateRange.Equals("Custom") && !DateRange.Equals("All")) { if (DateRange.Equals("Last 15 days")) { query = query.Where(t => t.TransactionDate >= DateTime.Now.AddDays(-1)); } else if (DateRange.Equals("Last 30 days")) { query = query.Where(t => t.TransactionDate >= DateTime.Now.AddDays(-30)); } else { query = query.Where(t => t.TransactionDate >= DateTime.Now.AddDays(-60)); } } if (DateRange.Equals("Custom")) { query = query.Where(t => t.TransactionDate >= model.DateFrom && t.TransactionDate <= model.DateTo); } if (!TransactionType.Equals("All")) { query = query.Where(t => t.TransactionType.Equals(TransactionType)); } if (!PriceRange.Equals("Custom")) { if (PriceRange.Equals("$0-$100")) { query = query.Where(t => t.Amount >= 0 && t.Amount <= 100); } else if (PriceRange.Equals("$100-$200")) { query = query.Where(t => t.Amount >= 100 && t.Amount <= 200); } else if (PriceRange.Equals("$200-$300")) { query = query.Where(t => t.Amount >= 200 && t.Amount <= 300); } else { query = query.Where(t => t.Amount >= 300); } } else { Decimal rangeFrom; Decimal rangeTo; try { rangeFrom = Convert.ToDecimal(RangeFrom); rangeTo = Convert.ToDecimal(RangeTo); query = query.Where(t => t.Amount >= rangeFrom && t.Amount <= rangeTo); } catch { ViewBag.Message = "Enter a valid range of numbers"; ViewBag.Count = checkingAccount.Transactions.Count(); ViewBag.TransactionTypes = new SelectList(Utilities.Utility.TranscationTypes); return(View(modelToPass)); } } if (TransactionNumberSort.Equals(SortBy.Ascending)) { if (TransactionTypeSort.Equals(SortBy.Ascending)) { if (DescriptionSort.Equals(SortBy.Ascending)) { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } else { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } } else { if (DescriptionSort.Equals(SortBy.Ascending)) { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } else { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderBy(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } } } else { if (TransactionTypeSort.Equals(SortBy.Ascending)) { if (DescriptionSort.Equals(SortBy.Ascending)) { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } else { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenBy(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } } else { if (DescriptionSort.Equals(SortBy.Ascending)) { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenBy(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } else { if (AmountSort.Equals(SortBy.Ascending)) { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenBy(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } else { if (DateSort.Equals(SortBy.Ascending)) { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenBy(t => t.TransactionDate); } else { query.OrderByDescending(t => t.TransactionID).ThenByDescending(t => t.TransactionType).ThenByDescending(t => t.Description).ThenByDescending(t => t.Amount).ThenByDescending(t => t.TransactionDate); } } } } } query.OrderByDescending(t => t.TransactionID); List <Transaction> list = query.ToList(); modelToPass = new CheckingAccountDetailsViewModel { CheckingAccountID = id, CheckingAccount = checkingAccount, Transactions = list }; ViewBag.Count = list.Count(); ViewBag.TransactionTypes = new SelectList(Utilities.Utility.TranscationTypes); return(View(modelToPass)); }