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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Development Project/Interview.Web/Contexts/CategoryContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Interview.Web.Models;
using System.Collections.Generic;

namespace Interview.Web.Contexts;

#region DTOs

public class CreateCategoryDto
{
public string Description { get; set; }
public string Name { get; set; }
}

#endregion

public class CategoryContext
{
public static CategoryModel CreateCategory(CreateCategoryDto category)
{
var sql = @"INSERT INTO Categories
([Description], [Name])
VALUES
(@Description, @Name)
";
// TODO: Exectue SQL ~ var newCat = ...
return new CategoryModel();
}

public static List<CategoryModel> GetCategories()
{
var sql = "SELECT * FROM Categories";
// TODO: Execute SQL ~ var categories = ...
return new List<CategoryModel>();
}
}
25 changes: 25 additions & 0 deletions Development Project/Interview.Web/Contexts/ProductContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Interview.Web.Models;
using System.Collections.Generic;

namespace Interview.Web.Contexts;

public class ProductContext
{
public static ProductModel CreateProduct(CreateProductDto product)
{
var sql = @"INSERT INTO Products
([Description], [Name], ProductImageUris, ValidSkus)
VALUES
(@Description, @Name, @ProductImageUris, @ValidSkus)
";
// TODO: Execute SQL ~ var newProd = ...
return new ProductModel();
}

public static List<ProductModel> GetAllProducts()
{
var sql = "SELECT * FROM Products";
// TODO: Execute SQL ~ var products = ...
return new List<ProductModel>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Interview.Web.Contexts;
using Interview.Web.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Interview.Web.Contexts;
using Microsoft.Extensions.Logging;

namespace Interview.Web.Controllers
{
[ApiController]
[Route("api/v1/categories")]
public class CategoryController : ControllerBase
{
private ILogger<CategoryController> _logger;

public CategoryController(ILogger<CategoryController> logger)
{
_logger = logger;
}

[HttpGet]
public ActionResult<List<CategoryModel>> GetAllCategories()
{
try
{
var categories = CategoryContext.GetCategories();
return Ok(categories);
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
return Problem();
}
}

[HttpPost]
public ActionResult<CategoryModel> CreateCategory([FromBody] CreateCategoryDto category)
{
try
{
var newCat = CategoryContext.CreateCategory(category);
return Ok(newCat);
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
return Problem();
}
}
}
}
56 changes: 52 additions & 4 deletions Development Project/Interview.Web/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,67 @@
using Microsoft.AspNetCore.Mvc;
using Interview.Web.Contexts;
using Interview.Web.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Interview.Web.Contexts;
using Microsoft.Extensions.Logging;

/*
* EVAL: Was not aware that Visual Studio would be a requirement. I am running on Endeavour
* and, as such, do not have access to Visual Studio. Sparcpoint.Inventory.Database
* does not load in Rider. I'm doing my best to extrapolate what I can from the
* *.sqlproj file and associated *.sql files.
*
* ERROR: "$(MSBuildExtensionsPath)/Microsoft/VisualStudio/v$(VisualStudioVersion)/SSDT/Microsoft.Data.Tools.Schema.SqlTasks.targets"
* does not exist and appears to be part of a Visual Studio component. This file may require MSBuild.exe in order to be imported
* successfully, and so may fail to build in the dotnet CLI.
* /home/jcroft/Git/Development-Project-CSharp/Development Project/Sparcpoint.Inventory.Database/Sparcpoint.Inventory.Database.sqlproj at (84:3)
*/

namespace Interview.Web.Controllers
{
[ApiController]
[Route("api/v1/products")]
public class ProductController : Controller
public class ProductController : ControllerBase
{
private ILogger<ProductController> _logger;

public ProductController(ILogger<ProductController> logger)
{
_logger = logger;
}

// NOTE: Sample Action
[HttpGet]
public Task<IActionResult> GetAllProducts()
public ActionResult<List<ProductModel>> GetAllProducts()
{
try
{
var products = ProductContext.GetAllProducts();
return Ok(products);
}
catch (Exception e)
{
_logger.LogError(e.Message);
return Problem();
}
}

[HttpPost]
public ActionResult<ProductModel> CreateProduct([FromBody] CreateProductDto product)
{
return Task.FromResult((IActionResult)Ok(new object[] { }));
try
{
var newProd = ProductContext.CreateProduct(product);
return Ok(newProd);
}
catch (Exception e)
{
_logger.LogError(e.Message);
return Problem();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Interview.Web.Models;

public class CategoryAttributeModel
{
// EVAL: I would, personally have named this CategoryInstanceId
public int InstanceId { get; set; }
public string Key { get; set; }
public string Value { get; set; }
}
30 changes: 30 additions & 0 deletions Development Project/Interview.Web/Models/CategoryModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;

namespace Interview.Web.Models;

public class CategoryModel
{
public DateTime CreatedTimestamp { get; set; }
public string Description { get; set; }
public int InstanceId { get; set; }
public string Name { get; set; }

private List<ProductModel>? _products;

public List<ProductModel>? Products
{
get => _products;
}

public void HydrateProducts()
{
if (_products != null)
{
return;
}

// EVAL: This will populate the Products property with ProductModel entities via the
// ProductCategories relation.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Interview.Web.Models;

public class ProductAttributeModel
{
// EVAL: I would have, personally named this ProductInstanceId
public int InstanceId { get; set; }
public string Key { get; set; }
public string Value { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Interview.Web.Models;

public class ProductCategoryModel
{
public int CategoryInstanceId { get; set; }
// EVAL: I would have, personally, named this ProductInstanceId
public int InstanceId { get; set; }
}
44 changes: 44 additions & 0 deletions Development Project/Interview.Web/Models/ProductModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;

namespace Interview.Web.Models;

#region DTOs

public class CreateProductDto
{
public string Description { get; set; }
public string Name { get; set; }
public string ProductImageUris { get; set; }
public string ValidSkus { get; set; }
}

#endregion

public class ProductModel
{
public DateTime CreatedTimestamp { get; set; }
public string Description { get; set; }
public int InstanceId { get; set; }
public string Name { get; set; }
public string ProductImageUris { get; set; }
public string ValidSkus { get; set; }

private List<CategoryModel>? _categories = null;

public List<CategoryModel>? Categories
{
get => _categories;
}

public void HydrateCategories()
{
if (_categories != null)
{
return;
}

// EVAL: This will populate the Categories property with CategoryModel entities via the
// ProductCategories relation.
}
}
3 changes: 3 additions & 0 deletions Development Project/Interview.Web/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
// for details on configuring this project to bundle and minify static web assets.

// Write your Javascript code.
window.addEventListener("DOMContentLoaded", () => {
// TODO
});