public async Task <IActionResult> Edit(int id, [Bind("product_id,seller_id,product_name,product_quantity,product_price,product_description,product_image")] item_detail item_detail) { if (id != item_detail.product_id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(item_detail); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!item_detailExists(item_detail.product_id)) { return(NotFound()); } else { throw; } } return(RedirectToActionPermanentPreserveMethod(actionName: "Homepage", controllerName: "sellers")); } return(View(item_detail)); }
public async Task <IActionResult> Create([Bind("product_id,product_name,product_quantity,product_price,product_description,product_image")] view_model.item_view_model item_detail) { //System.Diagnostics.Debug.WriteLine("seller.seller_image.FileName" + seller.seller_image.FileName); if (ModelState.IsValid) { //int seller_id = (int)HttpContext.Session.GetInt32("seller_id"); int seller_id = Int32.Parse(Request.Cookies["seller_id"].ToString()); System.Diagnostics.Debug.WriteLine("seller.seller_image.FileName" + seller_id); String uniqefileName = null; if (item_detail.product_image != null) { string uplodeFolder = Path.Combine(hostEnvironment.WebRootPath, "product_image"); uniqefileName = Guid.NewGuid().ToString() + "_" + item_detail.product_image.FileName; string filepath = Path.Combine(uplodeFolder, uniqefileName); item_detail.product_image.CopyTo(new FileStream(filepath, FileMode.Create)); } item_detail item = new item_detail { product_description = item_detail.product_description, product_name = item_detail.product_name, product_price = item_detail.product_price, product_image = uniqefileName, product_quantity = item_detail.product_quantity, seller_id = seller_id, }; _context.item_Details.Add(item); await _context.SaveChangesAsync(); return(RedirectToActionPermanentPreserveMethod(actionName: "Homepage", controllerName: "sellers")); } return(View(item_detail)); }