public ActionResult Index([Bind(Include = "Page, Sort")] PageSortCriteria pageSortCriteria, [Bind(Include = "Title, Description, Version")] InvoiceSearchCriteria searchCriteria = null) { InvoiceListVM vm = new InvoiceListVM { Invoices = UOW.Invoices.GetAllPaged(pageSortCriteria, searchCriteria), PageSortCriteria = pageSortCriteria, SearchCriteria = searchCriteria }; return(View(vm)); }
private InvoiceListVM GetListing(int?id) { if (id.HasValue && id == 0) { id = null; } InvoiceListVM indexVM; if (id.HasValue) { indexVM = new InvoiceListVM { invoiceListViewModel = _invoiceService.GetAllForHouse(id.Value) .Select(a => new InvoiceListViewModel { FullName = a.House.Owner.FullName, Invoicev = new Invoice { Amount = a.Amount, DatePaid = a.DatePaid, Description = a.Description, InvoiceDate = a.InvoiceDate, IsPaid = a.IsPaid, InvoiceId = a.InvoiceId, HouseId = a.HouseId }, HouseAddress = $"{a.House.StreetNumber} {a.House.StreetName } ", HouseId = a.HouseId }).ToList() }; var house = _houseService.GetById(id.Value); indexVM.InvoicesTotal = indexVM.invoiceListViewModel.Where(a => a.Invoicev.IsPaid == false).Sum(a => a.Invoicev.Amount); indexVM.ListingHeader = $"{house.StreetNumber} {house.StreetName} - {house.FullName}"; indexVM.HouseId = id.Value; } else { indexVM = new InvoiceListVM { invoiceListViewModel = _invoiceService.GetAll() .Select(a => new InvoiceListViewModel { FullName = a.House.Owner.FullName, Invoicev = new Invoice { Amount = a.Amount, DatePaid = a.DatePaid, Description = a.Description, InvoiceDate = a.InvoiceDate, IsPaid = a.IsPaid, InvoiceId = a.InvoiceId, HouseId = a.HouseId }, HouseAddress = $"{a.House.StreetNumber} {a.House.StreetName } ", HouseId = a.HouseId, }).ToList() }; indexVM.ListAll = true; indexVM.InvoicesTotal = indexVM.invoiceListViewModel.Where(a => a.Invoicev.IsPaid == false).Sum(a => a.Invoicev.Amount); indexVM.ListingHeader = "Invoices for all properties"; } return(indexVM); }