Example #1
0
        public ViewResult Index(Customer customer)
        {
            if (ModelState.IsValid)
            {
                //DEPENDENCY INJECTION!!
                //ICustomerRepository customerrepo = new XMLCustomerRepository();
                //IOrderRepository orderrepo = new XMLOrderRepository();
                ICustomerRepository customerrepo = (ICustomerRepository)DIResolver.GetClass <ICustomerRepository>();
                IOrderRepository    orderrepo    = (IOrderRepository)DIResolver.GetClass <IOrderRepository>();


                //Save Client
                int customerid = customerrepo.SaveClient(customer);

                //Save Order
                ShoppingCart sscart  = new ShoppingCart(Session["cart"]);
                int          orderid = orderrepo.SaveOrder(customerid, sscart);


                ViewBag.OrderNo = orderid;
                ViewBag.Name    = customer.Title + " " + customer.FirstName + " " + customer.LastName;

                return(View("ThankYou"));
            }
            else
            {
                return(View());
            }
        }
Example #2
0
        public ShoppingCart Add(int prodid)
        {
            int      qty          = 1;
            ItemCart existingItem = Cart.Find(p => p.ProductId == prodid);

            if (existingItem != null)
            {
                qty = existingItem.Quantity + 1;
                Cart.Remove(existingItem);
            }

            //DEPENDENCY INJECTION!!

            //IProductRepository prodrepo = new XMLProductRepository();
            IProductRepository prodrepo = (IProductRepository)DIResolver.GetClass <IProductRepository>();


            Product selectedprod = prodrepo.GetProduct(prodid);
            string  prodname     = selectedprod.Name;
            decimal prodprice    = selectedprod.Price;

            Cart.Add(new ItemCart()
            {
                ProductId = prodid,
                Product   = prodname,
                Quantity  = qty,
                UnitPrice = prodprice,
                Price     = decimal.Round(qty * prodprice, 2)
            });

            return(this);
        }
Example #3
0
        public decimal VAT()
        {
            //DEPENDENCY INJECTION!!
            //IParameterRepository paramrepo = new XMLParameterRepository();
            IParameterRepository paramrepo = (IParameterRepository)DIResolver.GetClass <IParameterRepository>();

            return(decimal.Parse(paramrepo.getParameter("VAT")));
        }