public async Task <IActionResult> Put(int id, [FromBody] ProductEditDTO product) { if (id != product.Id) { return(BadRequest("Ids don't match")); } if (!(await IsAllowedToPostOrPutProduct(product.CategoryId))) { return(Unauthorized("You are not allowed to edit product in this category")); } var existingProduct = await _unitOfWork.ProductRepository.Get(p => p.Id == product.Id); if (existingProduct == null) { return(NotFound()); } var productEntity = _mapper.Map <Product>(product); existingProduct.Name = productEntity.Name; existingProduct.CategoryId = productEntity.CategoryId; existingProduct.MaxDays = productEntity.MaxDays; existingProduct.Image = productEntity.Image; _unitOfWork.ProductRepository.Update(existingProduct); if (await _unitOfWork.SaveAll()) { return(NoContent()); } return(BadRequest("Error while editing product")); }
public async Task <ActionResult> EditProduct([FromBody] ProductEditDTO productEditDTO) { object?[] values = { productEditDTO.Username, productEditDTO.ProductDetails?.Name, productEditDTO.ProductDetails?.Category, }; if (values.Contains(null)) { return(BadRequest("Missing parameter values")); } string result = await MarketProductsService.EditProductAsync ( productEditDTO.ProductId, productEditDTO.ProductDetails !.ToProductData(), productEditDTO.StoreId, productEditDTO.Username ); if (string.IsNullOrWhiteSpace(result)) { return(InternalServerError()); } if (result != "Product edited") { return(InternalServerError(result)); } return(Ok()); }
public void Edit(ProductEditDTO productEditDTO) { var productToEdit = productRepository.Get(productEditDTO.Id) ?? throw new ArgumentNullException(nameof(productEditDTO.Id)); productToEdit.Name = productEditDTO.Name; productToEdit.Price = productEditDTO.Price; productRepository.Edit(productToEdit); }
public void Edit(ProductEditDTO productEditDTO) { EditProductCommand command = new EditProductCommand { Id = productEditDTO.Id, Name = productEditDTO.Name, Price = productEditDTO.Price }; productEdit.Handle(command); }
public async Task <bool> ProductEdit(ProductEditDTO dto) { var rao = _mapper.Map <ProductEditRAO>(dto); if (await _repository.ProductEdit(rao)) { return(true); } throw new NotImplementedException(); }
public async Task <bool> EditProduct(ProductEditDTO dto) { var rao = _mapper.Map <ProductEditRAO>(dto); if (await _repository.EditProduct(rao)) { return(true); } return(false); }
public void Edit(ProductEditDTO productEditDTO) { productEdit.Edit(productEditDTO); var entry = new Activity { Id = Guid.NewGuid(), CreatedOn = DateTime.Now, Operation = "CreateProduct", Data = JsonConvert.SerializeObject(productEditDTO) }; //Persist the Activity }
public async Task <IActionResult> Update(int id, ProductEditDTO productDTO) { if (id != productDTO.Id) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } await _productService.Update(_mapper.Map <Product>(productDTO)); return(Ok(productDTO)); }
public async Task <IActionResult> EditProduct(int id, [FromBody] ProductEditDTO productEditDTO) { try { var product = mapper.Map <Product>(productEditDTO); var isEdited = await productManager.EditProduct(id, product); if (isEdited == true) { return(NoContent()); } return(BadRequest()); } catch (Exception) { throw; } }
public async Task <IActionResult> Edit(ProductEditDTO editDTO) { if (ModelState.IsValid) { Product product = await _repository.FindByIDAsync(editDTO.Id); if (editDTO.EditImage != null) { if (product.ImageName != null) { _fileWorker.RemoveFileInPath("/img/" + product.ImageName); } product.ImageName = await _fileWorker.AddFileToPathAsync(editDTO.EditImage, "img"); } if (!editDTO.IsPublish) { product.PublishDate = null; } else if (!product.IsPublish) { product.PublishDate = DateTime.Now; } product.IsPublish = editDTO.IsPublish; product.Price = editDTO.Price; product.Stock = editDTO.Stock; product.Title = editDTO.Title; product.Description = editDTO.Description; product.CategoryId = editDTO.CategoryId; _repository.Update(product); await _context.SaveChangesAsync(); return(LocalRedirect("/admin/products/index")); } SetCategories(); return(View(editDTO)); }
public ResultDTO EditUser([FromRoute] int id, [FromBody] ProductEditDTO model) { var product = _context.Products.FirstOrDefault(t => t.Id == id); product.Name = model.Name; product.CompanyName = model.CompanyName; product.Price = model.Price; product.Description = model.Description; product.Image = model.Image; product.Data = model.Data; product.SystemRequirementProduct.OS = model.sysreqProduct.OS; product.SystemRequirementProduct.Processor = model.sysreqProduct.Processor; product.SystemRequirementProduct.Graphics = model.sysreqProduct.Graphics; product.SystemRequirementProduct.Memory = model.sysreqProduct.Memory; product.SystemRequirementProduct.Storege = model.sysreqProduct.Storege; foreach (var item in _context.ProductCategories) { if (item.ProdctId == id) { _context.ProductCategories.Remove(item); } } foreach (var item in _context.ProductLanguages) { if (item.ProdctId == id) { _context.ProductLanguages.Remove(item); } } foreach (var item in model.listIdLang) { ProductLanguages temp = new ProductLanguages(); temp.ProdctId = id; temp.LanguageId = item; _context.ProductLanguages.Add(temp); } foreach (var item in model.listIdCateg) { ProductCategories temp = new ProductCategories(); temp.ProdctId = id; temp.CategoryId = item; _context.ProductCategories.Add(temp); } _context.SaveChanges(); return(new ResultDTO { Status = 200, Message = "OK" }); }
public void Edit(ProductEditDTO productEditDTO) { productEdit.Edit(productEditDTO); }