Exemplo n.º 1
0
        protected void btnCheckout_Click(object sender, EventArgs e)
        {
            using (DataAccessContainer ctx = new DataAccessContainer())
            {
                DateTime now = DateTime.Now;

                Int.User usr = ctx.Users.FirstOrDefault(u => u.Id == loggedInUser.Id);
                Invoice nInv = new Invoice() { Date = now, IsPaid = false };
                Order nOrder = new Order() { Date = now, Invoice = nInv, Discount = 0 };
                decimal totalAmount = 0;
                GetCartItems().ForEach(ci =>
                {
                    OrderProduct nOrderProd = new OrderProduct() { Quantity = ci.Quantity, Product = ctx.Products.FirstOrDefault(p=>p.Id == ci.ProductId) };
                    nOrder.OrderProducts.Add(nOrderProd);
                    totalAmount += ci.Price * ci.Quantity;
                });

                //calulate discount
                if (totalAmount >= 50)
                {
                    nOrder.Discount += 10;
                }
                if(totalAmount >= 75)
                {
                    nOrder.Discount += 10;
                }
                if (totalAmount >= 100)
                {
                    nOrder.Discount += 10;
                }

                //save order and redirect
                usr.Orders.Add(nOrder);
                ctx.SaveChanges();
                ClearCart();
                Response.Redirect("ViewInvoiceAfterOrder.aspx?id=" + nOrder.Id);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Order object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="discount">Initial value of the Discount property.</param>
 public static Order CreateOrder(global::System.Int32 id, global::System.DateTime date, global::System.Decimal discount)
 {
     Order order = new Order();
     order.Id = id;
     order.Date = date;
     order.Discount = discount;
     return order;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrders(Order order)
 {
     base.AddObject("Orders", order);
 }