//Item public async Task <IActionResult> Index() { ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User); if (user != null) { _id = await getSupplierIdByEmail(user.Email); List <ServiceReference_Invoice.Invoice> invoices = null; List <ServiceReference_Invoice.Invoice> last_invoices = null; List <ServiceReference_PurchaseOrder.PurchaseOrder> lst_inquiries = null; float saletotal = 0; float profitmonth = 0; float total = 0; int faq = 0; try { invoices = (await iv.getAllInvoiceBySupplierIdAsync(_id)).OrderByDescending(x => x.InvoiceDate).ToList(); last_invoices = invoices.Where(d => d.InvoiceDate.ToString("dd-MM-yyyy") == DateTime.Now.ToString("dd-MM-yyyy")).OrderByDescending(x => x.InvoiceDate).ToList(); saletotal = invoices.Where(d => d.InvoiceDate.ToString("dd-MM-yyyy") == DateTime.Now.ToString("dd-MM-yyyy")).Count(); profitmonth = (float)invoices.Where(d => d.InvoiceDate.Month == DateTime.Now.Month && d.InvoiceDate.Year == DateTime.Now.Year && d.Status == "paid").Sum(t => t.Total); total = (float)invoices.Where(d => d.InvoiceDate.ToString("dd-MM-yyyy") == DateTime.Now.ToString("dd-MM-yyyy") && d.Status == "paid").Sum(t => t.Total); //faq = (await item.getAllItemAsync()).Where(f => f.FAQ != null && f.SupplierId == _id).Count(); } catch (Exception) { invoices = null; last_invoices = null; saletotal = 0; profitmonth = 0; total = 0; faq = 0; lst_inquiries = null; } lst_inquiries = (await po.getAllPurchaseOrderAsync()) .OrderByDescending(p => p.InquiriedData) .Where(p => p.SupplierId == _id) .ToList(); InvoiceModel model = new InvoiceModel() { Saletotal = saletotal, Total = total, ProfitMonth = profitmonth, Inquiries = lst_inquiries, Invoices = invoices, LastInvoices = last_invoices, FAQ = faq }; return(View(model)); } else { return(RedirectToAction("Login", "Account")); } }