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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bin
obj
.vscode
*.db
.vs/SimpleOrderSearchConsole/v16/.suo
.vs/SimpleOrderSearchConsole/v16/Server/sqlite3/db.lock
.vs/SimpleOrderSearchConsole/config/applicationhost.config
.vs/SimpleOrderSearchConsole/DesignTimeBuild/.dtbcache
.vs/SimpleOrderSearchConsole/v16/Server/sqlite3/storage.ide
.vs/SimpleOrderSearchConsole/v16/Server/sqlite3/storage.ide-shm
.vs/SimpleOrderSearchConsole/v16/Server/sqlite3/storage.ide-wal
29 changes: 2 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,2 @@
# simpleOrderSearch
simpleOrderSearch


I want to assess your ability to create an application and REST API service. It truly is the bare minimum of knowledge necessary to be successful in this position. I don't want you to spend a lot of time on this. You should be able to do this in an hour or so if the job is right for you.

Order Search

This programming task consists of building a simple console application to search for orders. Fork this repository and create your application. It should take this input from the user:

(Order Number || (MSA && Status)) && CompletionDte

The console application will call a service that you create using C#. I have provided some sample data for the application in the JSON file in the data folder.



The file contains an array whose elements represent orders. The data should be defined as a model in your service.

The application calling the service can be a console app. You have total freedom to do what you want but make sure it can do these three things:

• Validate that the user has provided the right criteria to make a search

• Provide an offset and page value for pagination.

• Write the outputs of the service call to a console window.

Create a pull request once you have it working. I will clone your repository, verify that it works, and evaluate it. Please ensure you include any instructions for running that may be required.
Run both of the project SimpleOrderSearchApi and SimpleOrderSearchConsole
Then follow instruction on console terminal.
47 changes: 47 additions & 0 deletions SimpleOrderSearchAPI/Controllers/SimpleOrderSearchController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SimpleOrderSearchAPI.Data;
using SimpleOrderSearchAPI.Model;

namespace SimpleOrderSearchAPI.Controllers
{
[Route("api/[controller]")]
public class SimpleOrderSearchController : Controller
{
private readonly ISimpleOrderSearchService _service;
public SimpleOrderSearchController(ISimpleOrderSearchService service)
{
_service = service;
}

[HttpGet]
public IActionResult GetOrders([FromQuery]Params orderParam)
{
try
{
var orders = _service.GetSearchOrders(orderParam);
var pagination = new Pagination
{
CurrentPage = orders.CurrentPage,
ItemPerPage = orders.ItemPerPage,
TotalItems = orders.TotalItem,
TotalPages = orders.TotalPages,
Offset = orders.Offset
};
var result = new GetOrdersResponseMessage
{
Orders = orders,
Pagination = pagination
};
return Ok(result);
}
catch (Exception ex)
{
Console.WriteLine(ex);
return BadRequest();
}

}
}
}
14 changes: 14 additions & 0 deletions SimpleOrderSearchAPI/Data/ISimpleOrderSearchService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using SimpleOrderSearchAPI.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleOrderSearchAPI.Data
{
public interface ISimpleOrderSearchService
{
PageList<Order> GetSearchOrders(Params param);

}
}
48 changes: 48 additions & 0 deletions SimpleOrderSearchAPI/Data/SimpleOrderSearchService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Newtonsoft.Json;
using SimpleOrderSearchAPI.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace SimpleOrderSearchAPI.Data
{
public class SimpleOrderSearchService : ISimpleOrderSearchService
{
public PageList<Order> GetSearchOrders(Params request)
{
try
{
var orders = GetAllOrders();
var selectOrders = orders.Where(a =>
(a.OrderId == request.OrderId || (a.MSA == request.MSA && a.Status == request.Status))
&& a.CompletionDte == request.CompletionDte)
.Select(a => a).ToList();
return PageList<Order>.CreateAsync(selectOrders, request.PageNumber, request.ItemsPerPage, request.Offset);
}
catch
{
throw;
}
}

private List<Order> GetAllOrders()
{
try
{
var a = Directory.GetCurrentDirectory();
List<Order> orders = new List<Order>();
using (StreamReader file = new StreamReader(Directory.GetCurrentDirectory() + @"/Resources/orderInfo.json"))
{
JsonSerializer serializer = new JsonSerializer();
orders = (List<Order>)serializer.Deserialize(file, typeof(List<Order>));
};
return orders;
}
catch
{
throw;
}
}
}
}
17 changes: 17 additions & 0 deletions SimpleOrderSearchAPI/Helper/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Http;
using SimpleOrderSearchAPI.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleOrderSearchAPI.Helper
{
public static class Helper
{
public static void AddPagination(this HttpResponse response, List<Order> orders, Params param)
{

}
}
}
16 changes: 16 additions & 0 deletions SimpleOrderSearchAPI/Model/GetOrdersResponseMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleOrderSearchAPI.Model
{
public class GetOrdersResponseMessage
{
[JsonProperty("orders")]
public List<Order> Orders { get; set; }
[JsonProperty("pagination")]
public Pagination Pagination { get; set; }
}
}
27 changes: 27 additions & 0 deletions SimpleOrderSearchAPI/Model/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using System;

