public void UpdateImage(UpdateProductImage command) { Image = command.ImageName; LastUpdated = DateTime.UtcNow; Validate(); }
public ActionResult ImagesUpdate(int id) { List <ImagesProduct> images = db.ImagesProduct.Where(I => I.ProductObject.ProductId == id).ToList(); UpdateProductImage updProIma = new UpdateProductImage(); updProIma.ImagesProductList = images; ViewData["ProductID"] = id; return(View(updProIma)); }
public ActionResult UpdateFiles(UpdateProductImage up, int ProductId) { ImagesProduct ImageProductObject; //Ensure model state is valid if (ModelState.IsValid) { //iterating through multiple file collection foreach (HttpPostedFileBase file in up.FileModelObj.files) { //Checking file is available to save. if (file != null) { var InputFileName = Path.GetFileName(file.FileName); var ServerSavePath = Path.Combine(Server.MapPath("~/Content/images/PoductImages/") + InputFileName); string filePath = "/Content/images/PoductImages/" + InputFileName; //Save file to server folder file.SaveAs(ServerSavePath); //assigning file uploaded status to ViewBag for showing message to user. ViewBag.UploadStatus = up.FileModelObj.files.Count().ToString() + " files uploaded successfully."; ImageProductObject = new ImagesProduct { ImagesUrl = filePath, }; // db.ImagesProduct.Add(ImageProductObject); // db.SaveChanges(); Product myProduct = db.Product.FirstOrDefault(p => p.ProductId == ProductId); myProduct.IamgesList.Add(ImageProductObject); db.SaveChanges(); } } } //return View(); return(RedirectToAction("Index")); }
public async Task <IActionResult> UpdateImage([FromForm] UpdateProductImage updateProductImage) { var result = await _whenUpdateProductImage.Handle(updateProductImage); return(Ok(result)); }