Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 12 additions & 0 deletions ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions ConsoleApp/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace ConsoleApp
{
public class Order
{
public int OrderID { get; set; }
public int ShipperID { get; set; }
public int DriverID { get; set; }
public DateTime CompletionDte { get; set; }
public int Status { get; set; }
public string Code { get; set; }
public int MSA { get; set; }
public double Duration { get; set; }
public int OfferType { get; set; }
}
}
141 changes: 141 additions & 0 deletions ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks;
using System.Globalization;

namespace ConsoleApp
{
class Program
{
public static HttpClientHandler clientHandler;
public static HttpClient client;
private static int resultLimit = 3;
static async Task Main()
{
clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };

// Pass the handler to httpclient(from you are calling api)
client = new HttpClient(clientHandler);
// Call asynchronous network methods in a try/catch block to handle exceptions.
string input = "";
string strDate = "";
DateTime userDate;
bool parsed = false;
while (true)
{
try
{
Console.WriteLine("___________________________________________");
Console.WriteLine("Find Orders");
Console.WriteLine("Select all orders by typing 'all'");
Console.WriteLine("Find a single order by typing id number (ex. 37)");
Console.WriteLine("Type 'exit' to exit program");
Console.WriteLine("___________________________________________");
input = Console.ReadLine();
parsed = Int32.TryParse(input, out int id);
if (parsed)
{
Console.WriteLine("Enter the Complete Date for order: (ex. 2018-02-15T05:10:00)");
strDate = Console.ReadLine();
userDate = DateTime.Parse(strDate);
Console.WriteLine($"getting order by id: {id}");
HttpResponseMessage response = await client.GetAsync($"http://localhost:5000/Order/{id}");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
if (responseBody.Length == 0)
{
Console.WriteLine($"Couldn't find order for id: {id}");
}
else
{
Order currentOrder = JsonConvert.DeserializeObject<Order>(responseBody);
if (DateTime.Compare(currentOrder.CompletionDte, userDate) == 0) {
Console.WriteLine("found your order!");
Console.WriteLine(responseBody);
} else {
Console.WriteLine($"Order {id} exists but the completion date wasn't correct. Try again");
}

}
}
else
{
if (input.ToLower() == "all")
{
Console.WriteLine("fetching all orders now...");
HttpResponseMessage response = await client.GetAsync("http://localhost:5000/Order");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
List<Order> orders = JsonConvert.DeserializeObject<List<Order>>(responseBody);
int numOfPages = orders.Count / resultLimit;
int currentPage = 1;
int prevPage = 1;
Order[] currentOrders = new Order[resultLimit];
Console.WriteLine(orders.Count + " orders found!");
while (true)
{
currentOrders = orders.GetRange(currentPage - 1, resultLimit).ToArray();
Console.WriteLine("===============================================");
Console.WriteLine($"Currently on page {currentPage}");
Console.WriteLine($"There are {numOfPages} pages of results");
string strOrder = "";
foreach (Order order in currentOrders)
{
strOrder = JsonConvert.SerializeObject(order);
Console.WriteLine(strOrder);
}
Console.WriteLine("===============================================");
Console.WriteLine($"To navigate to a new page, type a number between 1 - {numOfPages}");
Console.WriteLine("Type 'back' to return to search");
Console.WriteLine("Type 'exit' to exit program");
prevPage = currentPage;
string userInput = Console.ReadLine();
bool isNum = Int32.TryParse(userInput, out currentPage);
if (isNum && currentPage >= 1 && currentPage <= numOfPages)
{
continue;
} else
{
if (userInput.ToLower() == "back")
{
Console.WriteLine("returning to search...");
break;
} else if (userInput.ToLower() == "exit") {
Console.WriteLine("exiting program...");
System.Environment.Exit(0);
}
else
{
currentPage = prevPage;
Console.WriteLine("Page number incorrect, try again!");
}
}
}

}
else if (input.ToLower() == "exit")
{
Console.WriteLine("exiting program");
break;
}
else
{
Console.WriteLine("Wrong input given. Try again...");
}
}
}
catch (HttpRequestException e)
{
Console.WriteLine("Couldn't find your oder. Try again!");
}
catch (FormatException) {
Console.WriteLine("'{0}' is not in an acceptable format. Try again!", strDate);
}
}
}
}
}
41 changes: 41 additions & 0 deletions ConsoleApp/bin/Debug/netcoreapp3.0/ConsoleApp.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.0": {
"ConsoleApp/1.0.0": {
"dependencies": {
"Newtonsoft.Json": "12.0.3"
},
"runtime": {
"ConsoleApp.dll": {}
}
},
"Newtonsoft.Json/12.0.3": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "12.0.0.0",
"fileVersion": "12.0.3.23909"
}
}
}
}
},
"libraries": {
"ConsoleApp/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Newtonsoft.Json/12.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"path": "newtonsoft.json/12.0.3",
"hashPath": "newtonsoft.json.12.0.3.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file added ConsoleApp/bin/Debug/netcoreapp3.0/ConsoleApp.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\MSI Infinite\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\MSI Infinite\\.nuget\\packages",
"C:\\Microsoft\\Xamarin\\NuGet",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.0.0"
}
}
}
Binary file not shown.
41 changes: 41 additions & 0 deletions ConsoleApp/bin/Prod/ConsoleApp.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.0": {
"ConsoleApp/1.0.0": {
"dependencies": {
"Newtonsoft.Json": "12.0.3"
},
"runtime": {
"ConsoleApp.dll": {}
}
},
"Newtonsoft.Json/12.0.3": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "12.0.0.0",
"fileVersion": "12.0.3.23909"
}
}
}
}
},
"libraries": {
"ConsoleApp/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Newtonsoft.Json/12.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"path": "newtonsoft.json/12.0.3",
"hashPath": "newtonsoft.json.12.0.3.nupkg.sha512"
}
}
}
Binary file added ConsoleApp/bin/Prod/ConsoleApp.dll
Binary file not shown.
Binary file added ConsoleApp/bin/Prod/ConsoleApp.exe
Binary file not shown.
Binary file added ConsoleApp/bin/Prod/ConsoleApp.pdb
Binary file not shown.
10 changes: 10 additions & 0 deletions ConsoleApp/bin/Prod/ConsoleApp.runtimeconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\MSI Infinite\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\MSI Infinite\\.nuget\\packages",
"C:\\Microsoft\\Xamarin\\NuGet",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
]
}
}
9 changes: 9 additions & 0 deletions ConsoleApp/bin/Prod/ConsoleApp.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.0.0"
}
}
}
Binary file added ConsoleApp/bin/Prod/Newtonsoft.Json.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions ConsoleApp/obj/ConsoleApp.csproj.nuget.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 1,
"dgSpecHash": "izMNcGb4+UMKyfEIU+Q9hvjuoW91yeSKTf1o9BxT9VI8xzF/1bOEjHfxIuCW4G90EukgiWbz6Q3NLRG+SRGMPw==",
"success": true
}
71 changes: 71 additions & 0 deletions ConsoleApp/obj/ConsoleApp.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"format": 1,
"restore": {
"C:\\Users\\MSI Infinite\\Documents\\projects\\simpleOrderSearch\\ConsoleApp\\ConsoleApp.csproj": {}
},
"projects": {
"C:\\Users\\MSI Infinite\\Documents\\projects\\simpleOrderSearch\\ConsoleApp\\ConsoleApp.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\MSI Infinite\\Documents\\projects\\simpleOrderSearch\\ConsoleApp\\ConsoleApp.csproj",
"projectName": "ConsoleApp",
"projectPath": "C:\\Users\\MSI Infinite\\Documents\\projects\\simpleOrderSearch\\ConsoleApp\\ConsoleApp.csproj",
"packagesPath": "C:\\Users\\MSI Infinite\\.nuget\\packages\\",
"outputPath": "C:\\Users\\MSI Infinite\\Documents\\projects\\simpleOrderSearch\\ConsoleApp\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Microsoft\\Xamarin\\NuGet\\",
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
],
"configFilePaths": [
"C:\\Users\\MSI Infinite\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.0": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.0": {
"dependencies": {
"Newtonsoft.Json": {
"target": "Package",
"version": "[12.0.3, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.0.100\\RuntimeIdentifierGraph.json"
}
}
}
}
}
Loading