예제 #1
0
        public ActionResult AddOrder()
        {
            int OrderId = 0;

            cartModels = Session["cartItem"] as List <cartModel>;
            Order order = new Order()
            {
                OrderDate   = DateTime.Now,
                OrderNumber = string.Format("{0:ddmmyyyyHHmmsss}", DateTime.Now)
            };

            eCartDbEntities.Orders.Add(order);
            eCartDbEntities.SaveChanges();
            OrderId = order.OrderId;
            foreach (var item in cartModels)
            {
                OrderDetail orderDetail = new OrderDetail();
                orderDetail.Total     = item.Total;
                orderDetail.ItemId    = item.ItemId;
                orderDetail.OrderId   = OrderId;
                orderDetail.Quantity  = item.Quantity;
                orderDetail.UnitPrice = item.UnitPrice;
                eCartDbEntities.OrderDetails.Add(orderDetail);
                eCartDbEntities.SaveChanges();
            }
            Session["cartItem"]    = null;
            Session["cartCounter"] = null;
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public JsonResult Index(ItemViewModel itemViewModel)
        {
            //to recover image file extension to check against double image (image name + EXTENSION )
            string Image = Guid.NewGuid() + Path.GetExtension(itemViewModel.ImagePath.FileName);

            // saving new image to the intended directory
            itemViewModel.ImagePath.SaveAs(Server.MapPath("~/Images/" + Image));
            // Create an instance to attach properties
            Item item = new Item();

            item.ImagePath   = "~/Images/" + Image;
            item.CategoryId  = itemViewModel.CategoryId;
            item.Description = itemViewModel.Description;
            item.ItemCode    = itemViewModel.ItemCode;
            item.ItemId      = Guid.NewGuid();
            item.ItemName    = itemViewModel.ItemName;
            item.ItemPrice   = itemViewModel.ItemPrice;
            eCartDbEntities.Items.Add(item);
            eCartDbEntities.SaveChanges();
            //troubleshooting point to see teh values from the index formdata make use of the locals and watch tab to view
            return(Json(data: new { Success = true, Message = "Items added " }, JsonRequestBehavior.AllowGet));
        }