public async Task <ApiResponse> UploadImageMultile([FromForm] ProductImageDto dto) { try { if (!ModelState.IsValid) { return(new ApiResponse($"{ModelState}", ModelState, 400)); } if (dto.ProductId != Guid.Empty) { var product = await _productService.GetByIdAsync(dto.ProductId); if (product == null) { return(new ApiResponse("khong tim thay", dto.ProductId, 404)); } List <ProductImage> listPr = new List <ProductImage>(); foreach (IFormFile file in dto.Image) { ProductImage pr = new ProductImage(); MemoryStream ms = new MemoryStream(); file.CopyTo(ms); pr.Image = ms.ToArray(); pr.ProductId = product.Id; pr.Name = file.FileName; pr.Url = file.FileName; ms.Close(); ms.Dispose(); listPr.Add(pr); } var productImage = _mapper.Map <List <ProductImage> >(listPr); await _productImageService.AddManyAsync(productImage); var vm = _mapper.Map <List <ProductImageViewModel> >(productImage); return(new ApiResponse("them thanh cong", vm, 201)); } return(new ApiResponse("khong ton tai", 405)); } catch (Exception ex) { return(new ApiResponse("khong tim thay", ex, 404)); } }