public async Task <EditProduct> UpdateAsync(EditProduct editProduct) { if (ProductExists(editProduct.Id)) { var product = await _context.Products .Where(x => x.Deleted == false) .FirstOrDefaultAsync(x => x.Id == editProduct.Id); product.ProductName = editProduct.ProductName; product.Price = editProduct.Price; product.Quantity = editProduct.Quantity; product.Discount = editProduct.Discount; product.DateModified = DateTime.UtcNow; //updating product _context.Entry(product).State = EntityState.Modified; await _context.SaveChangesAsync(); return(editProduct); } else { return(null); } }
public IActionResult Edit(int id) { ViewBag.Categories = categoryRepository.Gets(); try { var product = productRepository.Get(id); if (product != null) { var productedit = new EditProduct() { ProductId = product.ProductId, ProductName = product.ProductName, catelogyid = product.CategoryId, Description = product.Description, Price = product.Price, ImagePath = product.PathImage, size = product.Size, BrandName = product.Brand, }; return(View(productedit)); } else { ViewBag.id = id; return(View("~/Views/Error/ProductNotFound.cshtml")); } } catch (Exception) { ViewBag.id = id; return(View("~/Views/Error/ProductNotFound.cshtml")); } }
private static void SaveImages(EditProduct editProduct, int productID) { var curList = ProductImages.GetByProductID(productID); foreach (var image in editProduct.Images) { if (!curList.Any(item => item.ID == image.ID)) { var productImage = Mapper.Map <ProductImage>(image); productImage.ProductID = productID; ProductImages.Insert(productImage); } else { ProductImages.UpdateProductImagePlace(image.ID, image.ProductImagePlace); curList.Remove(curList.Single(cls => cls.ID == image.ID)); } } foreach (var item in curList) { ProductImages.Delete(item.ID); } }
public OperationResult Edit(EditProduct command) { var operation = new OperationResult(); var product = _productRepository.Get(command.Id); if (product == null) { return(operation.Failed(ApplicationMessages.RecordNotFound)); } if (_productRepository.Exist(x => x.Name == command.Name && x.Id != command.Id)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var slug = command.Slug.Slugify(); product.Edit(command.Name, command.Code, command.UnitPrice, command.ShortDescription, command.Description, command.Picture, command.PictureAlt, command.PictureTitle, command.CategoryId, slug, command.Keywords, command.MetaDescription); _productRepository.SaveChange(); return(operation.Succedded()); }
// GET: Products/Edit/5 public IActionResult Edit(string id) { if (id == null) { return(NotFound()); } EditProduct ps = new EditProduct(); ps.parent = _context.Product.Find(id); var childs = _context.Product.Where(p => p.ParentId == id).OrderBy(p => p.ParentId).ToList(); ps.childs = childs; List <ProductImage> lstImg = _context.ProductImage.Where(p => p.product_id == id).OrderBy(p => p.position).ToList(); ps.lstImage = lstImg; List <string> lstStr = new List <string>(); foreach (ProductImage pi in lstImg) { lstStr.Add(pi.src); } //List<string> lstimg = getFTPImages(ps.parent.SKU); ps.imgtoShow = lstStr; if (childs == null) { return(NotFound()); } return(View(ps)); }
public OperationResult Edit(EditProduct command) { var operationResult = new OperationResult(); var product = _productRepository.GetProductWithCategory(command.Id); if (product == null) { return(operationResult.Failed(QueryValidationMessage.NotFound)); } if (_productRepository.Exists(p => p.Name == command.Name && p.Id != command.Id)) { return(operationResult.Failed(QueryValidationMessage.DuplicateRecord)); } var productCategorySlug = product.Category.Slug; var productSlug = GenerateSlug.Slugify(command.Slug); var picturePath = $"{productCategorySlug}/{productSlug}"; var pictureName = _fileUploader.FileUpload(command.Picture, picturePath); product.Edit(command.Name, command.Code, GenerateSlug.Slugify(command.Slug), command.MetaDescription, command.Keywords, command.Description, command.ShortDescription, pictureName, command.PictureAlt, command.PictureTitle, command.CategoryId); _productRepository.SaveChanges(); return(operationResult.Succeeded()); }
public ActionResult Edit(EditProduct model) { try { if (ModelState.IsValid) { var product = db.Products.Where(p => p.ProductId == model.ProductId).FirstOrDefault(); if (product != null) { decimal price = 0; decimal discount = 0; if (Decimal.TryParse(model.Price.Replace(",", ""), out price) && Decimal.TryParse(model.Discount.Replace(",", ""), out discount)) { product.ProductName = model.ProductName; product.ProductNameUnsign = StringExtensions.convertToUnSign(model.ProductName).ToLower(); product.Description = model.Description; product.DescriptionUnsign = StringExtensions.convertToUnSign(model.Description).ToLower(); product.BrandId = model.BrandId; product.CategoryId = model.CategoryId; product.SKU = model.SKU; product.QuantityPerUnit = model.QuantityPerUnit; product.Price = price; product.Discount = discount; product.LastUpdate = DateTime.Now; product.LastUpdateUser = GetLogonUserName(); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Giá sản phẩm không hợp lệ!"); } } else { ModelState.AddModelError("", "Không tìm thấy sản phẩm!!!"); } } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); // Write error log var log = new Log(); log.LogDate = DateTime.Now; log.Action = "Product - Edit()"; log.Tags = "Error"; log.Message = ex.ToString(); db.Logs.Add(log); } finally { model.BrandSelectOptions = DropDownListOption.GetBrandOptions(model.BrandId ?? 0); model.CategorySelectOptions = DropDownListOption.GetCategoryOptions(model.CategoryId ?? 0); } return(View(model)); }
public ActionResult Edit(int?id) { EditProduct editProduct; if (id.HasValue) { editProduct = Mapper.Map <EditProduct>(Products.GetByID(id.Value)); editProduct.Text = HttpUtility.HtmlDecode(editProduct.Text); editProduct.GroupUrlPerfix = Groups.GetByID(editProduct.GroupID.Value).UrlPerfix; editProduct.Groups = ProductGroups.GetByProductID(editProduct.ID).Select(item => item.GroupID).ToList(); editProduct.Images = ProductImages.GetByProductID(editProduct.ID); editProduct.Files = ProductFiles.GetByProductID(editProduct.ID); editProduct.Marks = ProductMarks.GetByProductID(editProduct.ID); editProduct.Points = ProductPoints.GetByProductID(editProduct.ID); editProduct.Keywords = ProductKeywords.GetByProductID(editProduct.ID); editProduct.Notes = ProductNotes.GetByProductID(editProduct.ID); editProduct.ProductPricesLinks = ProductPricesLinks.GetByProductID(editProduct.ID); editProduct.Supplies = ProductSupplies.GetByProductID(editProduct.ID); editProduct.Prices = ProductPrices.GetByProductID(editProduct.ID); editProduct.Varients = ProductVarients.GetByProductID(editProduct.ID); editProduct.Discounts = ProductDiscounts.GetAllByProductID(editProduct.ID); } else { editProduct = new EditProduct(); editProduct.userID = UserID; } return(View(editProduct)); }
private void editProduct_Click(object sender, EventArgs e) { EditProduct ep = new EditProduct(); ep.Show(); File.WriteAllText(@"D:\dsadsa.txt", "dsnfdasbnfbadfkjbafkjbdas"); }
private static void SaveMarks(EditProduct editProduct, int productID) { var curList = ProductMarks.GetByProductID(productID); foreach (var mark in editProduct.Marks) { if (!curList.Any(item => item.ID == mark.ID)) { var productMark = Mapper.Map <ProductMark>(mark); productMark.ProductID = productID; ProductMarks.Insert(productMark); } else { ProductMarks.Update(mark); curList.Remove(curList.Single(cls => cls.ID == mark.ID)); } } foreach (var item in curList) { ProductMarks.Delete(item.ID); } }
public void Execute(object parameter) { ScannedProduct s = (ScannedProduct)parameter; EditProduct ep = new EditProduct(ref s); VM.LoadEditProductView(ep); }
public OperationResult Edit(EditProduct command) { var operation = new OperationResult(); var product = _productRepository.GetProductWithCategory(command.Id); if (product == null) { return(operation.Failed(ApplicationMessages.RecordNotFound)); } if (_productRepository.Exists(x => x.Name == command.Name && x.Id != command.Id)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var slug = command.Slug.Slugify(); var path = $"{product.Category.Slug}/{slug}"; var picturePath = _fileUploader.Upload(command.Picture, path); product.Edit(command.Name, command.Code, command.ShortDescription, command.Description, picturePath, command.PictureAlt, command.PictureTitle, slug, command.Keywords, command.MetaDescription, command.CategoryId); _productRepository.SaveChanges(); return(operation.Succeed()); }
public OperationResult Edit(EditProduct command) { OperationResult operationResult = new OperationResult(); var product = _productRepo.GetProductWithCategory(command.Id); if (product == null) { return(operationResult.Failed(ApplicationMessage.recordNotFound)); } if (_productRepo.Exists(c => c.Name == command.Name && c.Id != command.Id)) { return(operationResult.Failed(ApplicationMessage.duplicated)); } if (_productRepo.Exists(c => c.Code == command.Code && c.Id != command.Id)) { return(operationResult.Failed(ApplicationMessage.duplicated)); } var slug = GenerateSlug.Slugify(command.Slug); var path = $"{product.ProductCategory.Slug}/{slug}"; var pictuepath = _fileUploader.Upload(command.picture, path); product.Edit(command.Name, command.Code, command.ShortDescription, command.Description, pictuepath, command.pictureAlt, command.pictureTitle, command.KeyWords, command.MetaDescription, slug, command.CategoryId); _productRepo.Save(); return(operationResult.Succeeded()); }
public ActionResult AddProduct(EditProduct product) { var newproduct = _manage.AddProduct(_manage.ToProduct(product)); _manage.SaveProductImage(product, newproduct.ProductId); return(RedirectToAction("Details", "Store", new { id = newproduct.ProductId })); }
private static void SaveFiles(EditProduct editProduct, int productID) { var curList = ProductFiles.GetByProductID(productID); foreach (var file in editProduct.Files) { if (!curList.Any(item => item.ID == file.ID)) { var productFile = Mapper.Map <ProductFile>(file); productFile.ProductID = productID; ProductFiles.Insert(productFile); } else { ProductFiles.UpdateTitle(file.ID, file.Title); curList.Remove(curList.Single(cls => cls.ID == file.ID)); } } foreach (var item in curList) { ProductFiles.Delete(item.ID); } }
private void EditProductExecute() { try { EditProduct editProduct = new EditProduct(SelectetProduct); editProduct.ShowDialog(); if ((editProduct.DataContext as EditProductViewModel).IsUpdateProduct == true) { string productName = (editProduct.DataContext as EditProductViewModel).OldProduct.ProductName; int amount = (int)(editProduct.DataContext as EditProductViewModel).OldProduct.Amount; string code = (editProduct.DataContext as EditProductViewModel).OldProduct.Code; decimal price = (decimal)(editProduct.DataContext as EditProductViewModel).OldProduct.Price; string newProductName = (editProduct.DataContext as EditProductViewModel).Product.ProductName; int newAmount = (int)(editProduct.DataContext as EditProductViewModel).Product.Amount; string newCode = (editProduct.DataContext as EditProductViewModel).Product.Code; decimal newPrice = (decimal)(editProduct.DataContext as EditProductViewModel).Product.Price; string textToWrite = String.Format("You changed product {0} {1} {2} {3} to " + " {4} {5} {6} {7}." , productName, amount, code, price, newProductName, newAmount, newCode, newPrice); eventObject.OnActionPerformed(textToWrite); ProductList = dataService.GetProducts(); } else { ProductList = dataService.GetProducts(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private static void SavePoints(EditProduct editProduct, int productID) { var curList = ProductPoints.GetByProductID(productID); foreach (var point in editProduct.Points) { if (!curList.Any(item => item.ID == point.ID)) { var productPoint = Mapper.Map <ProductPoint>(point); productPoint.ProductID = productID; ProductPoints.Insert(productPoint); } else { ProductPoints.Update(point); curList.Remove(curList.Single(cls => cls.ID == point.ID)); } } foreach (var item in curList) { ProductPoints.Delete(item.ID); } }
public async Task <HttpResult <bool> > UpdateProduct(Product entity, CancellationToken token = default(CancellationToken)) { var result = new HttpResult <bool>(); var model = new EditProduct { Id = entity.Id, Image = entity.Avatar, ProductAttributes = entity .ProductAttributes .Select(pa => new WebApiServer.Controllers.Product.ViewModel.ProductAttribute { Attribute = new WebApiServer.Controllers.Product.ViewModel.Attribute { Id = pa.Attribute.Id, Name = pa.Attribute.Name }, Value = pa.Value }) .ToList() }; await _unitOfWork.EditProduct(model); return(result); }
private static void SaveGroups(EditProduct editProduct, int productID) { var curList = ProductGroups.GetByProductID(productID); foreach (var groupID in editProduct.Groups) { if (!curList.Any(item => item.GroupID == groupID)) { var productGroup = new ProductGroup(); productGroup.ProductID = productID; productGroup.GroupID = groupID; ProductGroups.Insert(productGroup); } else { curList.Remove(curList.Single(cls => cls.GroupID == groupID)); } } foreach (var item in curList) { ProductGroups.Delete(item.ID); } }
public IActionResult Create(EditProduct lstProduct) { if (ModelState.IsValid) { return(Ok()); } return(NotFound()); }
public ViewResult Add() { var product = new EditProduct(); ViewBag.Title = Localisation.Admin.PageContent.Add; ViewBag.Product = Localisation.Admin.PageContent.Product; ViewBag.ViewType = "Add"; return(View("Edit", product)); }
public async Task EditProduct(EditProduct model) { var transaction = _dbContext.Database.BeginTransaction(); try { var product = await ProductRepository.Get(model.Id); product.Image = model.Image; ProductRepository.Update(product); Save(); product.ProductAttributes.Clear(); var attributesToAdd = model .ProductAttributes .Select(pa => pa.Attribute.Name) .Except( _attributeRepository .Entities .Select(at => at.Name)) .Select(at => new Data_Access_Layer.Attribute { Name = at }); await AttributeRepository.AddRange(attributesToAdd); Save(); var productAttributesToAdd = AttributeRepository .Entities .Join(model.ProductAttributes, pv => pv.Name, pv => pv.Attribute.Name, (attr, prattr) => new Data_Access_Layer.ProductAttribute { ProductId = product.Id, AttributeId = attr.Id, Value = prattr.Value }); await ProductAttributeRepository.AddRange(productAttributesToAdd); Save(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } }
public void Edit(EditProduct command) { var product = _productRepository.Get(command.ProductId); if (product != null) { product.Edit(command.Name, command.UnitPrice, command.CategoryId); _productRepository.SaveChanges(); } }
public JsonResult OnPostEdit(EditProduct command) { if (ModelState.IsValid) { } var result = _productApplication.Edit(command); return(new JsonResult(result)); }
public IActionResult OnPostEdit(EditProduct command) { var result = new OperationResult(); if (ModelState.IsValid) { result = _productApplication.Edit(command); } return(new JsonResult(result)); }
public async Task <IActionResult> EditProduct(EditProduct editedProduct) { if (!ModelState.IsValid) { return(View("~/Views/Admin/Product/EditProduct.cshtml", editedProduct)); } var resultProduct = await _productService.Update(editedProduct); return(RedirectToAction("EditBrand", new { id = resultProduct.BrandId })); }
public void FromEntity_should_map_properties_when_invoked() { var fakeProduct = Fakes.FakeProduct(); var editProduct = new EditProduct(); editProduct.FromEntity(fakeProduct); Assert.That(editProduct.Name, Is.EqualTo(fakeProduct.Name)); Assert.That(editProduct.Description, Is.EqualTo(fakeProduct.Description)); Assert.That(editProduct.Sku, Is.EqualTo(fakeProduct.Sku)); }
public IActionResult Edit(EditProduct model) { if (ModelState.IsValid) { if (productRepository.Edit(model) > 0) { return(RedirectToAction("Index", "Product", new { categoryid = model.catelogyid })); } } return(View(model)); }
private void PictureBox10_Click(object sender, EventArgs e) { if (dataGridView2.CurrentCell != null) { int i = dataGridView2.CurrentCell.RowIndex; EditProduct p = new EditProduct(levelProduct[i]); p.FormClosing += new FormClosingEventHandler(updAdminProductActions); p.Show(); } }
public void ToEntity_should_map_properties_when_invoked() { var editProduct = new EditProduct { Name = "Product Name", Description = "Product Description", Sku = "123" }; var product = editProduct.ToEntity(); Assert.That(product.Name, Is.EqualTo(editProduct.Name)); Assert.That(product.Description, Is.EqualTo(editProduct.Description)); Assert.That(product.Sku, Is.EqualTo(editProduct.Sku)); }
protected override void OnInit(EventArgs e) { contentListProducts.OnDblClickClientScriptFunction = "listDblClick"; btnEditProduct.ClientScript = "listDblClick(" + contentListProducts.ClientScriptId + ");"; btnAddProduct.SetWorkflowMethod<NewProduct>(null, null, false, false, true, null); if (Request["open"] != null) { string key = Request["open"].ToString(); EditProduct editProductWM = new EditProduct(); editProductWM.SetUnsecureInput("Key", key); WAFContext.StartWorkflowMethod(editProductWM); } else if (WAFContext.Session.CurrentNodeId > 0 && WAFContext.Request.SpecifiesNodeId) { EditProduct editProductWM = new EditProduct(); editProductWM.SetUnsecureInput("Key", new CKeyNLR(WAFContext.Session.CurrentNodeId, WAFContext.Session.LCID, 0).ToString()); WAFContext.StartWorkflowMethod(editProductWM); } base.OnInit(e); }