-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrates supplier service into two seperate services - product servic…
- Loading branch information
Nathan Parnell
committed
Oct 23, 2023
1 parent
96086ce
commit 0c5f8b9
Showing
11 changed files
with
446 additions
and
23 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
StockTrackerApp/Components/CustomerComponents/Home.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace StockTrackerApp.Components.CustomerComponents | ||
{ | ||
public partial class Home | ||
{ | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
StockTrackerApp/Services/Infrastructure/IProductCategoryService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using StockTrackerCommon.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace StockTrackerApp.Services.Infrastructure | ||
{ | ||
public interface IProductCategoryService | ||
{ | ||
#region "Get Methods" | ||
List<ProductCategory> GetProductCategoriesByProductCategoryIds(List<string> productCategoryIds); | ||
List<ProductCategory> GetAllProductCategories(); | ||
#endregion | ||
|
||
#region "Add Methods" | ||
bool AddProductCategory(ProductCategory productCategory); | ||
#endregion | ||
|
||
#region "Validation Methods" | ||
string ValidateAndAddProductCategory(ProductCategory productCategory, List<ProductCategory> existingProductCategories); | ||
#endregion | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
StockTrackerApp/Services/Infrastructure/IProductService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using StockTrackerCommon.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace StockTrackerApp.Services.Infrastructure | ||
{ | ||
public interface IProductService | ||
{ | ||
#region "Get Methods" | ||
List<Product> GetProductBySupplierId(string supplierId); | ||
Product GetProductByProductId(string productId); | ||
List<Product> GetProductsByProductIds(List<string> productIds); | ||
List<Product> GetAllProducts(); | ||
#endregion | ||
|
||
#region "Add Methods" | ||
bool AddProduct(Product product); | ||
#endregion | ||
|
||
#region "Update Methods" | ||
bool UpdateProduct(Product updatedProduct); | ||
#endregion | ||
|
||
#region "Delete Methods" | ||
bool DeleteProductByProductID(string productId); | ||
#endregion | ||
|
||
#region "Validation Methods" | ||
string ValidateAndAddProduct(Product newProduct, List<Product> existingProducts, List<ProductCategory> productCategories, ref bool success); | ||
string ValidateAndUpdateProduct(Product updatedProduct, List<Product> suppliersExistingProducts, List<ProductCategory> productCategories, ref bool success); | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using StockTrackerCommon.Helpers; | ||
using StockTrackerCommon.Models; | ||
using StockTrackerApp.Services.Infrastructure; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace StockTrackerApp.Services | ||
{ | ||
public class ProductCategoryService : IProductCategoryService | ||
{ | ||
//setup logger | ||
private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(ProductService)); | ||
|
||
//define services | ||
private readonly IClientTransportService _clientTransportService; | ||
|
||
public ProductCategoryService(IClientTransportService clientTransportService) | ||
{ | ||
_clientTransportService = clientTransportService; | ||
} | ||
|
||
#region "Get Methods" | ||
public List<ProductCategory> GetProductCategoriesByProductCategoryIds(List<string> productCategoryIds) | ||
{ | ||
string jsonResponse = _clientTransportService.TcpHandler(RequestSerializingHelper.CreateGetProductCategoriesByProductCategoryIDsRequest(productCategoryIds)); | ||
|
||
//if the method we tried to call did not exist | ||
if (String.IsNullOrEmpty(jsonResponse)) | ||
return null; | ||
|
||
List<ProductCategory> productCategories = ResponseDeserializingHelper.DeserializeResponse<List<ProductCategory>>(jsonResponse).First().ToList(); | ||
return productCategories; | ||
} | ||
|
||
public List<ProductCategory> GetAllProductCategories() | ||
{ | ||
string jsonResponse = _clientTransportService.TcpHandler(RequestSerializingHelper.CreateGetAllProductCategoriesRequest()); | ||
|
||
//if the method we tried to call did not exist | ||
if (String.IsNullOrEmpty(jsonResponse)) | ||
return null; | ||
|
||
List<ProductCategory> productCategories = ResponseDeserializingHelper.DeserializeResponse<List<ProductCategory>>(jsonResponse).First().ToList(); | ||
return productCategories; | ||
} | ||
#endregion | ||
|
||
#region "Add Methods" | ||
public bool AddProductCategory(ProductCategory productCategory) | ||
{ | ||
string jsonResponse = _clientTransportService.TcpHandler(RequestSerializingHelper.CreateAddProductCategoryRequest(productCategory)); | ||
|
||
//if the method we tried to call did not exist | ||
if (String.IsNullOrEmpty(jsonResponse)) | ||
return false; | ||
|
||
bool addConfirmation = ResponseDeserializingHelper.DeserializeResponse<bool>(jsonResponse).First(); | ||
return addConfirmation; | ||
} | ||
#endregion | ||
|
||
#region "Validation Methods" | ||
public string ValidateAndAddProductCategory(ProductCategory productCategory, List<ProductCategory> existingProductCategories) | ||
{ | ||
bool isProductCategoryValid = true; | ||
string prompt = "Product Category invalid, please enter:\n"; | ||
|
||
if (String.IsNullOrEmpty(productCategory.ProductCategoryName) || existingProductCategories.Any(cat => cat.ProductCategoryName == productCategory.ProductCategoryName)) | ||
{ | ||
prompt += "A Unique Product Category Name"; | ||
isProductCategoryValid = false; | ||
} | ||
|
||
if (isProductCategoryValid == true) | ||
{ | ||
productCategory.ProductCategoryId = Taikandi.SequentialGuid.NewGuid().ToString(); | ||
if (AddProductCategory(productCategory)) | ||
return "Product Category Added Successfully"; | ||
else | ||
return "Error Adding Product Category"; | ||
} | ||
else | ||
{ | ||
return prompt; | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
Oops, something went wrong.