Skip to content

Commit b62a69c

Browse files
Modified update-product
1 parent 036d44b commit b62a69c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

BlazorProducts.Client/BlazorProducts.Client/HttpRepository/IProductHttpRepository.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IProductHttpRepository
1515
Task CreateProduct(Product product);
1616
Task<string> UploadProductImage(MultipartFormDataContent content);
1717
Task<Product> GetProduct(string id);
18-
Task UpdateProduct(Product product, string id);
18+
Task UpdateProduct(Product product);
1919
Task DeleteProduct(Guid id);
2020
}
2121
}

BlazorProducts.Client/BlazorProducts.Client/HttpRepository/ProductHttpRepository.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ public async Task<Product> GetProduct(string id)
9393
return product;
9494
}
9595

96-
public async Task UpdateProduct(Product product, string id)
96+
public async Task UpdateProduct(Product product)
9797
{
9898
var content = JsonSerializer.Serialize(product);
9999
var bodyContent = new StringContent(content, Encoding.UTF8, "application/json");
100-
var url = Path.Combine("https://localhost:5011/api/products/", id);
100+
var url = Path.Combine("https://localhost:5011/api/products/", product.Id.ToString());
101101

102-
var postResult = await _client.PutAsync(url, bodyContent);
103-
var postContent = await postResult.Content.ReadAsStringAsync();
102+
var putResult = await _client.PutAsync(url, bodyContent);
103+
var putContent = await putResult.Content.ReadAsStringAsync();
104104

105-
if (!postResult.IsSuccessStatusCode)
105+
if (!putResult.IsSuccessStatusCode)
106106
{
107-
throw new ApplicationException(postContent);
107+
throw new ApplicationException(putContent);
108108
}
109109
}
110110

BlazorProducts.Client/BlazorProducts.Client/Pages/UpdateProduct.razor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected async override Task OnInitializedAsync()
2626

2727
private async Task Update()
2828
{
29-
await ProductRepo.UpdateProduct(_product, Id);
29+
await ProductRepo.UpdateProduct(_product);
3030
_notification.Show();
3131
}
3232

0 commit comments

Comments
 (0)