예제 #1
0
 // Using bind to prevent overposting.
 public IActionResult CreateReceipt([Bind("name", "address", "city")] ReceiptViewModel receiptvm)
 {
     if (ModelState.IsValid)
     {
         Receipt finalreceipt = new Receipt();
         finalreceipt.city       = receiptvm.city; finalreceipt.address = receiptvm.address; finalreceipt.name = receiptvm.name;
         finalreceipt.products   = Utitlities.getProductsInHtml();
         finalreceipt.totalPrice = Utitlities.getTotalPrice();
         context.Receipts.Add(finalreceipt);
         context.SaveChanges();
         ListOfProducts.clear();
         return(View(finalreceipt));
     }
     return(RedirectToAction("errorCreatingReceipt", "Error"));
 }
예제 #2
0
        public IActionResult RegisterOrder(ProductViewModel productvm)
        {
            // Clear the list of products, incase the user redirects to Home.
            ListOfProducts.clear();
            // Check that atleast one product is ordered.
            bool oneProductOrdered = oneProductIsAtleastOrdered(productvm);

            if (ModelState.IsValid && oneProductOrdered)
            {
                ICollection <Product> myproducts = new List <Product>();
                Product bread = new Bread(productvm.AmountOfBread);
                Product juice = new Juice(productvm.AmountOfJuice);
                ListOfProducts.addProduct(bread); ListOfProducts.addProduct(juice);
                return(RedirectToAction("handleReceipt", "Receipt"));
            }
            return(RedirectToAction("orderError", "Error"));
        }