Guarantor: basic frontend views + logic fixes.

This commit is contained in:
2023-05-13 18:23:36 +04:00
parent a55b6c91ea
commit e5eec7f4ca
97 changed files with 74918 additions and 36 deletions

View File

@@ -0,0 +1,201 @@
using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.ViewModels;
using ComputerStoreEmployeeApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.Data;
using System.Diagnostics;
namespace ComputerStoreEmployeeApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
if(APIClient.Employee == null) { return Redirect("Home/Enter"); }
return View();
}
[HttpGet]
public IActionResult ComponentMenu()
{
return View();
}
[HttpGet]
public IActionResult ComponentAdd()
{
return View();
}
[HttpPost]
public IActionResult ComponentAdd(string componentname, double componentprice)
{
try
{
if (string.IsNullOrEmpty(componentname) || string.IsNullOrEmpty(componentprice.ToString()))
{
throw new Exception("Enter component's name and price.");
}
Task.Run(() => APIClient.PostRequest("api/main/insertcomponent", new ComponentBindingModel
{
Name = componentname,
Price = componentprice
}));
}
catch (Exception ex)
{
ViewBag.Message = new string(ex.Message.ToString());
return View();
}
return Redirect("ComponentMenu");
}
[HttpGet]
public IActionResult ComponentUpdate()
{
return View();
}
[HttpPost]
public void ComponentUpdate(string val)
{
}
[HttpGet]
public IActionResult ComponentDelete()
{
return View();
}
[HttpPost]
public void ComponentDelete(string val)
{
}
[HttpGet]
public IActionResult ProductMenu()
{
return View();
}
[HttpGet]
public IActionResult ProductAdd()
{
return View();
}
[HttpPost]
public void ProductAdd(string val)
{
}
[HttpGet]
public IActionResult ProductUpdate()
{
return View();
}
[HttpPost]
public void ProductUpdate(string val)
{
}
[HttpGet]
public IActionResult ProductDelete()
{
return View();
}
[HttpPost]
public void ProductDelete(string val)
{
}
[HttpGet]
public IActionResult Register()
{
ViewBag.ShowTopBar = false;
return View();
}
[HttpPost]
public IActionResult Register(string username, string password, string? firstname, string? middlename,string? lastname)
{
try
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
throw new Exception("Enter login and password.");
}
Task.Run(() => APIClient.PostRequest("api/employee/register", new EmployeeBindingModel
{
Username = username,
Password = password,
FirstName = firstname != null ? firstname : null,
MiddleName = middlename != null ? middlename : null,
LastName = lastname != null ? lastname : null
}));
}
catch (Exception ex)
{
ViewBag.Message = new string(ex.Message.ToString());
ViewBag.ShowTopBar = false;
return View();
}
return Redirect("Enter");
}
[HttpGet]
public IActionResult Enter()
{
ViewBag.ShowTopBar = false;
return View();
}
[HttpPost]
public IActionResult Enter(string login, string password)
{
try
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Enter login and password"); }
APIClient.Employee = APIClient.GetRequest<EmployeeViewModel>($"api/employee/login?login={login}&password={password}").Result;
if (APIClient.Employee == null) { throw new Exception("Incorrect login/password"); }
}
catch (Exception ex)
{
ViewBag.Message = new string(ex.Message.ToString());
ViewBag.ShowTopBar = false;
return View();
}
return Redirect("Index");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}