public List <ProductInCart> GetProductInBasketByCoockie() { List <ProductInCart> productInCarts = new List <ProductInCart>(); string[] basketItems = GetCookie(); for (int i = 0; i < basketItems.Length - 1; i++) { string[] productItem = basketItems[i].Split('^'); string productCode = productItem[0]; Guid productColorId = new Guid(productItem[2]); Product product = db.Products.FirstOrDefault(current => current.IsDeleted == false && current.Code == productCode); Product_Color product_Color = db.ProductColors.Where(current => current.Id == productColorId).FirstOrDefault(); productInCarts.Add(new ProductInCart() { Product = product, Quantity = Convert.ToInt32(productItem[1]), Color = db.Colors.Where(current => current.Id == product_Color.ColorId).FirstOrDefault().Title }); } return(productInCarts); }
public ActionResult DetailProduct(string m_ProductID) { List <Product_Size> lstProductSize = db.Product_Size.Where(p => p.ProductID.ToString() == m_ProductID).ToList(); //Check product quanlity if (lstProductSize.Count() == 0) { return(RedirectToAction("Error", "Error")); } //get list category and product category ViewBag.ProductCategories = db.ProductCategories.ToList(); ViewBag.Categories = db.Categories.Take(5).ToList(); Product prd = db.Products.SingleOrDefault(p => p.ProductID.ToString() == m_ProductID); //get list image and size, color List <ProductImage> lstProductImage = db.ProductImages.Where(p => p.ProductID.ToString() == m_ProductID).ToList(); Product_Color ProductColor = db.Product_Color.FirstOrDefault(p => p.ProductID.ToString() == m_ProductID); ViewBag.lstProductSize = lstProductSize; ViewBag.lstProductImage = lstProductImage; ViewBag.ProductColor = ProductColor; if (prd == null) { return(RedirectToAction("Error", "Error")); } // return PartialView("../Product/View_ccdatvoday?m_ProductID=" + m_ProductID + "&sizes=" + iSize + ""); return(View(prd)); }
public ActionResult DeleteConfirmed(Guid id) { Product_Color product_Color = db.ProductColors.Find(id); product_Color.IsDeleted = true; product_Color.DeletionDate = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index", new { id = product_Color.ProductId })); }
public ActionResult Edit(Product_Color product_Color) { if (ModelState.IsValid) { product_Color.IsDeleted = false; db.Entry(product_Color).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { id = product_Color.ProductId })); } ViewBag.ColorId = new SelectList(db.Colors, "Id", "Title", product_Color.ColorId); ViewBag.ProductId = product_Color.ProductId; return(View(product_Color)); }
// GET: Product_Color/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product_Color product_Color = db.ProductColors.Find(id); if (product_Color == null) { return(HttpNotFound()); } return(View(product_Color)); }
// GET: Product_Color/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product_Color product_Color = db.ProductColors.Find(id); if (product_Color == null) { return(HttpNotFound()); } ViewBag.ColorId = new SelectList(db.Colors, "Id", "Title", product_Color.ColorId); ViewBag.ProductId = product_Color.ProductId; return(View(product_Color)); }
public ActionResult Create(Product_Color product_Color, Guid id) { if (ModelState.IsValid) { product_Color.IsDeleted = false; product_Color.CreationDate = DateTime.Now; product_Color.Id = Guid.NewGuid(); product_Color.ProductId = id; db.ProductColors.Add(product_Color); db.SaveChanges(); return(RedirectToAction("Index", new { id = product_Color.ProductId })); } ViewBag.ColorId = new SelectList(db.Colors, "Id", "Title", product_Color.ColorId); ViewBag.ProductId = id; return(View(product_Color)); }
public ActionResult CreateProduct(FormCollection f, HttpPostedFileBase file, IEnumerable <HttpPostedFileBase> files) { if (ModelState.IsValid) { ProductDao productDAO = new ProductDao(); Product product = new Product(); product.Name = f["Name"].ToUpper().ToString(); product.Price = decimal.Parse(f["Price"]); product.PromotionPrice = product.Price; product.Detail = f["Detail"].ToString(); product.Quantity = f["Quantity"] == "" ? 0 : int.Parse(f["Quantity"]); product.CategoryID = long.Parse(f["Category"]); product.ProductCategoryID = long.Parse(f["ProductCategory"]); product.Warranty = int.Parse(f["Warranty"]); product.CreatedDate = DateTime.Now; product.CreatedBy = Session["UserNameAdmin"].ToString(); product.New = f["New"] == "1" ? true : false; string filename = ""; if (file != null && file.ContentLength > 0) { filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/ProductImage"), filename); file.SaveAs(path); } product.Image = "ProductImage" + "/" + filename; db.Products.Add(product); //get max product_id long maxid = productDAO.getMaxIdProduct() + 1; //add data table product_color Product_Color productcolor = new Product_Color(); productcolor.ProductID = maxid; productcolor.ColorID = int.Parse(f["Color"]); db.Product_Color.Add(productcolor); //add data table product_size Product_Size productsize = new Product_Size(); productsize.ProductID = maxid; productsize.SizeID = int.Parse(f["Size"]); db.Product_Size.Add(productsize); //add data table product_image foreach (var file1 in files) { ProductImage productimage = new ProductImage(); if (file1 != null && file1.ContentLength > 0) { filename = Path.GetFileName(file1.FileName); var path = Path.Combine(Server.MapPath("~/ProductImage"), filename); file1.SaveAs(path); productimage.ProductID = maxid; productimage.ImageDetail = "ProductImage" + "/" + filename; } db.ProductImages.Add(productimage); } db.SaveChanges(); return(RedirectToAction("Index")); } return(null); }