Exemplo n.º 1
0
        public ActionResult AddOrder(double totalSum)
        {
            if (Session["Cart"] != null)
            {
                Dictionary <int, int> cart = (Dictionary <int, int>)Session["Cart"];
                Order order = new Order();
                order.OrderDate = DateTime.Now;
                order.Sum       = totalSum;
                order.IsPaid    = false;
                if (Session["Promo"] != null)
                {
                    order.VoucherId = (int)Session["Promo"];
                }
                order.UserId = User.Identity.GetUserId();
                foreach (KeyValuePair <int, int> item in cart)
                {
                    OrderEntry temp = new OrderEntry();
                    temp.Good = ModelService.GetGoodById(item.Key);
                    temp.Good.CalcPrice();
                    temp.GoodId   = item.Key;
                    temp.Order    = order;
                    temp.Quantity = item.Value;
                    temp.EndPrice = temp.Good.Price;
                    temp.Good     = null;
                    order.OrderEntries.Add(temp);
                }

                ViewBag.StateOrder = "error";
                if (ModelService.AddOrder(order))
                {
                    ViewBag.StateOrder = "success";
                }
                Session["Cart"]  = null;
                Session["Promo"] = null;
            }

            return(View());
        }