just end?

This commit is contained in:
Дмитрий Блохин 2024-05-29 17:12:33 +04:00
parent 588f856ce8
commit 80f3f77d0d
9 changed files with 390 additions and 183 deletions

View File

@ -23,7 +23,10 @@ namespace DatabaseImplement.Implements
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login)) { return null; }
using var context = new FactoryGoWorkDatabase();
return context.Guarantors.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password) && x.Login.Equals(model.Login) && x.Password.Equals(model.Password)))?.GetViewModel; ;
if (!string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))
return context.Guarantors.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel;
else
return context.Guarantors.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password) && x.Login.Equals(model.Login) && x.Password.Equals(model.Password)))?.GetViewModel;
}
public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model)

View File

@ -34,7 +34,7 @@ namespace DatabaseImplement.Models
public virtual List<DetailProduction> Details { get; set; } = new();
public virtual Implementer User { get; set; }
[ForeignKey("ProductionId")]
public virtual List<Workshop> Workshops { get; set; }
public virtual List<Workshop> Workshops { get; set; } = new();
public static Production Create(FactoryGoWorkDatabase context, ProductionBindingModel model)
{

View File

@ -1,6 +1,7 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicsContracts;
using Contracts.ViewModels;
using DocumentFormat.OpenXml.Packaging;
using GuarantorAPP.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
@ -19,6 +20,22 @@ namespace GuarantorAPP.Controllers
}
private bool IsLoggedIn { get { return UserGuarantor.user != null; } }
private int UserId { get { return UserGuarantor.user!.Id; } }
[HttpPost]
public JsonResult CheckLogin(string login)
{
try
{
var unique = _data.CheckLogin(login);
return Json(new
{
isUnique = unique
});
}
catch (Exception)
{
return Json(new {isUnique = false});
}
}
public IActionResult IndexNonReg()
{
if (!IsLoggedIn)
@ -40,6 +57,8 @@ namespace GuarantorAPP.Controllers
}
[HttpPost]
public void Enter(string login, string password)
{
try
{
var user = _data.Login(login, password);
if (user != null)
@ -47,6 +66,11 @@ namespace GuarantorAPP.Controllers
UserGuarantor.user = user;
Response.Redirect("Index");
}
Response.Redirect("Enter");
} catch (Exception)
{
Response.Redirect("IndexNonReg");
}
}
[HttpGet]
public IActionResult Register()
@ -60,30 +84,50 @@ namespace GuarantorAPP.Controllers
}
[HttpPost]
public void Register(string name, string login, string email, string password1, string password2)
{
try
{
if (password1 == password2 && _data.Register(new() { Email = email, Login = login, Name = name, Password = password1 }))
{
Response.Redirect("Index");
}
} catch (Exception)
{
Response.Redirect("IndexNonReg");
}
}
[HttpGet]
public IActionResult IndexMachine()
{
if (UserGuarantor.user != null)
{
var machines = _data.GetMachines(UserGuarantor.user.Id);
return View(machines);
}
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var machines = _data.GetMachines(UserGuarantor.user!.Id);
return View(machines);
} catch
{
return RedirectToAction("IndexNonReg");
}
}
[HttpPost]
public IActionResult IndexMachine(int id)
{
try
{
_data.DeleteMachine(id);
return RedirectToAction("IndexMachine");
} catch
{
return RedirectToAction("IndexNonReg");
}
}
[HttpGet]
public IActionResult CreateMachine(int id)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var workers = _data.GetWorkers(UserGuarantor.user!.Id);
ViewBag.AllWorkers = workers;
@ -93,10 +137,17 @@ namespace GuarantorAPP.Controllers
if (value != null)
return View(value);
}
}
catch
{
return RedirectToAction("IndexMachine");
}
return View(new MachineViewModel());
}
[HttpPost]
public IActionResult CreateMachine(int id, string title, string country, int[] workerIds)
{
try
{
MachineBindingModel model = new MachineBindingModel();
model.Id = id;
@ -129,23 +180,31 @@ namespace GuarantorAPP.Controllers
ViewBag.AllWorkers = workers;
return View(model);
}
} catch
{
return RedirectToAction("IndexMachine");
}
}
[HttpGet]
public IActionResult IndexWorker()
{
if (UserGuarantor.user != null)
{
var list = _data.GetWorkers(UserGuarantor.user.Id);
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try {
var list = _data.GetWorkers(UserGuarantor.user!.Id);
if (list != null)
return View(list);
return View(new List<WorkerViewModel>());
}
return RedirectToAction("IndexNonReg");
catch (Exception)
{
return View(new List<WorkerViewModel>()); ;
}
return View(new List<WorkerViewModel>());
}
[HttpPost]
public void IndexWorker(int id)
{
if (UserGuarantor.user != null)
if (IsLoggedIn)
{
_data.DeleteWorker(id);
}
@ -154,6 +213,10 @@ namespace GuarantorAPP.Controllers
[HttpGet]
public IActionResult CreateWorker(int id)
{
if (!IsLoggedIn)
{
return RedirectToAction("IndexNonReg");
}
if (id != 0)
{
var value = _data.GetWorker(id);
@ -164,10 +227,12 @@ namespace GuarantorAPP.Controllers
}
[HttpPost]
public IActionResult CreateWorker(WorkerBindingModel model)
{
try
{
if (model.Id == 0)
{
model.UserId = UserGuarantor.user!.Id;
model.UserId = UserId;
if (_data.CreateWorker(model))
return RedirectToAction("IndexWorker");
}
@ -176,26 +241,45 @@ namespace GuarantorAPP.Controllers
if (_data.UpdateWorker(model))
return RedirectToAction("IndexWorker");
}
return View();
}
catch (Exception)
{
return RedirectToAction("IndexWorker");
}
return RedirectToAction("IndexWorker");
}
[HttpGet]
public IActionResult IndexWorkshop()
{
if (IsLoggedIn)
{
try
{
var workshops = _data.GetWorkshops(UserGuarantor.user!.Id);
return View(workshops);
} catch (Exception)
{
return RedirectToAction("IndexNonReg");
}
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult IndexWorkshop(int id)
{
try
{
_data.DeleteWorkshop(id);
}
catch (Exception) { }
return RedirectToAction("IndexWorkshop");
}
[HttpGet]
public IActionResult CreateWorkshop(int id)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var workers = _data.GetWorkers(UserGuarantor.user!.Id);
ViewBag.AllWorkers = workers;
@ -205,10 +289,14 @@ namespace GuarantorAPP.Controllers
if (value != null)
return View(value);
}
}
catch (Exception) { }
return View(new WorkshopViewModel());
}
[HttpPost]
public IActionResult CreateWorkshop(int id, string title, string address, string director, int[] workerIds)
{
try
{
WorkshopBindingModel model = new WorkshopBindingModel();
model.Id = id;
@ -223,25 +311,22 @@ namespace GuarantorAPP.Controllers
var worker = workers!.FirstOrDefault(x => x.Id == workerIds[i])!;
model.WorkshopWorker[workerIds[i]] = (worker);
}
bool changed = false;
if (model.WorkshopWorker.Count > 0)
{
if (model.WorkshopWorker.Count == 0)
return RedirectToAction("IndexWorkshop");
if (id != 0)
{
changed = _data.UpdateWorkshop(model);
_data.UpdateWorkshop(model);
}
else
{
changed = _data.CreateWorkshop(model);
_data.CreateWorkshop(model);
}
} catch (InvalidOperationException ex)
{
ViewBag.ErrorMessage = "Такое название Цеха уже сущетсвует";
return View();
}
if (changed)
return RedirectToAction("IndexWorkshop");
else
{
ViewBag.AllWorkers = workers;
return View(model);
}
}
[HttpGet]
public IActionResult Privacy()
@ -255,12 +340,18 @@ namespace GuarantorAPP.Controllers
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
GuarantorBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name };
if (_data.UpdateUser(user))
{
UserGuarantor.user = new GuarantorViewModel { Id = id, Login = login, Password = password, Name = name, Email = email };
}
return View(user);
} catch (Exception)
{
return RedirectToAction("IndexNonReg");
}
}
[HttpGet]
public IActionResult MachineWorkshopTimeChoose()
@ -270,21 +361,18 @@ namespace GuarantorAPP.Controllers
return View();
}
[HttpPost]
public IActionResult SendReport(DateTime startDate, DateTime endDate)
{
return Ok();
}
[HttpPost]
public IActionResult TimeReportWeb(DateTime startDate, DateTime endDate)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
HttpContext.Session.SetString("StartDate", startDate.ToString());
HttpContext.Session.SetString("EndDate", endDate.ToString());
return RedirectToAction("MachineWorkshopTimeReport");
}
[HttpGet]
public IActionResult MachineWorkshopTimeReport()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
@ -295,9 +383,15 @@ namespace GuarantorAPP.Controllers
ViewBag.StartDate = startDate;
ViewBag.EndDate = endDate;
return View(values);
} catch
{
return RedirectToAction("Index");
}
}
[HttpPost]
public void MachineWorkshopTimeMail()
{
try
{
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
@ -308,17 +402,29 @@ namespace GuarantorAPP.Controllers
_data.SendMailReport(startDate, endDate, UserId, memoryStream);
}
Response.Redirect("MachineWorkshopTimeReport");
} catch
{
Response.Redirect("Error");
}
}
[HttpGet]
public IActionResult WorkerProductChoose()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var workers = _data.GetWorkers(UserId);
return View(workers);
} catch
{
return RedirectToAction("Error");
}
}
[HttpPost]
public IActionResult WorkerProductChoose(List<int> selectedItems, string reportType)
{
try
{
string value = string.Join("/", selectedItems);
HttpContext.Session.SetString("Workers", value);
@ -328,8 +434,14 @@ namespace GuarantorAPP.Controllers
return RedirectToAction("ExcelGenerate");
else
return RedirectToAction("WordGenerate");
} catch
{
return RedirectToAction("Error");
}
}
public async Task<IActionResult> ExcelGenerate()
{
try
{
var value = HttpContext.Session.GetString("Workers");
if (value != null)
@ -346,8 +458,14 @@ namespace GuarantorAPP.Controllers
}
}
return RedirectToAction("WorkerProductChoose");
} catch
{
RedirectToAction("Error");
}
}
public async Task<IActionResult> WordGenerate()
{
try
{
var value = HttpContext.Session.GetString("Workers");
if (value != null)
@ -364,9 +482,17 @@ namespace GuarantorAPP.Controllers
}
}
return RedirectToAction("WorkerProductChoose");
} catch
{
return RedirectToAction("Error");
}
}
[HttpGet]
public IActionResult WorkerProductReport()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var value = HttpContext.Session.GetString("Workers");
if (value != null)
@ -375,6 +501,11 @@ namespace GuarantorAPP.Controllers
var reports = _data.GetProductReports(rawReports);
return View(reports);
}
}
catch
{
return RedirectToAction("Error");
}
return View(new List<WorkerProductReportViewModel>());
}
public IActionResult ReportsMenu()
@ -386,27 +517,36 @@ namespace GuarantorAPP.Controllers
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var workshop = _data.GetWorkshop(id);
ViewBag.Workshop = workshop;
var productions = _data.GetProductions();
return View(productions);
}
catch (Exception)
{
return RedirectToAction("IndexWorkshop");
}
}
[HttpPost]
public IActionResult WorkshopProductionAdd(int workshopId, int productionId)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try
{
var workshop = _data.GetWorkshop(workshopId);
if (workshop == null)
return RedirectToAction("Index");
WorkshopBindingModel workshopBinding = new() { Id = workshopId, Title = workshop.Title, Address = workshop.Address, Director = workshop.Director, UserId = workshop.UserId, ProductionId = workshop.ProductionId, WorkshopWorker = workshop.WorkerWorkshops };
_data.UpdateWorkshop(workshopBinding);
}
catch (Exception) { }
return RedirectToAction("IndexWorkshop");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
public IActionResult Error(string ex)
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
return View(ex);
}
}
}

