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

View File

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

View File

@ -89,6 +89,10 @@ namespace ImplementerApp
{ {
return _detailLogic.ReadElement(new() { Id= id }); return _detailLogic.ReadElement(new() { Id= id });
} }
public bool CheckDetailName(string name)
{
return _detailLogic.ReadElement(new() { Name = name }) == null;
}
public List<ProductViewModel>? GetProducts(int userId) public List<ProductViewModel>? GetProducts(int userId)
{ {
@ -110,8 +114,12 @@ namespace ImplementerApp
{ {
return _productLogic.Create(model); 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 }); return _productionLogic.ReadList(new() { UserId = userId });
} }
@ -131,8 +139,12 @@ namespace ImplementerApp
{ {
return _productionLogic.Delete(new() { Id = productionId}); return _productionLogic.Delete(new() { Id = productionId});
} }
public bool CheckProductionName(string name)
{
return _productionLogic.ReadElement(new() { Name = name }) == null;
}
public List<MachineViewModel>? GetMachines() public List<MachineViewModel>? GetMachines()
{ {
return _machineLogic.ReadList(null); return _machineLogic.ReadList(null);
} }

View File

@ -43,6 +43,26 @@
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script> <script>
$(document).ready(function () { $(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) { $('#clientForm').submit(function(event) {
var login = $('#login').val(); var login = $('#login').val();
var email = $('#email').val(); var email = $('#email').val();

View File

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