Example #1
0
        public ActionResult Index
            ([Bind(Include =
                       "LastName, " +
                       "FirstName, " +
                       "Email, " +
                       "Phone, ")
            ] Person p)

        {
            db.People.Add(p);
            db.SaveChanges();

            return(View());
        }
        public ActionResult Index([Bind(Include = "ProductName, ProductPrice")] Product np)
        {
            Product newproduct = new Product();

            newproduct.ProductName  = np.ProductName;
            newproduct.ProductPrice = np.ProductPrice;

            db.Products.Add(newproduct);
            db.SaveChanges();

            Message m = new Message();

            m.MessageText = "Thank you for adding  to our line of Products";
            return(View("Result", m));
        }
        public ActionResult Index([Bind(Include = "ProductName, ProductPrice")] Product np)
        {
            Product newproduct = new Product();

            newproduct.ProductName  = np.ProductName;
            newproduct.ProductPrice = np.ProductPrice;

            db.Products.Add(newproduct);
            db.SaveChanges();

            Message m = new Message();

            m.MessageTitle = "Product Added Successfully";
            m.MessageText  = "Thank you for adding " + np.ProductName + " to our ever-increasing list of delicious menu options!";
            return(View("Result", m));
        }
Example #4
0
        public ActionResult Index([Bind(Include = "PersonLastName, PersonFirstName, PersonEmail, PersonPhone, PersonDateAdded")] Person dudemanbro)
        {
            Person p = new Person();

            p.PersonLastName  = dudemanbro.PersonLastName;
            p.PersonFirstName = dudemanbro.PersonFirstName;
            p.PersonEmail     = dudemanbro.PersonEmail;
            p.PersonPhone     = dudemanbro.PersonPhone;
            p.PersonDateAdded = DateTime.Now;

            db.People.Add(p);
            db.SaveChanges();

            Message m = new Message();

            m.MessageText  = "Thanks for Registering.";
            m.MessageTitle = "Registration Successful.";
            return(View("Result", m));
        }
Example #5
0
        public ActionResult Index([Bind(Include =
                                            "PersonLastName, " +
                                            "PersonFirstName, " +
                                            "PersonEmail," +
                                            "PersonPhone," +
                                            "PersonDateAdded")] Person per)
        {
            Person p = new Person();

            p.PersonLastName  = per.PersonLastName;
            p.PersonFirstName = per.PersonFirstName;
            p.PersonEmail     = per.PersonEmail;
            p.PersonPhone     = per.PersonPhone;
            p.PersonDateAdded = DateTime.Now;

            db.People.Add(p);
            db.SaveChanges();

            Message m = new Message();

            m.MessageText = "Thank you for registaring at Pete's Bakery";
            return(View("Result", m));
        }
        public ActionResult Index([Bind(Include = "ProductKey, ProductName, ProductPrice, ProductQuantity, DiscountType, CustomerEatIn, CustomerKey, EmployeeKey")] ProductSale ps)
        {
            //get id from user selection on product page
            int id = (int)Session["PurchaseSelection"];

            //set some product information based on the product id
            Product p = db.Products.Find(id);

            ps.ProductKey   = p.ProductKey;
            ps.ProductName  = p.ProductName;
            ps.ProductPrice = p.ProductPrice;


            //set discount amount based on user selection
            double discountAmount;

            if (ps.DiscountType == 2)
            {
                discountAmount = 0.9;
            }
            else if (ps.DiscountType == 3)
            {
                discountAmount = 0.85;
            }
            else if (ps.DiscountType == 4)
            {
                discountAmount = 0.8;
            }
            else
            {
                discountAmount = 1;
            }

            double EatInTax = 0;

            if (ps.CustomerEatIn)
            {
                EatInTax = 0.25;
            }

            //print to console to make sure values are being saved properly
            System.Diagnostics.Debug.WriteLine("ProductKey: " + ps.ProductKey);
            System.Diagnostics.Debug.WriteLine("ProductName: " + ps.ProductName);
            System.Diagnostics.Debug.WriteLine("ProductPrice: " + ps.ProductPrice);
            System.Diagnostics.Debug.WriteLine("ProductQuantity: " + ps.ProductQuantity);
            System.Diagnostics.Debug.WriteLine("DiscountAmount: " + discountAmount);
            System.Diagnostics.Debug.WriteLine("EatInTax: " + EatInTax);
            System.Diagnostics.Debug.WriteLine("CustomerKey: " + ps.CustomerKey);
            System.Diagnostics.Debug.WriteLine("EmployeeKey: " + ps.EmployeeKey);

            //calculate subtotal and total after taxes
            double purchaseSubtotal = (((double)ps.ProductPrice * ps.ProductQuantity) * discountAmount) + EatInTax;
            double salesTax         = 1.0996;
            double purchaseTotal    = Math.Round((purchaseSubtotal * salesTax), 2);

            //stage a new record for the Sale table in the Bakery db
            Sale s = new Sale();

            s.SaleDate    = DateTime.Now;
            s.CustomerKey = ps.CustomerKey;
            s.EmployeeKey = ps.EmployeeKey;
            db.Sales.Add(s);

            //stage a new record for the SaleDetail table in the Bakery db
            SaleDetail anotherSale = new SaleDetail();

            anotherSale.ProductKey               = ps.ProductKey;
            anotherSale.SaleDetailPriceCharged   = (decimal)purchaseTotal;
            anotherSale.SaleDetailQuantity       = ps.ProductQuantity;
            anotherSale.SaleDetailDiscount       = (decimal)discountAmount;
            anotherSale.SaleDetailSaleTaxPercent = ((decimal)salesTax - 1);
            anotherSale.SaleDetailEatInTax       = (decimal)EatInTax;
            anotherSale.SaleKey = s.SaleKey;
            db.SaleDetails.Add(anotherSale);

            //save Sale and SaleDetail records to the Bakery db
            db.SaveChanges();

            //gather info to pass to receipt view
            ReceiptModel rm = new ReceiptModel();

            rm.MessageTitle     = "Receipt";
            rm.MessageText      = "Transaction complete. Thank you for your purchase!";
            rm.ProductKey       = ps.ProductKey;
            rm.ProductName      = ps.ProductName;
            rm.ProductQuantity  = ps.ProductQuantity;
            rm.TransactionTotal = purchaseTotal.ToString("C"); //this converts a number to a string formatted for currency

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