public async Task <int> UpdateProduct(NewProductVM product) { var model = _mapper.Map <Product>(product); model.Ammount = new Ammount() { Quantity = product.Ammount }; List <string> images = _imageRepository.AddPathToPhoto(product.Images); for (int i = 0; i < images.Count; i++) { var item = new Image() { Path = images[i] }; model.Paths.Add(item); } if (images.Count != 0) { await _imageRepository.RemoveItems(product.Id); } if (model.Ammount != null) { await _ammountRepository.DeleteAmmount(product.Id); } int id = await _productManager.UpdateProduct(model); return(id); }
public async Task <IActionResult> UpdateProduct(NewProductVM product) { if (ModelState.IsValid) { int id = await _productManagerService.UpdateProduct(product); return(RedirectToAction("ProductDetails", "Products", new { Id = id }));//narazie przekierowanie na index, bo na details powoduje nulla przy zdjeciach } return(View()); }
public async Task <IActionResult> AddProduct(NewProductVM product) { if (ModelState.IsValid) { int id = await _productManagerService.AddProduct(product); return(RedirectToAction("ProductDetails", "Products", new { Id = id }));//same id bez new powoduje blad w photo null } return(View()); }
public ActionResult Index() { var data = new NewProductVM() { Price = 100, ProductName = "T-Shirt" }; ViewData["MyName"] = "Will"; ViewData["MyTitle"] = "ASP.NET MVC 1"; ViewBag.MyTitle = "ASP.NET MVC 2"; ViewBag.Products = db.Product.Take(5).ToList(); TempData["Msg"] = "test"; ViewData.Model = data; return(View()); }
public ActionResult NewProduct(NewProductVM product) { if (ModelState.IsValid) { var prod = Mapper.Map <Product>(product); //var prod = new Product(); //prod.ProductName = product.ProductName; //prod.Price = product.Price; repo.Add(prod); try { repo.UnitOfWork.Commit(); } catch (DbEntityValidationException ex) { var allErrors = new List <string>(); foreach (DbEntityValidationResult re in ex.EntityValidationErrors) { foreach (DbValidationError err in re.ValidationErrors) { allErrors.Add(err.ErrorMessage); } } return(Content(String.Join("<br>", allErrors.ToArray()))); //throw ex; } return(RedirectToAction("Index")); } return(View(product)); }
public async Task <int> AddProduct(NewProductVM product)//do poprawy { var model = _mapper.Map <Product>(product); model.Ammount = new Ammount() { Quantity = product.Ammount }; List <string> images = _imageRepository.AddPathToPhoto(product.Images); for (int i = 0; i < images.Count; i++) { var item = new Image() { Path = images[i] }; model.Paths.Add(item); } int id = await _productManager.CreateProduct(model); return(id); }