-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mdd-add-shipping-data-service #607
base: 25.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using System; | ||
using System.Net.Http.Json; | ||
|
||
namespace Infragistics.Samples | ||
{ | ||
public class ShippingDataService : IShippingDataService | ||
{ | ||
private readonly HttpClient _http; | ||
|
||
public ProductDataService(HttpClient http) | ||
{ | ||
_http = http; | ||
} | ||
|
||
public async Task<List<ShippingDataItem>> GetTable() | ||
{ | ||
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://www.igniteui.com/api/orders", UriKind.RelativeOrAbsolute)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define the Uri as a variable and then pass it to the http request |
||
using HttpResponseMessage response = await _http.SendAsync(request).ConfigureAwait(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why adding "using" statements in code-behind and not just declare them above "namespace Infragistics.Samples" ? |
||
if (response.IsSuccessStatusCode) | ||
{ | ||
return await response.Content.ReadFromJsonAsync<List<ShippingDataItem>>().ConfigureAwait(false); | ||
} | ||
|
||
return new List<ShippingDataItem>(); | ||
} | ||
} | ||
public interface IShippingDataService | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this interface really needed? |
||
{ | ||
Task<List<ShippingDataItem>> GetTable(); | ||
} | ||
|
||
public class ShippingDataItem | ||
{ | ||
public int OrderID { get; set; } | ||
public string EmployeeName { get; set; } | ||
public double ShipperID { get; set; } | ||
public string ShipperName { get; set; } | ||
public string CustomerID { get; set; } | ||
public string ContactName { get; set; } | ||
public int TotalItems { get; set; } | ||
public double TotalPrice { get; set; } | ||
public double Freight { get; set; } | ||
public string ShipAddress { get; set; } | ||
public string ShipCountry { get; set; } | ||
public string OrderDate { get; set; } | ||
public string ShipPostalCode { get; set; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why passing HttpClient if you can create it in an constructor of a ShippingDataService?