Frontend component views + api logic fixes.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreEmployeeApp.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
@@ -22,13 +23,12 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
||||
public IActionResult ComponentMenu()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
||||
public IActionResult ComponentAdd()
|
||||
{
|
||||
return View();
|
||||
@@ -44,11 +44,14 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
throw new Exception("Enter component's name and price.");
|
||||
}
|
||||
|
||||
Task.Run(() => APIClient.PostRequest("api/main/insertcomponent", new ComponentBindingModel
|
||||
if(!Task.Run(() => APIClient.PostRequest("api/main/insertcomponent", new ComponentBindingModel
|
||||
{
|
||||
Name = componentname,
|
||||
Price = componentprice
|
||||
}));
|
||||
})).Result)
|
||||
{
|
||||
throw new InvalidOperationException("Component with such name already exists");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -62,25 +65,85 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult ComponentUpdate()
|
||||
{
|
||||
ViewBag.Components = Task.Run(() => APIClient.GetRequest<List<ComponentViewModel>>("api/main/getcomponentslist")).Result;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ComponentUpdate(string val)
|
||||
public IActionResult ComponentUpdate(int component, string? componentname, double? componentprice)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(componentname) && !componentprice.HasValue)
|
||||
{
|
||||
throw new Exception("Enter at least one field.");
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(componentname))
|
||||
{
|
||||
Task.Run(() => APIClient.PatchRequest("api/main/updatecomponent", new ComponentBindingModel
|
||||
{
|
||||
ID = component,
|
||||
Price = componentprice.Value
|
||||
}));
|
||||
}
|
||||
|
||||
else if (!componentprice.HasValue)
|
||||
{
|
||||
Task.Run(() => APIClient.PatchRequest("api/main/updatecomponent", new ComponentBindingModel
|
||||
{
|
||||
ID = component,
|
||||
Name = componentname
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run(() => APIClient.PatchRequest("api/main/updatecomponent", new ComponentBindingModel
|
||||
{
|
||||
ID = component,
|
||||
Name = componentname,
|
||||
Price = componentprice.Value
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ViewBag.Message = new string(ex.Message.ToString());
|
||||
return View();
|
||||
}
|
||||
|
||||
return Redirect("ComponentMenu");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ComponentDelete()
|
||||
{
|
||||
ViewBag.Components = Task.Run(() => APIClient.GetRequest<List<ComponentViewModel>>("api/main/getcomponentslist")).Result;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ComponentDelete(string val)
|
||||
public IActionResult ComponentDelete(int component)
|
||||
{
|
||||
try
|
||||
{
|
||||
Task.Run(() => APIClient.DeleteRequest<string>($"api/main/deletecomponent/{component}"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ViewBag.Message = new string(ex.Message.ToString());
|
||||
return View();
|
||||
}
|
||||
|
||||
return Redirect("ComponentMenu");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ComponentCheck()
|
||||
{
|
||||
return View(Task.Run(() => APIClient.GetRequest<List<ComponentViewModel>>("api/main/getcomponentslist")).Result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
||||
Reference in New Issue
Block a user