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;
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

@ -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,6 +114,10 @@ namespace ImplementerApp
{
return _productLogic.Create(model);
}
public bool CheckProductName(string name)
{
return _productLogic.ReadElement(new() { Name = name }) == null;
}
public List<ProductionViewModel>? GetProductions(int userId)
{
@ -131,6 +139,10 @@ namespace ImplementerApp
{
return _productionLogic.Delete(new() { Id = productionId});
}
public bool CheckProductionName(string name)
{
return _productionLogic.ReadElement(new() { Name = name }) == null;
}
public List<MachineViewModel>? GetMachines()
{

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) {