public async Task <int> update(ProductUpdateSerializer request) { var product = await _context.Products.FindAsync(request.id); var productTranslation = await _context .ProductTranslations.FirstOrDefaultAsync( x => x.productId == request.id && x.languageId == request.languageId); if (product == null || productTranslation == null) { throw new AppleException($"Product {request.id} not found, try again!"); } productTranslation.name = request.name; productTranslation.brief = request.brief; productTranslation.title = request.title; productTranslation.slug = request.slug; // Save images if (request.thumbnail != null) { var productUpdate = await _context.ProductImages .FirstOrDefaultAsync( x => x.isDefault == true && x.productId == request.id); if (productUpdate != null) { productUpdate.imagePath = await this.SaveFile(request.thumbnail); } } return(await _context.SaveChangesAsync()); }
public async Task <IActionResult> update([FromBody] ProductUpdateSerializer request) { var affectedResult = await _manageProductServices.update(request); if (affectedResult == 0) { return(BadRequest()); } return(Ok()); }