protected async Task AddRemoveSuppliers(ProductEditVM vm) { var product = await GetProductQuery() .Include(p => p.Suppliers) .FirstOrDefaultAsync(p => p.Id == vm.Id); if (vm.SuppliersSelected != null) { var toBeRemoved = new List <Supplier>(); foreach (var item in product.Suppliers) { if (!vm.SuppliersSelected.Contains(item.Id)) { toBeRemoved.Add(item); } } var suppliers = await GetSupplierQuery() .Where(s => vm.SuppliersSelected.Contains(s.Id)) .ToListAsync(); foreach (var item in suppliers) { if (!product.Suppliers.Contains(item)) { product.Suppliers.Add(item); } } foreach (var item in toBeRemoved) { product.Suppliers.Remove(item); } } await DataContext.SaveChangesAsync(this); }
public async Task <ActionResult> Edit(ProductEditVM vm) //POST: /Products/Edit/5 { Product product; if (ModelState.IsValid) { product = vm.ToProduct(); DataContext.Entry(product).State = EntityState.Modified; await DataContext.SaveChangesAsync(this); await AddRemoveSuppliers(vm); return(RedirectToAction("Index")); } product = await FindAsyncProduct(vm.Id); foreach (var item in product.Suppliers) { vm.Suppliers.Add(new SupplierDTO(item)); } await SetProductCategorySelectListAsync(vm); await SetCurrencySelectLists(vm); return(View(vm)); }
public ActionResult Edit(ProductEditVM u, long id) { try { ProductBiz productBiz = new ProductBiz(); u.ProductId = id; productBiz.UpdateProduct(u.ProductId, u.OldVersion, u.Versions, u.OldComponents, u.Components); ModelState.AddModelError("SM", "Product saved successfully"); return(View(u)); } catch (Exception Ex) { ModelState.AddModelError("SM", Ex.Message); return(View(u)); } }
public ActionResult ProductEdit(string id) { var product = svc.GetProduct(id); var model = new ProductEditVM() { Product = product }; Regex reg = new Regex(@"^_"); List <BaseFile> proImgs = null; if (!string.IsNullOrEmpty(product.Id) && !reg.IsMatch(product.Id)) { var bfService = new BaseFileService(); proImgs = bfService.GetBaseFiles(product.Id); } ViewBag.ProductImgs = proImgs; return(View(model)); }
public ActionResult Edit(ProductEditVM product2BUpdated) { if (ModelState.IsValid) { try { _productBL.UpdateProduct(_mapper.cast2Product(product2BUpdated)); Log.Information($"Product updated-- Name: {product2BUpdated.ProdName}"); return(RedirectToAction(nameof(Index))); } catch (Exception e) { Helper.WriteError(e, "Error"); Helper.WriteFatal(e, "Fatal"); Helper.WriteVerbose(e, "Verbose"); return(View()); } } return(View()); }
public async Task <ActionResult> Edit(int?id) //GET: /Products/Edit/5 { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product product = await FindAsyncProduct(id.Value); if (product == null) { return(HttpNotFound()); } await SetProductCategorySelectListAsync(product); var vm = new ProductEditVM(product); await SetCurrencySelectLists(vm); return(View(vm)); }
// GET: Products/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var product = await _context.Product.FindAsync(id); if (product == null) { return(NotFound()); } var viewModel = new ProductEditVM() { Product = product, Categories = await _context.ProductType.ToListAsync() }; return(View(viewModel)); }
public ActionResult Edit(int id) { try { ProductEditVM m = new ProductEditVM(); ProductBiz productBiz = new ProductBiz(); Product p = productBiz.GetProductInfo(id); m.ProductName = p.Name; // should get from databse; m.Versions = p.Versions; // get from databse; m.OldVersion = p.Versions; m.OldComponents = p.Components; m.Components = p.Components; return(View(m)); } catch (Exception ex) { throw ex; } }
public ProductEditWindow(object selectedProduct) { InitializeComponent(); DataContext = new ProductEditVM(selectedProduct); }