public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } VMProductInfo product = db.Get(id); var category = catdb.Get(product.CategoryID); ViewBag.CategoryName = category.Name; var Img = imgdb.Get(id); ViewBag.Img = Path.GetFileName(Img.ImgPath); ViewBag.Thum = Path.GetFileName(Img.ThumbnailPath); if (product == null) { return(HttpNotFound()); } return(View(product)); }
public ActionResult Edit(ProductEditViewModel model) { if (ModelState.IsValid) { var product = productRepository.Get(model.ID); var productMG = productMGRepository.Get(model.ID); if (product != null) { product.Name = model.Name; product.Brand = model.Brand; product.CategoryID = model.CategoryID; product.Details = model.Details; product.IsActive = model.IsActive; product.IsFavorite = model.IsFavorite; product.Price = model.Price; product.StockQuantity = model.StockQuantity; if (productMG != null) { string uniqueFileName = null; int i = 1; if (model.ImagePath[0] != null && model.ImagePath.Count > 0) { if (model.ExistenceImagePath != null) { string photoPath = Path.Combine(Server.MapPath("~/ProductPhoto"), model.ExistenceImagePath); System.IO.File.Delete(photoPath); } foreach (var photo in model.ImagePath) { uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName; string uploaddFile = Path.Combine(Server.MapPath("~/ProductPhoto"), uniqueFileName); photo.SaveAs(uploaddFile); productMG.ImgPath = uniqueFileName; productMGRepository.Update(productMG); i++; } } } productRepository.Update(product); return(RedirectToAction("Index")); } return(View(model)); } return(View(model)); }
public ActionResult Edit(long id) { var productMG = productMGRepository.Get(id); return(View(productMG)); }