diff --git a/ComputerStoreEmployeeApp/ComputerStoreEmployeeApp.csproj b/ComputerStoreEmployeeApp/ComputerStoreEmployeeApp.csproj index b74e4fc..4a6b9cd 100644 --- a/ComputerStoreEmployeeApp/ComputerStoreEmployeeApp.csproj +++ b/ComputerStoreEmployeeApp/ComputerStoreEmployeeApp.csproj @@ -7,6 +7,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ComputerStoreEmployeeApp/Controllers/HomeController.cs b/ComputerStoreEmployeeApp/Controllers/HomeController.cs index f734009..54818da 100644 --- a/ComputerStoreEmployeeApp/Controllers/HomeController.cs +++ b/ComputerStoreEmployeeApp/Controllers/HomeController.cs @@ -3,35 +3,33 @@ using ComputerStoreContracts.BindingModels; using ComputerStoreContracts.ViewModels; using ComputerStoreDataModels.Models; using ComputerStoreEmployeeApp.Models; -using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Mvc; using System.Data; using System.Diagnostics; -using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute; namespace ComputerStoreEmployeeApp.Controllers { public class HomeController : Controller { - private readonly ILogger _logger; + private readonly ILogger _logger; public HomeController(ILogger logger) - { - _logger = logger; + { + _logger = logger; } public IActionResult Index() { - if(APIClient.Employee == null) { return Redirect("Home/Enter"); } + if (APIClient.Employee == null) { return Redirect("Home/Enter"); } return View(); } - + public IActionResult ComponentMenu() { return View(); } - + public IActionResult ComponentAdd() { return View(); @@ -47,7 +45,7 @@ namespace ComputerStoreEmployeeApp.Controllers throw new Exception("Enter component's name and price."); } - if(!Task.Run(() => APIClient.PostRequest("api/main/insertcomponent", new ComponentBindingModel + if (!Task.Run(() => APIClient.PostRequest("api/main/insertcomponent", new ComponentBindingModel { Name = componentname, Price = componentprice @@ -80,9 +78,9 @@ namespace ComputerStoreEmployeeApp.Controllers if (string.IsNullOrEmpty(componentname) && !componentprice.HasValue) { throw new Exception("Enter at least one field."); - } + } - if(string.IsNullOrEmpty(componentname)) + if (string.IsNullOrEmpty(componentname)) { Task.Run(() => APIClient.PatchRequest("api/main/updatecomponent", new ComponentBindingModel { @@ -108,7 +106,7 @@ namespace ComputerStoreEmployeeApp.Controllers Price = componentprice.Value })); } - + } catch (Exception ex) @@ -131,7 +129,7 @@ namespace ComputerStoreEmployeeApp.Controllers public IActionResult ComponentDelete(int component) { try - { + { Task.Run(() => APIClient.DeleteRequest($"api/main/deletecomponent/{component}")); } catch (Exception ex) @@ -145,8 +143,8 @@ namespace ComputerStoreEmployeeApp.Controllers [HttpGet] public IActionResult ComponentCheck() - { - return View( APIClient.GetRequest>("api/main/getcomponentslist").Result); + { + return View(APIClient.GetRequest>("api/main/getcomponentslist").Result); } [HttpGet] @@ -158,7 +156,7 @@ namespace ComputerStoreEmployeeApp.Controllers [HttpGet] public IActionResult ProductAdd() - { + { ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentslist").Result; return View(APIClient.productComponents); } @@ -200,31 +198,31 @@ namespace ComputerStoreEmployeeApp.Controllers [HttpPost] public double ProductComponents(int id, int componentquantity) - { + { var component = APIClient.GetRequest($"api/main/getcomponent?id={id}").Result; - if(APIClient.productComponents.ContainsKey(component.ID)) + if (APIClient.productComponents.ContainsKey(component.ID)) { APIClient.productComponents[component.ID] = (component, componentquantity); } else { APIClient.productComponents.Add(component.ID, (component, componentquantity)); - } + } return APIClient.productComponents.Sum(x => x.Value.Component.Price * x.Value.Quantity); } - + [HttpGet("/Home/ProductUpdate/{id}")] - public IActionResult ProductUpdate(int? id,bool selectChange = false) - { + public IActionResult ProductUpdate(int? id, bool selectChange = false) + { ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentslist").Result; var list = APIClient.GetRequest>("api/main/getproductslist").Result; - ViewBag.Products = list; + ViewBag.Products = list; if (!id.HasValue) - { + { var product = list.First(); APIClient.productComponents = product.ProductComponents; ViewBag.Price = product.Price; @@ -235,7 +233,7 @@ namespace ComputerStoreEmployeeApp.Controllers ViewBag.ID = id; if (selectChange) - { + { var specproduct = list.First(x => x.ID == id); APIClient.productComponents = specproduct.ProductComponents; ViewBag.Price = specproduct.Price; @@ -248,7 +246,7 @@ namespace ComputerStoreEmployeeApp.Controllers } [HttpPost] - public IActionResult ProductUpdate(int id, double productprice,string? productname) + public IActionResult ProductUpdate(int id, double productprice, string? productname) { try { @@ -259,7 +257,7 @@ namespace ComputerStoreEmployeeApp.Controllers Price = productprice, EmployeeID = APIClient.Employee.ID, ProductComponents = APIClient.productComponents.Where(component => component.Value.Quantity != 0).ToDictionary(x => x.Key, x => (x.Value.Component as IComponentModel, x.Value.Quantity)) - + })).Result) { throw new InvalidOperationException("Something went wrong."); @@ -277,7 +275,7 @@ namespace ComputerStoreEmployeeApp.Controllers return Redirect("ProductMenu"); } - + [HttpGet] public IActionResult ProductDelete() @@ -308,6 +306,198 @@ namespace ComputerStoreEmployeeApp.Controllers return View(APIClient.GetRequest>("api/main/getproductslist").Result); } + + + [HttpGet] + public IActionResult PCMenu() + { + APIClient.pcComponents = new Dictionary(); + return View(); + } + + [HttpGet] + public IActionResult PCAdd(int? request) + { + ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentslist").Result; + ViewBag.Requests = APIClient.GetRequest>($"api/main/getrequestlist?id={null}").Result; + ViewBag.PCComponents = APIClient.pcComponents; + if(request == null) + { + ViewBag.ID = ViewBag.Requests[0].ID; + } + else + { + ViewBag.ID = request; + } + + return View(Requests(request)); + } + + public List Requests(int? id) + { + if (id == null) + { + var wholelist = APIClient.GetRequest>($"api/main/getrequestcomponentlist?id={null}").Result; + + ViewBag.Requests = APIClient.GetRequest>($"api/main/getrequestlist?id={null}").Result; + + var componentsList = wholelist.Where(x => x.RequestID == ViewBag.Requests[0].ID).Select(x => new RequestComponentViewModel { ComponentName = x.ComponentName, ComponentCount = x.ComponentCount }).ToList(); + + return componentsList; + + } + + var speclist = APIClient.GetRequest>($"api/main/getrequestcomponentlist?id={id}").Result; + + var specificcomponentList = speclist.Where(x => x.RequestID == id).Select(x => new RequestComponentViewModel { ComponentName = x.ComponentName, ComponentCount = x.ComponentCount }).ToList(); + return specificcomponentList; + } + + [HttpPost] + public IActionResult PCAdd(string pcname, double pcprice, int request) + { + try + { + if (string.IsNullOrEmpty(pcname) || string.IsNullOrEmpty(pcprice.ToString())) + { + throw new Exception("Enter pc's name or pc doesn't have any components."); + } + + if (APIClient.PostRequest("api/main/insertpc",new PCBindingModel + { + Name = pcname, + Price = pcprice, + EmployeeID = APIClient.Employee.ID, + RequestID = request, + PCComponents = APIClient.pcComponents + }).Result) + { + throw new InvalidOperationException("PC with such name already exists"); + } + + } + catch (Exception ex) + { + APIClient.pcComponents.Clear(); + ViewBag.Message = new string(ex.Message.ToString()); + ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentslist").Result; + ViewBag.Requests = APIClient.GetRequest>($"api/main/getrequestlist?id={null}").Result; + ViewBag.PCComponents = APIClient.pcComponents; + return View(Requests(request)); + } + + APIClient.pcComponents.Clear(); + return Redirect("PCMenu"); + } + + + [HttpPost] + public double PCComponents(int id, int componentquantity) + { + var component = APIClient.GetRequest($"api/main/getcomponent?id={id}").Result; + if (APIClient.pcComponents.ContainsKey(component.ID)) + { + APIClient.pcComponents[component.ID] = (component, componentquantity); + } + else + { + APIClient.pcComponents.Add(component.ID, (component, componentquantity)); + } + return APIClient.pcComponents.Sum(x => x.Value.Component.Price * x.Value.Quantity); + } + + [HttpGet("/Home/PCUpdate/{id}")] + public IActionResult PCUpdate(int? id, bool selectChange = false) + { + + ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentslist").Result; + var list = APIClient.GetRequest>("api/main/getpcslist").Result; + ViewBag.PCs = list; + + if (!id.HasValue) + { + var pc = list.First(); + APIClient.pcComponents = pc.PCComponents; + ViewBag.Price = pc.Price; + return View(APIClient.pcComponents); + } + + + ViewBag.ID = id; + + if (selectChange) + { + var specpc = list.First(x => x.ID == id); + APIClient.pcComponents = specpc.PCComponents; + ViewBag.Price = specpc.Price; + return View(specpc.PCComponents); + } + + ViewBag.Price = APIClient.pcComponents.Sum(x => x.Value.Component.Price * x.Value.Quantity); + + return View(APIClient.pcComponents); + } + + [HttpPost] + public IActionResult PCUpdate(int id, double pcprice, string? pcname) + { + try + { + if (!Task.Run(() => APIClient.PatchRequest("api/main/updatepc", new PCBindingModel + { + ID = id, + Name = pcname, + Price = pcprice, + EmployeeID = APIClient.Employee.ID, + PCComponents = APIClient.pcComponents.Where(component => component.Value.Quantity != 0).ToDictionary(x => x.Key, x => (x.Value.Component as IComponentModel, x.Value.Quantity)) + + })).Result) + { + throw new InvalidOperationException("Something went wrong."); + } + } + catch (Exception ex) + { + APIClient.pcComponents.Clear(); + ViewBag.Message = new string(ex.Message.ToString()); + ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentslist").Result; + return View(APIClient.pcComponents); + } + + APIClient.pcComponents.Clear(); + + return Redirect("PCMenu"); + } + + [HttpGet] + public IActionResult PCDelete() + { + ViewBag.PCs = APIClient.GetRequest>("api/main/getpcslist").Result; + return View(); + } + + [HttpPost] + public IActionResult PCDelete(int pc) + { + try + { + Task.Run(() => APIClient.DeleteRequest($"api/main/deletepc/{pc}")); + } + catch (Exception ex) + { + ViewBag.Message = new string(ex.Message.ToString()); + return View(); + } + + return Redirect("PCMenu"); + } + + [HttpGet] + public IActionResult PCCheck() + { + return View(APIClient.GetRequest>("api/main/getpcslist").Result); + } + [HttpGet] public IActionResult Register() { diff --git a/ComputerStoreEmployeeApp/Views/Home/PCAdd.cshtml b/ComputerStoreEmployeeApp/Views/Home/PCAdd.cshtml new file mode 100644 index 0000000..ea407d4 --- /dev/null +++ b/ComputerStoreEmployeeApp/Views/Home/PCAdd.cshtml @@ -0,0 +1,130 @@ +@using ComputerStoreDataModels.Models +@using ComputerStoreContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Add a PC"; +} +
+

Add a PC

+
+
+
+
+

Component:

+ +
Quantity:
+ + +
+
+ + + + + + + + + + @foreach ((IComponentModel,int) item in ViewBag.PCComponents.Values) + { + + + + + + } + +
+ Name + + Count +
+ @Html.DisplayFor(modelItem => item.Item1.Name) + + @Html.DisplayFor(modelItem => item.Item2) +
+
+
+

PC:

+
Name:
+ +
Price:
+ + +
+
+
+ + + + + + + + + + @if (Model != null) + { + foreach (var item in Model) + { + + + + + } + } + +
+ Component + + Count +
+ @Html.DisplayFor(modelItem => item.ComponentName) + + @Html.DisplayFor(modelItem => item.ComponentCount) +
+
+ @if (!string.IsNullOrEmpty(ViewBag.Message)) + { + + } +
+ \ No newline at end of file diff --git a/ComputerStoreEmployeeApp/Views/Home/PCCheck.cshtml b/ComputerStoreEmployeeApp/Views/Home/PCCheck.cshtml new file mode 100644 index 0000000..787686f --- /dev/null +++ b/ComputerStoreEmployeeApp/Views/Home/PCCheck.cshtml @@ -0,0 +1,56 @@ +@using ComputerStoreContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Storage"; +} +
+

Storage

+
+ +
+ @{ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Name + + Price + + Employee username + + Components +
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Price) + + @Html.DisplayFor(modelItem => item.EmployeeUsername) + + + @foreach (var component in item.PCComponents) + { + + + } +
@component.Value.Component.Name
+
+ } +
\ No newline at end of file diff --git a/ComputerStoreEmployeeApp/Views/Home/PCDelete.cshtml b/ComputerStoreEmployeeApp/Views/Home/PCDelete.cshtml new file mode 100644 index 0000000..17a26a8 --- /dev/null +++ b/ComputerStoreEmployeeApp/Views/Home/PCDelete.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "Delete a product"; +} +
+

Delete a product

+
+
+
+
+ + +
+
+ @if (!string.IsNullOrEmpty(ViewBag.Message)) + { + + } +
\ No newline at end of file diff --git a/ComputerStoreEmployeeApp/Views/Home/PCMenu.cshtml b/ComputerStoreEmployeeApp/Views/Home/PCMenu.cshtml new file mode 100644 index 0000000..5c498dc --- /dev/null +++ b/ComputerStoreEmployeeApp/Views/Home/PCMenu.cshtml @@ -0,0 +1,32 @@ +@{ + ViewData["Title"] = "PCs"; +} +
+ +
+
+

What do you want to do with pcs?

+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
diff --git a/ComputerStoreEmployeeApp/Views/Home/PCRequest.cshtml b/ComputerStoreEmployeeApp/Views/Home/PCRequest.cshtml new file mode 100644 index 0000000..0646cf3 --- /dev/null +++ b/ComputerStoreEmployeeApp/Views/Home/PCRequest.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "Choose a request"; +} +
+

Choose a request

+
+
+
+
+ + +
+
+ @if (!string.IsNullOrEmpty(ViewBag.Message)) + { + + } +
\ No newline at end of file diff --git a/ComputerStoreEmployeeApp/Views/Home/PCUpdate.cshtml b/ComputerStoreEmployeeApp/Views/Home/PCUpdate.cshtml new file mode 100644 index 0000000..2254b1f --- /dev/null +++ b/ComputerStoreEmployeeApp/Views/Home/PCUpdate.cshtml @@ -0,0 +1,96 @@ +@using ComputerStoreDataModels.Models; +@model Dictionary +@{ + ViewData["Title"] = "Update a PC"; +} +
+

Update a PC

+
+
+
+
+

Component:

+ +
Quantity:
+ + +
+
+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Name + + Count +
+ @Html.DisplayFor(modelItem => item.Value.Item1.Name) + + @Html.DisplayFor(modelItem => item.Value.Item2) +
+
+
+

PC:

+ +
Name:
+ +
Price:
+ + +
+
+ @if (!string.IsNullOrEmpty(ViewBag.Message)) + { + + } +
+ diff --git a/ComputerStoreEmployeeApp/Views/Home/ProductUpdate.cshtml b/ComputerStoreEmployeeApp/Views/Home/ProductUpdate.cshtml index 1926e05..17db7d4 100644 --- a/ComputerStoreEmployeeApp/Views/Home/ProductUpdate.cshtml +++ b/ComputerStoreEmployeeApp/Views/Home/ProductUpdate.cshtml @@ -13,7 +13,7 @@
Quantity:
- +
@@ -51,7 +51,7 @@
Price:
- + @if (!string.IsNullOrEmpty(ViewBag.Message)) diff --git a/ComputerStoreEmployeeApp/Views/Shared/Requests.cshtml b/ComputerStoreEmployeeApp/Views/Shared/Requests.cshtml new file mode 100644 index 0000000..e16cc4c --- /dev/null +++ b/ComputerStoreEmployeeApp/Views/Shared/Requests.cshtml @@ -0,0 +1,32 @@ +@using ComputerStoreContracts.ViewModels +@model List + + +
+ + + + + + + + @if(Model != null) + { + foreach (var item in Model) + { + + + + + } + } + +
+ Component + + Count +
+ @Html.DisplayFor(modelItem => item.ComponentName) + + @Html.DisplayFor(modelItem => item.ComponentCount) +
\ No newline at end of file diff --git a/ComputerStoreEmployeeApp/Views/Shared/_Layout.cshtml b/ComputerStoreEmployeeApp/Views/Shared/_Layout.cshtml index b7ea863..f35c507 100644 --- a/ComputerStoreEmployeeApp/Views/Shared/_Layout.cshtml +++ b/ComputerStoreEmployeeApp/Views/Shared/_Layout.cshtml @@ -33,7 +33,7 @@ Products