public ActionResult Edit(ProductEdit model) { var chkimg = 0; var imgList = new List <int>(); var product = db.Products.Where(o => o.ID == model.ID).FirstOrDefault(); //db.Product_Images.RemoveRange(db.Product_Images.Where(o=>o.Product_Id == product.ID)); product.Description = model.description; product.MaxPrice = model.MaxPrice; product.MinPrice = model.MinPrice; product.Name = model.Name; var b = Request["chkimg"].ToString(); if (Request["chkimg"] != null) { chkimg = int.Parse(Request["chkimg"].ToString()); } var a = Request["hidimages"].ToString(); if (Request["hidimages"] != null) { imgList = Request["hidimages"].ToString().Split(',').Select(Int32.Parse).ToList(); } var tempimg = (from temp in db.temp_image where imgList.Contains(temp.ID) select temp).ToList(); foreach (var temp in tempimg) { if (temp.ID == chkimg) { db.Product_Images.Add(new Product_Images { Image_Byte = temp.image_Byte, Image_Path = temp.image_Path, IsPrimary = true, Product_Id = product.ID }); } else { db.Product_Images.Add(new Product_Images { Image_Byte = temp.image_Byte, Image_Path = temp.image_Path, IsPrimary = false, Product_Id = product.ID, }); } } db.SaveChanges(); return(RedirectToAction("Edit", new { id = model.ID })); }
protected override void Editar() { try { base.Editar(); if (productInfoListBindingSource.Current == null) { return; } var seleccionado = productInfoListBindingSource.Current as ProductInfo; entidad = ProductEdit.GetProductEdit(seleccionado.ID); productEditBindingSource.DataSource = entidad; productEditBindingSource.ResetBindings(false); codigoTextBox.Focus(); } catch (DataPortalException ex) { MessageBox.Show(ex.BusinessException.Message, "Editar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.Genders = db.Genders.ToList(); ViewBag.Sizes = db.Sizes.ToList(); ViewBag.Colors = db.Colors.Where(f => f.status == true).ToList(); ViewBag.Brands = db.Brands.Where(i => i.status == true).ToList(); ViewBag.Cats = db.SubCategories.ToList(); ProductEdit items = new ProductEdit() { Product = db.Products.FirstOrDefault(k => k.id == id), Images = db.Images.Where(i => i.productId == id).ToList(), ProductColors = db.ProductColors.Where(p => p.productId == id).ToList(), ProductSizes = db.ProductSizes.Where(s => s.productId == id).ToList() }; if (items == null) { return(HttpNotFound()); } return(View(items)); }
// GET: Admin/Products/Edit/{id} public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var product = await _productService.GetProductByIdAsync(id); if (product == null) { return(HttpNotFound()); } var model = new ProductEdit() { ProductId = product.ProductId, ProductName = product.ProductName, ProductDescription = product.ProductDescription, ProductPrice = product.ProductPrice, ProductImage = product.ProductImage, ProductQuantity = product.ProductQuantity, ProductCategory = product.ProductCategory }; return(View(model)); }
public async Task <IActionResult> Edit([FromRoute] int?id) { // If no id was in the route, return 404 if (id == null) { return(NotFound()); } var product = await context.Product .Include(s => s.User) .SingleOrDefaultAsync(m => m.ProductId == id); var productSubTypes = context.ProductSubType .OrderBy(l => l.Label) .AsEnumerable() .Where(t => t.ProductTypeId == product.ProductTypeId) .Select(li => new SelectListItem { Text = li.Label, Value = li.ProductSubTypeId.ToString() }); // If product not found, return 404 if (product == null) { return(NotFound()); } var model = new ProductEdit(context); model.CurrentProduct = product; model.ProductSubTypes = productSubTypes; return(View(model)); }
public ActionResult PutProduct(int id) { ProductEdit product = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44320/api/"); string token = DeserializeToken(); client.BaseAddress = new Uri("https://localhost:44320/api/"); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); var responseTask = client.GetAsync("product/" + id.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <ProductEdit>(); readTask.Wait(); product = readTask.Result; } else { ModelState.AddModelError(string.Empty, result.Content.ReadAsStringAsync().Result); } return(View(product)); } }
public ActionResult PutProduct(ProductEdit product) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44320/api/"); string token = DeserializeToken(); client.BaseAddress = new Uri("https://localhost:44320/api/"); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); var putTask = client.PutAsJsonAsync <ProductEdit>("product", product); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("GetProduct")); } else { ModelState.AddModelError(string.Empty, result.Content.ReadAsStringAsync().Result); } return(View(product)); } }
public ProductDeleteViewModel(ProductEdit product) : this() { Id = product.Id; Name = product.Name.Slovak; Type = product.Type; }
public IActionResult Edit(string id) { ViewBag.Categories = categoryRepository.Gets(); try { var product = productRepository.Get(int.Parse(id)); if (product != null && !product.IsDelete) { var productedit = new ProductEdit() { ProductId = product.ProductId, ProductName = product.ProductName, CategoryId = product.CategoryId, Description = product.Description, Price = product.Price, ImagePath = product.PathImage, Sale = product.Sale, Size = product.Size, Brand = product.Brand, Status = product.Status }; return(View(productedit)); } else { ViewBag.id = id; return(View("~/Views/Error/ProductNotFound.cshtml")); } } catch (Exception) { ViewBag.id = id; return(View("~/Views/Error/ProductNotFound.cshtml")); } }
protected override void Editar() { try { base.Editar(); if (productInfoListBindingSource.Current == null) return; var seleccionado = productInfoListBindingSource.Current as ProductInfo; entidad = ProductEdit.GetProductEdit(seleccionado.ID); productEditBindingSource.DataSource = entidad; productEditBindingSource.ResetBindings(false); codigoTextBox.Focus(); } catch (DataPortalException ex) { MessageBox.Show(ex.BusinessException.Message, "Editar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public IActionResult Edit(int?productId) { if (!productId.HasValue) { var myProductModelView = new ProductEdit(); myProductModelView.GroupList = new SelectList(productsService.GetGroups(), "GroupId", "Name"); return(View(myProductModelView)); } var myProductEntity = productsService.GetProductsByName("").Where(p => p.ProductId == productId).FirstOrDefault(); var groups = productsService.GetGroups(); var myProductModel = new ProductEdit(); myProductModel.GroupList = new SelectList(groups, "GroupId", "Name"); myProductModel.Description = myProductEntity.Description; myProductModel.Price = myProductEntity.Price; myProductModel.Name = myProductEntity.Name; myProductModel.ProductId = myProductEntity.ProductId; myProductModel.GroupId = myProductEntity.GroupId; return(View(myProductModel)); }
protected override void Nuevo() { base.Nuevo(); entidad = ProductEdit.NewProductEdit(); productEditBindingSource.DataSource = entidad; productEditBindingSource.ResetBindings(false); codigoTextBox.Focus(); }
public void Edit() { int productId = (int)productGridView.SelectedRows[0].Cells[0].Value; var productEdit = new ProductEdit(productId); productEdit._refreshDataGridView += new ProductEdit.DoEvent(LoadDataGrid); productEdit.ShowDialog(); }
public async Task UpdateProduct([FromBody] ProductEdit product) { await productService.UpdateProductAsync(product); if (product.Price != product.OldPrice) { await productService.CreateProductSnapshotAsync(product); } }
public async System.Threading.Tasks.Task <ActionResult> Create() { var loadSelectListItem = new LoadSelectListItem(); ProductEdit product = new ProductEdit(); product.SuppliersList = await loadSelectListItem.SupplierAsync(); return(View(product)); }
public ActionResult Edit([Bind(Include = "ProductID,Name,Brand,CategoryID,Quantity,Price")] ProductEdit productEdit) { if (ModelState.IsValid) { serviceProducts.UpdateProduct(productEdit.ToProduct()); return(RedirectToAction("Index")); } return(View(productEdit)); }
// GET: Products/Edit/5 public async System.Threading.Tasks.Task <ActionResult> Edit(int id) { var loadSelectListItem = new LoadSelectListItem(); ProductEdit product = await new HttpClientLib().GetByIdAsync <ProductEdit>("API", "/api/Products/GetProductsById/", id); product.SuppliersList = await loadSelectListItem.SupplierAsync(); return(View(product)); }
public JsonResult Edit(ProductEdit productEdit) { var editProduct = db.Products.FirstOrDefault(x => x.ID == productEdit.ProductId); editProduct.Name = productEdit.ProductName; editProduct.Price = Convert.ToInt32(productEdit.ProductPrice); db.SubmitChanges(); return(Json(true)); }
public IActionResult Edit([FromBody] ProductEdit productEdit) { Response <Product> response = new Response <Product>(); Product product = _productRepository.Update(productEdit.ToProduct()); response.Data = product; return(Ok(response)); }
public IActionResult Edit(ProductEdit model) { if (ModelState.IsValid) { if (productRepository.Update(model) > 0) { return(RedirectToAction("ProductbyCategory", "Product", new { categoryid = model.CategoryId })); } } return(View()); }
public bool EditProduct(ProductEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Products.FirstOrDefault(p => p.ProductId == model.ProductId); entity.StockQuantity = model.StockQuantity; entity.Price = model.Price; return(ctx.SaveChanges() == 1); } }
public async Task CreateProductSnapshotAsync(ProductEdit product) { using ( NpgsqlCommand command = new NpgsqlCommand( $"insert into {productsSnapshotsTableName} (manufacturer, datetime, name, price) values" + $"('{product.Manufacturer}', '{DateTime.Now}', '{product.Name}', {product.Price.ToString().Replace(",", ".")}); ", Connection )) { await command.ExecuteNonQueryAsync(); } }
public bool Update(ProductEdit model) { using (var ctx = new ApplicationDbContext()) { var product = GetProduct(ctx, model.ProductId); product.ProductName = model.ProductName; product.ProductDescription = model.ProductDescription; product.Upc = model.Upc; return(ctx.SaveChanges() == 1); } }
public bool UpdateProduct(ProductEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Products.Single(e => e.ProductId == model.ProductId); entity.Name = model.Name; entity.Description = model.Description; entity.TypeOfProduct = model.TypeOfProduct; entity.Price = model.Price; entity.IsMagical = model.IsMagical; return(ctx.SaveChanges() == 1); } }
public bool UpdateProduct(ProductEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Products.Single(e => e.ProductId == model.ProductId && e.OwnerId == _pUserId); entity.ProductName = model.ProductName; entity.ProductPrice = model.ProductPrice; entity.ProductDescription = model.ProductDescription; entity.ModifiedUtc = DateTimeOffset.UtcNow; entity.ProductReviewId = model.ProductReviewId; return(ctx.SaveChanges() == 1); } }
public ProductEditViewModel(ProductEdit product, IReadOnlyList <Application.Categories.Queries.Category> categories) : this() { Id = product.Id; NameSlovak = product.Name.Slovak; NameEnglish = product.Name.English; Type = product.Type; DescriptionSlovak = product.Description.Slovak; DescriptionEnglish = product.Description.English; Image = null !; SelectedCategoryId = product.CategoryId; Categories = categories; }
public async Task UpdateProductAsync(ProductEdit product) { using ( NpgsqlCommand command = new NpgsqlCommand( $"update {productsTableName} set " + $"name = '{product.Name}', category = '{product.Category}', price = '{product.Price.ToString().Replace(",", ".")}'" + $"where code = {product.Code}", Connection )) { await command.ExecuteNonQueryAsync(); } }
//GET: Product Edit public ActionResult Edit(int id) { var service = new ProductService(); var detail = service.GetProductById(id); var model = new ProductEdit { ProductId = detail.ProductId, Price = detail.Price, StockQuantity = detail.StockQuantity }; return(View(model)); }
//GET Invoice Edit public ActionResult Edit(int id) { var svc = CreateProductService(); var detail = svc.GetProductById(id); var model = new ProductEdit { ProductId = detail.ProductId, ProductName = detail.ProductName, ProductPrice = detail.ProductPrice, Quantity = detail.Quantity }; return(View(model)); }
// GET: Admin/Product/Edit public virtual ActionResult Edit(int?id) { if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductEdit Product = _ProductService.FindForEdit(id ?? 0); if (Product == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } return(View(Product)); }
public IHttpActionResult Put(ProductEdit products) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateProductService(); if (!service.UpdateProduct(products)) { return(InternalServerError()); } return(Ok()); }