public IActionResult Checkout() { if (HttpContext.Session.GetString("CustomerId") != null) { string loginCustomerId = HttpContext.Session.GetString("CustomerId"); int conIntloginCustomerId = Convert.ToInt32(loginCustomerId); Invoice customerInvoice = new Invoice() { AccountId = conIntloginCustomerId, Date = DateTime.Now.Date, Name = "Order Invoice", Status = false }; bool isSaveCustomerInvoice = _iInvoiceManager.Add(customerInvoice); bool isSaveCustomerInvoiceDetails = false; Invoice lastCustomerInvoice = _iInvoiceManager.GetAll().LastOrDefault(); List <Product> addProducts = HttpContext.Session.Get <List <Product> >("AddProducts"); foreach (Product product in addProducts) { InvoiceDetails customerInvoiceDetails = new InvoiceDetails() { InvoiceId = lastCustomerInvoice.Id, Price = product.Price, ProductId = product.Id, Quantity = product.Quantity }; isSaveCustomerInvoiceDetails = _iInvoiceDetailsManager.Add(customerInvoiceDetails); } if (isSaveCustomerInvoice && isSaveCustomerInvoiceDetails) { HttpContext.Session.Remove("AddProducts"); return(RedirectToAction("Thanks")); } else { ViewBag.ErrorMessage = "Chack out is failed! Try Again"; return(View("Index")); } } return(RedirectToAction("CustomerLogin", "Login")); }
public IActionResult AddInvoice(Invoice invoice) { if (invoice.Items.Any()) { ModelState.AddModelError("", "Položky se přidávají až po přidání faktury. Nejprve přidejte prázdnou fakturu, a poté do ní přidejte položky."); } if (invoice.Paid) { ModelState.AddModelError("", "Nelze přidat zaplacenou fakturu. Nejprve ji přidejte, a pak ji nastavte jako zaplacenou."); } if (!ModelState.IsValid || ModelState.ErrorCount > 0) { return(View(invoice)); } _invoiceManager.Add(invoice); return(RedirectToAction("List", "Invoice")); }