namespace SimpleOrderSearchAPI.Model
{
public class Order
{
[JsonProperty("OrderID")]
public int OrderId { get; set; }
[JsonProperty("ShipperID")]
public int ShipperID { get; set; }
[JsonProperty("DriverID")]
public int DriverID { get; set; }
[JsonProperty("CompletionDte")]
public DateTime CompletionDte { get; set; }
[JsonProperty("Status")]
public int Status { get; set; }
[JsonProperty("Code")]
public string Code { get; set; }
[JsonProperty("MSA")]
public int MSA { get; set; }
[JsonProperty("Duration")]
public string Duration { get; set; }
[JsonProperty("OfferType")]
public int OfferType { get; set; }
}
}
38 changes: 38 additions & 0 deletions SimpleOrderSearchAPI/Model/PageList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleOrderSearchAPI.Model
{
public class PageList<T> : List<T>
{
[JsonProperty("currentPage")]
public int CurrentPage { get; set; } = 1;
[JsonProperty("itemPerPage")]
public int ItemPerPage { get; set; } = 2;
[JsonProperty("totalItems")]
public int TotalItem { get; set; }
[JsonProperty("totalPages")]
public int TotalPages { get; set; }
[JsonProperty("offset")]
public int Offset { get; set; }

public PageList(List<T> items, int count, int pageNumber, int pageSize, int offset)
{
TotalItem = count;
ItemPerPage = pageSize;
Offset = offset;
CurrentPage = pageNumber;
TotalPages = (int)Math.Ceiling(count / (double)pageSize);
this.AddRange(items);
}
public static PageList<T> CreateAsync(List<T> source, int pageNumber, int pageSize, int offset)
{
var count = (source.Count() - offset) < 0 ? 0 : source.Count() - offset;
var items = source.Skip((pageNumber - 1) * pageSize + offset).Take(pageSize).ToList();
return new PageList<T>(items, count, pageNumber, pageSize, offset);
}
}
}
22 changes: 22 additions & 0 deletions SimpleOrderSearchAPI/Model/Pagination.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleOrderSearchAPI.Model
{
public class Pagination
{
[JsonProperty("currentPage")]
public int CurrentPage { get; set; } = 1;
[JsonProperty("itemPerPage")]
public int ItemPerPage { get; set; } = 2;
[JsonProperty("totalItems")]
public int TotalItems { get; set; }
[JsonProperty("totalPages")]
public int TotalPages { get; set; }
[JsonProperty("offset")]
public int Offset { get; set; }
}
}
28 changes: 28 additions & 0 deletions SimpleOrderSearchAPI/Model/Params.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SimpleOrderSearchAPI.Model
{
public class Params
{
[JsonProperty("offset")]
public int Offset { get; set; } = 0;
[JsonProperty("pageNumber")]
public int PageNumber { get; set; } = 1;
[JsonProperty("orderId")]
public int OrderId { get; set; }
[JsonProperty("msa")]
public int MSA { get; set; }
[JsonProperty("status")]
public int Status { get; set; }
[JsonProperty("totalItem")]
public int TotalItem { get; set; }
[JsonProperty("completionDte")]
public DateTime CompletionDte { get; set; }
[JsonProperty("itemsPerPage")]
public int ItemsPerPage { get; set; } = 2;
}
}
26 changes: 26 additions & 0 deletions SimpleOrderSearchAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace SimpleOrderSearchAPI
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
30 changes: 30 additions & 0 deletions SimpleOrderSearchAPI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55768",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SimpleOrderSearchAPI": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading