ControllersShiza

This commit is contained in:
Sergey Kozyrev 2024-05-28 22:40:13 +04:00
parent 6cd7e771fa
commit 17db7a656c
7 changed files with 53 additions and 14 deletions

View File

@ -17,7 +17,6 @@ namespace ImplementerApp.Controllers
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpGet]
public IActionResult IndexDetail()
{
@ -57,8 +56,13 @@ namespace ImplementerApp.Controllers
{
model.DateCreate = DateTime.Now;
model.UserId = UserImplementer.user!.Id;
if (_data.CreateDetail(model))
return RedirectToAction("IndexDetail");
try {
if (_data.CreateDetail(model))
return RedirectToAction("IndexDetail");
} catch (ArgumentException ex)
{
return RedirectToAction("Error", ex.Message);
}
}
else
{
@ -69,9 +73,9 @@ namespace ImplementerApp.Controllers
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
public IActionResult Error(string ex)
{
return View();
return View(ex);
}
}
}

View File

@ -22,7 +22,12 @@ namespace ImplementerApp.Controllers
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpPost]
public JsonResult CheckLogin(string login)
{
var unique = _data.CheckLogin(login);
return Json(new { isUnique = unique });
}
public IActionResult IndexNonReg()
{
if (!IsLoggedIn)

View File

@ -17,7 +17,7 @@ namespace ImplementerApp.Controllers
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpGet]
public IActionResult IndexProduct()
{

View File

@ -16,8 +16,6 @@ namespace ImplementerApp.Controllers
}
private bool IsLoggedIn { get { return UserImplementer.user != null; } }
private int UserId { get { return UserImplementer.user!.Id; } }
[HttpGet]
public IActionResult IndexProduction()
{

View File

@ -89,6 +89,10 @@ namespace ImplementerApp
{
return _detailLogic.ReadElement(new() { Id= id });
}
public bool CheckDetailName(string name)
{
return _detailLogic.ReadElement(new() { Name = name }) == null;
}
public List<ProductViewModel>? GetProducts(int userId)
{
@ -110,8 +114,12 @@ namespace ImplementerApp
{
return _productLogic.Create(model);
}
public bool CheckProductName(string name)
{
return _productLogic.ReadElement(new() { Name = name }) == null;
}
public List<ProductionViewModel>? GetProductions(int userId)
public List<ProductionViewModel>? GetProductions(int userId)
{
return _productionLogic.ReadList(new() { UserId = userId });
}
@ -130,9 +138,13 @@ namespace ImplementerApp
public bool DeleteProduction(int productionId)
{
return _productionLogic.Delete(new() { Id = productionId});
}
public List<MachineViewModel>? GetMachines()
}
public bool CheckProductionName(string name)
{
return _productionLogic.ReadElement(new() { Name = name }) == null;
}
public List<MachineViewModel>? GetMachines()
{
return _machineLogic.ReadList(null);
}

View File

@ -43,6 +43,26 @@
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
$('#login').blur(function () {
var login = $('#login').val();
if (login.length >= 5 && login.length <= 50) {
$.ajax({
url: '@Url.Action("CheckLogin", "Home")',
type: 'POST',
data: { login: login },
success: function (response) {
if (!response.isUnique) {
$('#loginError').text('Логин уже используется.');
} else {
$('#loginError').text('');
}
},
error: function () {
$('#loginError').text('Ошибка при проверке уникальности логина.');
}
});
}
});
$('#clientForm').submit(function(event) {
var login = $('#login').val();
var email = $('#email').val();

View File

@ -54,7 +54,7 @@
var login = $('#login').val();
if (login.length >= 5 && login.length <= 50) {
$.ajax({
url: '@Url.Action("CheckLoginUnique", "YourController")',
url: '@Url.Action("CheckLogin", "Home")',
type: 'POST',
data: { login: login },
success: function (response) {