public ActionResult AddOrder() { int OrderId = 0; listOfShoppingCartModels = Session["CartItem"] as List <ShoppingCartModel>; Order orderObj = new Order() { OrderDate = DateTime.Now, OrderNumber = String.Format("{0:ddmmyyyyHHmmsss}", DateTime.Now) }; objCartDbEntities.Orders.Add(orderObj); objCartDbEntities.SaveChanges(); OrderId = orderObj.OrderId; foreach (var item in listOfShoppingCartModels) { OrderDetail objOrderDetail = new OrderDetail(); objOrderDetail.Total = item.Total; objOrderDetail.ItemId = item.ItemId; objOrderDetail.OrderId = OrderId; objOrderDetail.Quantity = item.Quantity; objOrderDetail.UnitPrice = item.UnitPrice; objCartDbEntities.OrderDetails.Add(objOrderDetail); objCartDbEntities.SaveChanges(); } Session["CartItem"] = null; Session["CartCounter"] = null; return(RedirectToAction("Index")); }
public JsonResult Index(ItemViewModel objItemViewModel) { string NewImage = Guid.NewGuid() + Path.GetExtension(objItemViewModel.ImagePath.FileName); objItemViewModel.ImagePath.SaveAs(Server.MapPath("~/Images/" + NewImage)); Item objItem = new Item(); objItem.ImagePath = "~/Image/" + NewImage; objItem.CategoryId = objItemViewModel.CategoryId; objItem.Description = objItemViewModel.Description; objItem.ItemCode = objItemViewModel.ItemCode; objItem.ItemId = Guid.NewGuid(); objItem.ItemName = objItemViewModel.ItemName; objItem.ItemPrice = objItemViewModel.ItemPrice; objECartDbEntities.Items.Add(objItem); objECartDbEntities.SaveChanges(); return(Json(new { Sucess = true, Message = "Item is added Successfully" }, "HHHH", JsonRequestBehavior.AllowGet)); }