public JsonResult AddCart(int?id) { var product = productProcess.Get(Convert.ToInt32(id)); var cartResult = new Cart(); var carItem = new CartItem(); var listCarItem = new List <CartItem>(); if (Session["Cart"] == null || String.IsNullOrEmpty(Session["Cart"].ToString())) { carItem.ProductId = product.Id; carItem.Price = product.Price; carItem.Quantity = 1; carItem.ChangedBy = "admin"; carItem.ChangedOn = DateTime.Now; carItem.CreatedOn = DateTime.Now; listCarItem.Add(carItem); cartResult = cartController.AddCart(listCarItem); } else { cartResult = cartController.GetCar(); } return(Json(cartResult, JsonRequestBehavior.AllowGet)); }
// [HttpPost] // public ActionResult Create(FormCollection form) // { // //var listModel = db.ValidateModel(artist); // //if (ModelIsValid(listModel)) // // return View(artist); // //try // //{ // // db.Create(artist); // // return RedirectToAction("Index"); // //} // //catch (Exception ex) // //{ // // Logger.Instance.LogException(ex); // // ViewBag.MessageDanger = ex.Message; // // return View(artist); // //} // var product = new Product(); // product.Title = form["title"]; // product.Description = form["description"]; // product.ArtistId = Convert.ToInt32(form["artistId"]); // product.QuantitySold = Convert.ToInt32(form["quantitySold"]); // product.AvgStars = double.Parse(form["avgStars"], System.Globalization.CultureInfo.InvariantCulture); // product.Price = Convert.ToInt32(form["price"]); // // uploaded image // if (Request.Files.Count > 0) // { // var file = Request.Files[0]; // if (file != null && file.ContentLength > 0) // { // var fileName = Path.GetFileName(file.FileName); // var path = Path.Combine(Server.MapPath("~/Content/Images/Products"), fileName); // file.SaveAs(path); // product.Image = file.FileName; // } // } // CheckAuditPattern(product, true); // ProductManagement.AddProduct(product); // return RedirectToAction("Index"); // } public ActionResult Modify(int id) { Product product = _pp.Get(id); var artistList = new List <SelectListItem>(); artistList.AddRange(_ap.GetAll() .Select(a => new SelectListItem { Value = a.Id.ToString(), Text = a.LastName }));; artistList.Where(x => x.Value == product.ArtistId.ToString()).First().Selected = true; ViewBag.ArtistList = artistList; return(View(product)); }