Skip to content
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

Open
wants to merge 1 commit into
base: 25.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions code-gen-library/ShippingDataService/ShippingDataService.cs
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;
Copy link
Collaborator

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?

}

public async Task<List<ShippingDataItem>> GetTable()
{
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://www.igniteui.com/api/orders", UriKind.RelativeOrAbsolute));
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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; }
}
}
Loading