public async Task <IActionResult> UpdateImage(int imageId, PropertyImageUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _ownerPropertyService.UpdateImage(imageId, request); if (result == 0) { return(BadRequest()); } return(Ok()); }
public async Task <int> UpdateImage(int imageId, PropertyImageUpdateRequest request) { var propertyImage = await _context.PropertyImages.FindAsync(imageId); if (propertyImage == null) { throw new RealEstateException($"Không thể tìm thấy hình: {imageId}"); } if (request.ImageFile != null) { propertyImage.LinkName = await this.SaveFile(request.ImageFile); propertyImage.FileSize = request.ImageFile.Length; } _context.PropertyImages.Update(propertyImage); return(await _context.SaveChangesAsync()); }