View File

@ -1,9 +1,11 @@
using BusinessLogic.MailWorker;
using BusinessLogic.BusinessLogic;
using BusinessLogic.MailWorker;
using BusinessLogic.OfficePackage;
using Contracts.BindingModels;
using Contracts.BusinessLogicsContracts;
using Contracts.SearchModels;
using Contracts.ViewModels;
using DocumentFormat.OpenXml.Bibliography;
namespace GuarantorAPP
{
@ -55,6 +57,11 @@ namespace GuarantorAPP
return _guarantorLogic.Update(model);
}
public bool CheckLogin(string login)
{
return _guarantorLogic.ReadElement(new() { Login = login }) == null;
}
public List<WorkerViewModel>? GetWorkers(int userId)
{
return _workerLogic.ReadList(new WorkerSearchModel() { UserId = userId });
@ -75,7 +82,10 @@ namespace GuarantorAPP
{
return _workerLogic.ReadElement(new() { Id = id });
}
public bool CheckWorkerName(string name)
{
return _workerLogic.ReadElement(new() { Name = name }) == null;
}
public List<WorkshopViewModel>? GetWorkshops(int userId)
{
return _workshopLogic.ReadList(new WorkshopSearchModel() { UserId = userId });
@ -96,7 +106,10 @@ namespace GuarantorAPP
{
return _workshopLogic.Create(model);
}
public bool CheckWorkshopTitle(string title)
{
return _workshopLogic.ReadElement(new() { Title = title }) == null;
}
public List<MachineViewModel>? GetMachines(int userId)
{
return _machineLogic.ReadList(new() { UserId = userId });
@ -117,12 +130,14 @@ namespace GuarantorAPP
{
return _machineLogic.Delete(new() { Id = machineId });
}
public bool CheckMachineTitle(string title)
{
return _machineLogic.ReadElement(new() { Title = title }) == null;
}
public List<ProductionViewModel>? GetProductions()
{
return _productionLogic.ReadList(null);
}
public List<MachineWorkshopTimeReport> GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId)
{
var workshops = _workshopLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId });

View File

@ -28,10 +28,10 @@
</div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-4">Имя:</div>
<div class="col-8">
<input type="text" name="fio" id="fio" value="@Model.Name" />
<span id="fioError" class="text-danger"></span>
<input type="text" name="name" id="name" value="@Model.Name" />
<span id="nameError" class="text-danger"></span>
</div>
</div>
<div class="row">
@ -43,11 +43,31 @@
<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();
var password = $('#password').val();
var fio = $('#fio').val();
var name = $('#name').val();
var isValid = true;
$('#loginError').text('');
@ -74,9 +94,9 @@
isValid = false;
}
// Валидация ФИО
if (fio.length < 2 || fio.length > 20) {
$('#fioError').text('ФИО должно быть от 2 до 20 символов.');
// Валидация Имя
if (name.length < 2 || name.length > 20) {
$('#nameError').text('Имя должно быть от 2 до 20 символов.');
isValid = false;
}

View File

@ -50,6 +50,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('Ошибка при проверке уникальности логина.');
}
});
}
});
$('#registerForm').submit(function (event) {
var name = $('#name').val();
var login = $('#login').val();

View File

@ -16,7 +16,7 @@
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<img src="~/images/Work-transformed.png" width="150" height="150" alt="Логотип">
<a asp-controller="Home" asp-action="Index">Приложение "Завод "Иди работать". Поручитель"</a>
<a asp-controller="Home" asp-action="Index" class="custom-link"><h1>Приложение "Завод "Иди работать". Поручитель"</h1></a>
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Privacy">@ViewData["Name"]</a>
</div>
</nav>

View File

@ -16,3 +16,12 @@ html {
body {
margin-bottom: 60px;
}
.custom-link {
color: inherit;
text-decoration: none;
}
.custom-link:hover {
text-decoration: none;
color: inherit;
}

View File

@ -97,7 +97,7 @@
}
// Валидация почты
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
var emailPattern = /^[a-zA-Z0-9._-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailPattern.test(email)) {
$('#emailError').text('Неверный формат почты.');
isValid = false;