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
3 changes: 3 additions & 0 deletions Development Project/.github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools.
- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first.
- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it.
14 changes: 12 additions & 2 deletions Development Project/Development Project.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.357
# Visual Studio Version 17
VisualStudioVersion = 17.14.37216.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Interview.Web", "Interview.Web\Interview.Web.csproj", "{EE17B748-4D84-46AE-9E83-8D04B92DD6A9}"
EndProject
Expand All @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sparcpoint.Core", "Sparcpoi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sparcpoint.SqlServer.Abstractions", "Sparcpoint.SqlServer.Abstractions\Sparcpoint.SqlServer.Abstractions.csproj", "{4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sparcpoint.Api", "Sparcpoint.Api\Sparcpoint.Api.csproj", "{7F3ED659-743B-4121-8A88-ACBCDB879DD3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -55,6 +57,14 @@ Global
{4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|Any CPU.Build.0 = Release|Any CPU
{4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|x86.ActiveCfg = Release|Any CPU
{4E72CD4A-C9FE-4A04-9F07-A770E3AD7297}.Release|x86.Build.0 = Release|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|x86.ActiveCfg = Debug|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Debug|x86.Build.0 = Debug|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|Any CPU.Build.0 = Release|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|x86.ActiveCfg = Release|Any CPU
{7F3ED659-743B-4121-8A88-ACBCDB879DD3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
31 changes: 26 additions & 5 deletions Development Project/Interview.Web/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
using Microsoft.AspNetCore.Mvc;
using Sparcpoint.API.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sparcpoint.API.API;

namespace Interview.Web.Controllers
{
[Route("api/v1/products")]
public class ProductController : Controller
public class ProductController(Products products) : Controller
{

// NOTE: Sample Action
[HttpGet]
public Task<IActionResult> GetAllProducts()
public async Task<IActionResult> GetAllProducts()
{
var allProducts = await products.GetProducts();

return Ok(allProducts);
}

[HttpPost]
public async Task<IActionResult> AddNewProduct(ProductModel productModel, ProductAttributesModel productAttributesModel)
{
return Task.FromResult((IActionResult)Ok(new object[] { }));
var add = await products.AddProduct(productModel, productAttributesModel);

return Json(add);
}

[HttpPost]
public async Task<IActionResult> SearchProducts(SearchModel searchModel)
{
var search = await products.SearchProducts(searchModel);

//get needed product info to pass into ui

return Json(search);
}
}
}
4 changes: 4 additions & 0 deletions Development Project/Interview.Web/Interview.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Sparcpoint.Api\Sparcpoint.Api.csproj" />
</ItemGroup>

</Project>
29 changes: 23 additions & 6 deletions Development Project/Interview.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using Interview.Web.Controllers;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Sparcpoint.API.API;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Threading.Tasks;

namespace Interview.Web
Expand All @@ -16,11 +20,24 @@ public static void Main(string[] args)
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
public static IHostBuilder CreateHostBuilder(string[] args)
{
var builder = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureServices((hostContext, services) =>
{
var connectionString = hostContext.Configuration.GetConnectionString("DefaultConnectionString") ??
throw new InvalidOperationException("ConnectionString cannot be null");
services.AddSingleton(connectionString);
services.AddScoped<ProductController>();
services.AddScoped<Products>();
});

return builder;
}
}
}

5 changes: 4 additions & 1 deletion Development Project/Interview.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=Sparcpoint;Trusted_Connection=True;MultipleActiveResultSets=True;"
}
}
92 changes: 92 additions & 0 deletions Development Project/Sparcpoint.Api/API/Products.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Sparcpoint.API.Models;

using Dapper;
using System.Linq.Expressions;
using Microsoft.Data.SqlClient;
using System.Text.Json.Nodes;

namespace Sparcpoint.API.API
{
public class Products
{
private readonly string _connectionString;

public Products(string connectionString)
{
_connectionString = connectionString;
}
public async Task<IEnumerable<ProductModel>> GetProducts()
{
try
{
using (var connection = new SqlConnection(_connectionString))
{
var sql = "SELECT * FROM Products";
var products = await connection.QueryAsync<ProductModel>(sql);
return products.ToList();
}
}
catch (Exception ex)
{
// Handle exceptions (e.g., log the error)
Console.WriteLine($"An error occurred: {ex.Message}");
return Enumerable.Empty<ProductModel>();
}
}

public async Task<ProductModel> AddProduct(ProductModel productModel, ProductAttributesModel productAttributesModel)
{
try
{
using (var connection = new SqlConnection(_connectionString))
{
var productSql = "INSERT INTO Products (Name, Description, ProductImageUris, ValidSkus, CreatedTimestamp) VALUES (@Name, @Description, @ProductImageUris, @ValidSkus, @CreatedTimestamp";

productModel.Id = await connection.ExecuteAsync(productSql, productModel);

productAttributesModel.Key = productModel.Id;
var productAttributesSql = "INSERT INTO Products (Key, Value,) VALUES (@Key, @Value";

productAttributesModel.InstanceId = await connection.ExecuteAsync(productAttributesSql, productAttributesModel);
}
}
catch (Exception ex)
{
// Handle exceptions (e.g., log the error)
Console.WriteLine($"An error occurred: {ex.Message}");
}

return productModel;
}

public async Task<ReturnModel> SearchProducts(SearchModel model)
{
using (var connection = new SqlConnection(_connectionString))
{
var sql = @"
SELECT p.Id
FROM [dbo].[Product] p
Join [dbo].[ProductAttributes] pa on pa.Key = p.Id
WHERE p.Description Like %@Query% or p.Name Like %@Name% or p.CreatedTimestamp = @CreatedTimestamp or pa.value Like %Query%";


var run = await connection.QueryAsync(sql, model);

List<int> productIds = new List<int>();

foreach (var item in run)
{
productIds.Add(item.Id);
}

var searchResults = new ReturnModel
{
ProductIds = productIds
};

return searchResults;

}
}
}
}
12 changes: 12 additions & 0 deletions Development Project/Sparcpoint.Api/Models/CategoriesModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Sparcpoint.API.Models
{
public class CategoriesModel
{
public int Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public DateTime CreatedDate { get; set; }
}
}
22 changes: 22 additions & 0 deletions Development Project/Sparcpoint.Api/Models/ProductModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Sparcpoint.API.Models
{
public class ProductModel
{
public int Id { get; set; }
public required string Name { get; set; }
public required string Description { get; set; }
public required string ProductImageUris { get; set; }
public required string ValidSkus { get; set; }
public DateTime CreatedTimestamp { get; set; }
}

public class ProductAttributesModel
{
public int InstanceId { get; set; }
public int Key { get; set; }
public string? Value { get; set; }
}

}
22 changes: 22 additions & 0 deletions Development Project/Sparcpoint.Api/Models/SearchModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sparcpoint.API.Models
{
public class SearchModel
{
public int Id { get; set; }
public string? Query { get; set; }
public string? Name { get; set; }
public string? Category { get; set; }
public DateTime? CreatedTimestamp { get; set; }
}

public class ReturnModel
{
public List<int>? ProductIds { get; set; }
}
}
14 changes: 14 additions & 0 deletions Development Project/Sparcpoint.Api/Sparcpoint.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.72" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.1" />
</ItemGroup>

</Project>