Beispiel #1
0
        public ActionResult Index([Bind(Include = "SaleKey")] string sk)

        {
            var  resultMessage = new Message();
            Sale sl;

            if (Request["SaleKey"] == "")
            {
                sl          = new Sale();
                sl.SaleDate = DateTime.Now;
                db.Sales.Add(sl);
            }
            else
            {
                sl = db.Sales.Find(Int32.Parse(Request["SaleKey"]));
            }

            if (ModelState.IsValid)
            {
                var slDet = new SaleDetail();
                sl.CustomerKey                 = Int32.Parse(Request["CustomerKey"]);
                sl.EmployeeKey                 = Int32.Parse(Request["EmployeeKey"]);
                slDet.ProductKey               = Int32.Parse(Request["Products"]);
                slDet.SaleDetailPriceCharged   = db.Products.Find(Int32.Parse(Request["Products"])).ProductPrice;
                slDet.SaleDetailQuantity       = Request["Quantity"] == "" ? 0 : Int32.Parse(Request["Quantity"]);
                slDet.SaleDetailDiscount       = Request["Discount"] == "" ? 0 : Int32.Parse(Request["Discount"]);
                slDet.SaleDetailSaleTaxPercent = 10;
                slDet.SaleDetailEatInTax       = 20;
                sl.SaleDetails.Add(slDet);
                db.SaveChanges();

                if (Request["addmore"] == "Confirm and Add Another Product")
                {
                    return(View(sl));
                }
                else
                {
                    db.Entry(sl).Reference(r => r.Person).Load();
                    db.Entry(sl).Reference(r => r.Employee).Load();
                    db.Entry(sl.Employee).Reference(r => r.Person).Load();

                    return(View("Receipt", sl));
                }
            }

            else
            {
                resultMessage.MessageText = "We're so sorry, something seems to have gone wrong. Please try again.";
                return(View("Result", resultMessage));
            }
        }
 public ActionResult Edit([Bind(Include = "PersonKey,PersonLastName,PersonFirstName,PersonEmail,PersonPhone,PersonDateAdded")] Person person)
 {
     if (ModelState.IsValid)
     {
         db.Entry(person).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(person));
 }
 public ActionResult Edit([Bind(Include = "ProductKey,ProductName,ProductPrice")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Beispiel #4
0
 public ActionResult Edit([Bind(Include = "ProductKey,ProductName,ProductPrice,SaleKey,SaleDate,CustomerKey,EmployeeKey")] Sale sale)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductKey  = new SelectList(db.Sales, "ProductKey", "ProductName", sale.ProductKey);
     ViewBag.EmployeeKey = new SelectList(db.Employees, "EmployeeKey", "EmployeeTitle", sale.EmployeeKey);
     ViewBag.CustomerKey = new SelectList(db.People, "PersonKey", "PersonLastName", sale.CustomerKey);
     return(View(sale));
 }