public IActionResult Edit(int id) { var model = new ProductUpdateModel(); model.Load(id); return(View(model)); }
public ActionResult UpdateProduct(int receiptId, int productId, ProductUpdateModel productUpdateModel) { if (ModelState.IsValid) { var client = new RestClient(WebConfigurationManager.AppSettings["webApiUrl"]); var request = authorizationService.GenerateAuthorizedRequest ("/receipts/" + receiptId + "/products/" + productId + "/", Method.PUT, HttpContext); request.RequestFormat = DataFormat.Json; request.AddJsonBody(productUpdateModel); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { return(RedirectToAction("GetUserReceiptProducts", new { receiptId = receiptId })); } else { ViewBag.WrongMessage = response.ErrorMessage; return(View()); } } return(View()); }
public async Task <string> UpdateProductAsync(ProductUpdateModel model) { MultipartFormDataContent dataContent = new MultipartFormDataContent(); if (model.Image != null) { var stream = new MemoryStream(); await model.Image.CopyToAsync(stream); var bytes = stream.ToArray(); ByteArrayContent byteContent = new ByteArrayContent(bytes); byteContent.Headers.ContentType = new MediaTypeHeaderValue(model.Image.ContentType); dataContent.Add(byteContent, nameof(model.Image), model.Image.FileName); } dataContent.Add(new StringContent(model.Id.ToString()), nameof(model.Id)); dataContent.Add(new StringContent(model.Name), nameof(model.Name)); dataContent.Add(new StringContent(model.Description), nameof(model.Description)); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accessor.HttpContext.Session.GetString("token")); var responseMessage = await _httpClient.PutAsync($"{model.Id}", dataContent); if (responseMessage.IsSuccessStatusCode) { return(""); } else { return("api hatas� kontrol et"); } }
private void UpdateEvaluation(ProductUpdateModel productUpdateModel, ProductEntity productEntity) { var evaluationToDelete = productEntity.Evaluations.Where(evaluation => !productUpdateModel.Evaluations.Any(evaluations => evaluations.Id == evaluation.Id)); foreach (var evaluation in evaluationToDelete) { evaluationFacade.Delete(evaluation.Id); } var evaluationToInsert = productUpdateModel.Evaluations.Where( evaluation => !productEntity.Evaluations.Any(evaluations => evaluations.Id == evaluation.Id)); foreach (var evaluation in evaluationToInsert) { evaluation.ProductId = productUpdateModel.Id; evaluationFacade.Create(mapper.Map <EvaluationNewModel>(evaluation)); } var evaluationToUpdate = productUpdateModel.Evaluations.Where( evaluation => productEntity.Evaluations.Any(evaluations => evaluations.Id == evaluation.Id)); foreach (var evaluation in evaluationToUpdate) { evaluation.ProductId = productUpdateModel.Id; evaluationFacade.Update(evaluation); } }
public async Task <ProductResponseModel> UpdateAsync(Guid id, ProductUpdateModel model) { var newProduct = _mapper.Map <Product>(model); var updatedProduct = await _productService.UpdateAsync(id, newProduct); return(_mapper.Map <ProductResponseModel>(updatedProduct)); }
public IActionResult Update(ProductUpdateModel model) { if (ModelState.IsValid) { var product = _productService.GetById(model.Id); if (product != null) { Product p = new Product() { Id = model.Id, SellingPrice = model.SellingPrice, Stok = model.Stok, BuyingPrice = model.BuyingPrice, CategoryId = model.CategoryId, Marka = model.Marka, ProductName = model.ProductName, ProductPicture = model.ProductPicture, Condition = model.Condition, Description = model.Description }; _productService.Update(p); return(RedirectToAction("Index")); } return(RedirectToAction("Update")); } return(View(model)); }
public IActionResult Update(int id) { List <SelectListItem> dropcategory = _categoryService.GetAll().Select(x => new SelectListItem() { Text = x.CategoryName, Value = x.Id.ToString() }).ToList(); ViewBag.dropcategory = dropcategory; var model = _productService.GetById(id); ProductUpdateModel updateModel = new ProductUpdateModel() { SellingPrice = model.SellingPrice, Stok = model.Stok, BuyingPrice = model.BuyingPrice, CategoryId = model.CategoryId, Condition = model.Condition, Description = model.Description, Id = model.Id, Marka = model.Marka, ProductName = model.ProductName, ProductPicture = model.ProductPicture }; return(View(updateModel)); }
public IActionResult Add() { var model = new ProductUpdateModel(); var categories = model.GetAllCategoryList(); ViewBag.CategoryList = categories; return(View(model)); }
public IActionResult Edit(ProductUpdateModel model) { if (ModelState.IsValid) { model.EditProduct(); } return(RedirectToAction("Index")); }
public HttpResponseMessage Update(ProductUpdateModel productUpdateModel) { ProductDto productDto = this.mapper.Map <ProductUpdateModel, ProductDto>(productUpdateModel); this.productAppService.UpdateExistingProduct(productDto); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public async Task <IActionResult> Update([FromRoute] int id, [FromBody] ProductUpdateModel productUpdate) { var updatedProduct = await productService.UpdateProductAsync(id, mapper.Map <Product>(productUpdate)); var productFromDb = await productService.GetProductByIdAsync(updatedProduct.Id); // TODO: To optimize return(Ok(mapper.Map <ProductResponseModel>(productFromDb))); }
public async Task <IActionResult> Put(Guid id, ProductUpdateModel model) { var updatedProduct = await _productService.UpdateAsync(id, model); var response = new Response(updatedProduct); return(Ok(response)); }
public async Task <bool> UpdateDocumentAsync(int productId, ProductUpdateModel productInformation) { var ok = await this.updateDocumentAsync(productId, productInformation).ConfigureAwait(false); if (ok == false) { return(false); } return(await this.finalizeUdateAsync(productId).ConfigureAwait(false)); }
public async Task <int> UpdateProductAsync(ProductUpdateModel model, long productId) { var product = await _repositories.Products.FindAsync(productId); product.Description = model.Description; product.Name = model.Name; product.QuantityAvailable = model.QuantityAvailable; return(await _repositories.SaveChangesAsync()); }
public async Task <IActionResult> UpdateProduct(int id, ProductUpdateModel model) { var updated = await _service.UpdateProduct(id, model.Name, model.Description, model.ImageUrl, model.Price); if (!updated) { return(BadRequest()); } return(Ok()); }
public ProductDetailsModel UpdateProductById(Guid id, ProductUpdateModel productUpdateModel) { var found = Database.FirstOrDefault(id); if (found == null) { return(null); } Mapper.Map(productUpdateModel, found); return(Mapper.Map <ProductDetailsModel>(found)); }
public Guid?Update(ProductUpdateModel productUpdateModel) { var productEntityExisting = productRepository.GetById(productUpdateModel.Id); productEntityExisting.Evaluations = evaluationRepository.GetByProductId(productUpdateModel.Id); UpdateEvaluation(productUpdateModel, productEntityExisting); var productEntityUpdated = mapper.Map <ProductEntity>(productUpdateModel); return(productRepository.Update(productEntityUpdated)); }
public IHttpActionResult Update([FromBody] ProductUpdateModel productToUpdate) { if (ModelState.IsValid) { _productService = new ProductService(); _productService.UpdateProduct(productToUpdate); return(Ok()); } return(BadRequest("Invalid model state")); }
public static Product ConvertToEntity(this ProductUpdateModel updateModel) { Product product = new Product { Price = updateModel.Price, RepresentativeImage = updateModel.RepresentativeImage }; product.ChangeAttributes(updateModel.Attributes); product.ChangeImages(updateModel.Images); return(product); }
public IActionResult Add(ProductUpdateModel model) { if (ModelState.IsValid) { var imageUrl = model.ImageUpload(model.ProductImage); model.AddNewProductItem(imageUrl); } var categories = model.GetAllCategoryList(); ViewBag.CategoryList = categories; return(View(model)); }
public async Task <bool> UpdateMetaAsync(int productId, ProductUpdateModel productInformation) { //update the product using (var dclient = this.CreateClient()) { var client = dclient.Client; var url = ApiUrls.ProductUpdateMetaUrl.Replace("{id}", productId.ToString()); var content = this.GetContent(productInformation); var response = await client.PutAsync(this.GetUri(url), content).ConfigureAwait(false); return(await this.HandleResponseAsync(response).ConfigureAwait(false)); } }
private static async Task UpdateProduct(Dinero dinero, Product product) { var model = new ProductUpdateModel { AccountNumber = 1000, Quantity = 30, Unit = "km", Name = product.Name + " Updated", BaseAmountValue = 300, }; await dinero.Products.UpdateAsync(product.ProductGuid, model); Console.WriteLine("Product updated"); }
public async Task <bool> UpdateAsync(ProductUpdateModel model) { if (model == null || model.Id <= 0) { return(ToResponse(false, Errors.invalid_data)); } if (model.PartnerId <= 0) { return(ToResponse(false, "Vui lòng chọn đối tác")); } if (string.IsNullOrWhiteSpace(model.ProductName)) { return(ToResponse(false, "Vui lòng nhập tên sản phẩm")); } return(ToResponse(await _rpProduct.UpdateAsync(model, _process.User.Id))); }
public IActionResult ViewDetails(Product product, string error = "", int id = -1) { product.Category = (from products in _context.Products join categories in _context.Categories on products.Category.CategoryID equals categories.CategoryID where products.ProductID == product.ProductID select categories).FirstOrDefault(); ProductUpdateModel model = new ProductUpdateModel { product = id != -1 ? _context.Products.Find(id) : product, Categories = new SelectList(_context.Categories, "CategoryID", "CategoryName") }; ViewBag.error = error; return(View(model)); }
public void UpdateProduct(ProductUpdateModel productToUpdate) { using (var ctx = new ApplicationDbContext()) { // Find the product we want to update Product productWeWantToUpdate = ctx.Products.Find(productToUpdate.ProductID); if (productWeWantToUpdate != null) { // Update it productWeWantToUpdate.Name = productToUpdate.UpdatedName; productWeWantToUpdate.Price = productToUpdate.UpdatedPrice; // Save our changes to the database ctx.SaveChanges(); } } }
public IActionResult Add(ProductUpdateModel model) { if (ModelState.IsValid) { string path = null; var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); if (model.Image != null) { path = model.GetUploadedImage(model.Image.FileName); } model.AddNewProduct(path, userId); } var categories = model.GetAllCategoryList(); ViewBag.CategoryList = categories; return(View(model)); }
public async Task <IActionResult> UpdateProduct(ProductUpdateModel model) { if (ModelState.IsValid) { string message = await _productService.UpdateProductAsync(model); if (string.IsNullOrWhiteSpace(message)) { return(RedirectToAction("Index", "Product")); } else { ModelState.AddModelError("", "Resim yükleme hatası! Lütfen JPG veya PNG türünde yükleme yapınız"); return(View(model)); } } return(View(model)); }
public async Task <ActionResult> UpdateProduct([FromBody] ProductUpdateModel product) { try { if (!ModelState.IsValid) { return(BadRequest()); } var obj = await _dBRepository.product.Where(l => l.id == product.id).FirstOrDefaultAsync(); if (obj == null) { throw new Exception("there is no product with this id that passed in."); } obj.coding_id = product.coding_id; obj.product_code = product.product_code; obj.product_name = product.product_name; obj.buy_price = product.buy_price; obj.sale_price = product.sale_price; obj.sale_price2 = product.sale_price2; obj.product_barcode = product.product_barcode; obj.session_count = product.session_count; obj.start_date = product.start_date; obj.end_date = product.end_date; obj.is_active = product.is_active; await _dBRepository.SaveChangesAsync(); return(Ok(new CoreResponse() { is_success = true, data = obj })); } catch (Exception ex) { return(Ok(new CoreResponse() { is_success = false, data = null, dev_message = ex.Message })); } }
public IActionResult UpdateProduct(int productId, [FromBody] ProductUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var productEntity = _productRepository.GetProduct(productId); if (productEntity == null) { return(NotFound()); } _mapper.Map(model, productEntity); _productRepository.UpdateProduct(productEntity); return(NoContent()); }
public async Task <IActionResult> Put([FromBody] ProductUpdateModel model, [FromRoute][Required] int id) { var product = await _context.Product .FirstOrDefaultAsync(p => p.ProductId == id); if (product == null) { throw new EntryNotFoundException(id); } _mapper.Map(model, product); product.ModifiedDate = DateTime.UtcNow; _context.Update(product); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <bool> UpdateDocumentAsync(int productId, ProductUpdateModel productInformation, IEnumerable <FileModel> files) { if (files != null && files.Any(f => f.IsValid == false)) { throw new ArgumentException("Incorrect files, need the FileName, ContentType and Content", "files"); } var ok = await this.updateDocumentAsync(productId, productInformation).ConfigureAwait(false); if (ok == false) { return(false); } if (files != null) { return(await this.uploadFilesAsync(productId, files).ConfigureAwait(false)); } return(await this.finalizeUdateAsync(productId).ConfigureAwait(false)); }
/// <summary> /// Update a product in the organization. /// </summary> /// <param name="guid">The guid of the product to update</param> /// <param name="productUpdateModel">The updated product</param> public Task UpdateAsync(Guid guid, ProductUpdateModel productUpdateModel) { if (productUpdateModel == null) throw new ArgumentNullException("productUpdateModel"); return PutAsyncWithGuid<EmptyDineroResult>(guid, productUpdateModel); }
/// <summary> /// Update a product in the organization. /// </summary> /// <param name="guid">The guid of the product to update</param> /// <param name="productUpdateModel">The updated product</param> public void Update(Guid guid, ProductUpdateModel productUpdateModel) { TaskHelper.ExecuteSync(() => UpdateAsync(guid, productUpdateModel)); }