Example #1
0
        public ActionResult Create(Customer customer)
        {
            Customer foundCustomer = facade.GetCustomerRepository().Find(customer.ID);

            if (foundCustomer == null)
            {
                facade.GetCustomerRepository().Add(customer);
            }
            else
            {
                facade.GetCustomerRepository().Edit(customer);
            }

            Order order = new Order();

            ShoppingCart cart = Session["ShoppingCart"] as ShoppingCart;
            if (cart == null)
            {
                cart = new ShoppingCart();
            }

            foreach (var item in cart.OrderLines)
            {
                order.OrderLines.Add(item);
            }

            order.Customer = customer;

            facade.GetOrderRepository().Add(order);
            Session["ShoppingCart"] = cart;
            return Redirect("Confirmation");
        }
Example #2
0
 public void Edit(Order order)
 {
     using (var ctx = new MovieShopContext())
     {
         var dbOrder = Find(order.ID, ctx);
         dbOrder.Date = order.Date;
         ctx.SaveChanges();
     }
 }
Example #3
0
 //Addding Order, making sure to attach customer, such no new customer would be made and use existing customer instead
 public void Add(Order order)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Customers.Attach(order.Customer);
         order.OrderLines.ForEach(x => ctx.Movies.Attach(x.Movie));
         ctx.Orders.Add(order);
         ctx.SaveChanges();
     }
 }
Example #4
0
 public ActionResult Edit(Order order)
 {
     facade.GetOrderRepository().Edit(order);
     return Redirect("Index");
 }
Example #5
0
 public ActionResult Create(Order order)
 {
     facade.GetOrderRepository().Add(order);
     return Redirect("Index");
 }