From 1df510267113d334e5b80fa7e6b0e3e7c2a4fc73 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Mon, 27 May 2024 21:03:42 +0400 Subject: [PATCH] guarantor --- .../BindingModels/MachineBindingModel.cs | 3 +- .../BindingModels/WorkshopBindingModel.cs | 3 +- .../SearchModels/GuarantorSearchModel.cs | 1 + .../SearchModels/MachineSearchModel.cs | 1 + .../Contracts/ViewModels/WorkshopViewModel.cs | 1 + .../Implements/GuarantorStorage.cs | 2 +- .../Implements/MachineStorage.cs | 6 +- .../Implements/WorkerStorage.cs | 4 +- .../Implements/WorkshopStorage.cs | 6 +- Course/DatabaseImplement/Models/Workshop.cs | 3 +- .../Controllers/HomeController.cs | 411 +++++++++++------- Course/GuarantorAPP/GuarantorAPP.csproj | 6 + Course/GuarantorAPP/GuarantorData.cs | 132 ++++++ Course/GuarantorAPP/Program.cs | 31 +- Course/GuarantorAPP/UserGuarantor.cs | 9 + .../Views/Home/CreateMachine.cshtml | 173 +++++++- .../Views/Home/CreateWorker.cshtml | 105 ++++- .../Views/Home/CreateWorkshop.cshtml | 201 ++++++++- Course/GuarantorAPP/Views/Home/Index.cshtml | 5 +- .../Views/Home/IndexMachine.cshtml | 7 +- .../Views/Home/IndexNonReg.cshtml | 10 + .../Views/Home/IndexWorker.cshtml | 7 +- .../Views/Home/IndexWorkshop.cshtml | 20 +- .../Home/MachineWorkshopTimeChoose.cshtml | 76 ++++ Course/GuarantorAPP/Views/Home/Privacy.cshtml | 86 +++- .../GuarantorAPP/Views/Home/Register.cshtml | 124 ++++-- .../Views/Home/ReportsMenu.cshtml | 5 +- .../Views/Home/WorkshopProductionAdd.cshtml | 7 +- .../GuarantorAPP/Views/Shared/_Layout.cshtml | 8 +- Course/GuarantorAPP/log4net.config | 16 + 30 files changed, 1199 insertions(+), 270 deletions(-) create mode 100644 Course/GuarantorAPP/GuarantorData.cs create mode 100644 Course/GuarantorAPP/UserGuarantor.cs create mode 100644 Course/GuarantorAPP/Views/Home/IndexNonReg.cshtml create mode 100644 Course/GuarantorAPP/Views/Home/MachineWorkshopTimeChoose.cshtml create mode 100644 Course/GuarantorAPP/log4net.config diff --git a/Course/Contracts/BindingModels/MachineBindingModel.cs b/Course/Contracts/BindingModels/MachineBindingModel.cs index f0de0a0..35b0ded 100644 --- a/Course/Contracts/BindingModels/MachineBindingModel.cs +++ b/Course/Contracts/BindingModels/MachineBindingModel.cs @@ -8,6 +8,7 @@ namespace Contracts.BindingModels public int UserId { get; set; } public string Title { get; set; } = string.Empty; public string Country { get; set; } = string.Empty; - public Dictionary MachineWorker { get; set; } = new(); + public DateTime DateCreate { get; set; } + public Dictionary MachineWorker { get; set; } = new(); } } diff --git a/Course/Contracts/BindingModels/WorkshopBindingModel.cs b/Course/Contracts/BindingModels/WorkshopBindingModel.cs index fc8160e..be47081 100644 --- a/Course/Contracts/BindingModels/WorkshopBindingModel.cs +++ b/Course/Contracts/BindingModels/WorkshopBindingModel.cs @@ -9,7 +9,8 @@ namespace Contracts.BindingModels public string Title { get; set; } = string.Empty; public string Address { get; set; } = string.Empty; public string Director { get; set; } = string.Empty; - public int? ProductionId { get; set; } + public DateTime DateCreate { get; set; } + public int? ProductionId { get; set; } public Dictionary WorkshopWorker { get; set; } = new(); } } diff --git a/Course/Contracts/SearchModels/GuarantorSearchModel.cs b/Course/Contracts/SearchModels/GuarantorSearchModel.cs index 31220d4..a176365 100644 --- a/Course/Contracts/SearchModels/GuarantorSearchModel.cs +++ b/Course/Contracts/SearchModels/GuarantorSearchModel.cs @@ -4,5 +4,6 @@ { public int? Id { get; set; } public string? Login { get; set; } + public string? Password { get; set; } } } diff --git a/Course/Contracts/SearchModels/MachineSearchModel.cs b/Course/Contracts/SearchModels/MachineSearchModel.cs index 34a2f2d..4dfdf81 100644 --- a/Course/Contracts/SearchModels/MachineSearchModel.cs +++ b/Course/Contracts/SearchModels/MachineSearchModel.cs @@ -6,6 +6,7 @@ public string? Title { get; set; } public int? UserId { get; set; } public int? WorkerId { get; set; } + public int? WorkshopId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/Course/Contracts/ViewModels/WorkshopViewModel.cs b/Course/Contracts/ViewModels/WorkshopViewModel.cs index 872b782..8d1e64b 100644 --- a/Course/Contracts/ViewModels/WorkshopViewModel.cs +++ b/Course/Contracts/ViewModels/WorkshopViewModel.cs @@ -14,6 +14,7 @@ namespace Contracts.ViewModels public string Director { get; set; } = string.Empty; public int UserId { get; set; } public int? ProductionId { get; set; } + public string? ProductionName { get; set; } public Dictionary? WorkerWorkshops { get; set; } } } diff --git a/Course/DatabaseImplement/Implements/GuarantorStorage.cs b/Course/DatabaseImplement/Implements/GuarantorStorage.cs index 19409c6..f4f9371 100644 --- a/Course/DatabaseImplement/Implements/GuarantorStorage.cs +++ b/Course/DatabaseImplement/Implements/GuarantorStorage.cs @@ -23,7 +23,7 @@ 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) && x.Login.Equals(model.Login)))?.GetViewModel; ; + 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 GetFilteredList(GuarantorSearchModel model) diff --git a/Course/DatabaseImplement/Implements/MachineStorage.cs b/Course/DatabaseImplement/Implements/MachineStorage.cs index 78edaea..52331b1 100644 --- a/Course/DatabaseImplement/Implements/MachineStorage.cs +++ b/Course/DatabaseImplement/Implements/MachineStorage.cs @@ -24,7 +24,7 @@ namespace DatabaseImplement.Implements public MachineViewModel? GetElement(MachineSearchModel model) { using var context = new FactoryGoWorkDatabase(); - return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Equals(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(MachineSearchModel model) @@ -35,9 +35,9 @@ namespace DatabaseImplement.Implements } using var context = new FactoryGoWorkDatabase(); if (model.DateFrom.HasValue) - return context.Machines.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList(); + return context.Machines.Where(x => x.UserId == model.UserId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList(); else - return context.Machines.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Machines.Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/Course/DatabaseImplement/Implements/WorkerStorage.cs b/Course/DatabaseImplement/Implements/WorkerStorage.cs index 9b14839..fc00cf7 100644 --- a/Course/DatabaseImplement/Implements/WorkerStorage.cs +++ b/Course/DatabaseImplement/Implements/WorkerStorage.cs @@ -22,7 +22,7 @@ namespace DatabaseImplement.Implements public WorkerViewModel? GetElement(WorkerSearchModel model) { using var context = new FactoryGoWorkDatabase(); - return context.Workers.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Contains(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Workers.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name.Equals(model.Name)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(WorkerSearchModel model) @@ -32,7 +32,7 @@ namespace DatabaseImplement.Implements return new(); } using var context = new FactoryGoWorkDatabase(); - return context.Workers.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Workers.Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/Course/DatabaseImplement/Implements/WorkshopStorage.cs b/Course/DatabaseImplement/Implements/WorkshopStorage.cs index 327f90c..e8e53d3 100644 --- a/Course/DatabaseImplement/Implements/WorkshopStorage.cs +++ b/Course/DatabaseImplement/Implements/WorkshopStorage.cs @@ -25,7 +25,7 @@ namespace DatabaseImplement.Implements public WorkshopViewModel? GetElement(WorkshopSearchModel model) { using var context = new FactoryGoWorkDatabase(); - return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).Include(x => x.Production).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Equals(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(WorkshopSearchModel model) @@ -38,9 +38,9 @@ namespace DatabaseImplement.Implements if (model.DetailId.HasValue) return context.Workshops.Where(x => x.ProductionId.HasValue).Include(x => x.Production).Where(x => x.Production.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); else if (model.DateFrom.HasValue) - return context.Workshops.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList(); + return context.Workshops.Where(x => x.UserId == model.UserId).Where(x => x.DateCreate <= model.DateTo && x.DateCreate >= model.DateFrom).Select(x => x.GetViewModel).ToList(); else - return context.Workshops.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Workshops.Where(x => x.UserId == model.UserId).Include(x => x.Production).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/Course/DatabaseImplement/Models/Workshop.cs b/Course/DatabaseImplement/Models/Workshop.cs index 742483c..4d1f9af 100644 --- a/Course/DatabaseImplement/Models/Workshop.cs +++ b/Course/DatabaseImplement/Models/Workshop.cs @@ -76,7 +76,7 @@ namespace DatabaseImplement.Models Title = model.Title; Address = model.Address; Director = model.Director; - ProductionId = model.ProductionId; + ProductionId = model.ProductionId == null ? ProductionId : model.ProductionId; } public WorkshopViewModel GetViewModel => new() { @@ -85,6 +85,7 @@ namespace DatabaseImplement.Models Address = Address, Director = Director, ProductionId = ProductionId, + ProductionName = Production == null ? null : Production.Name, UserId = UserId, WorkerWorkshops = WorkerWorkshops }; diff --git a/Course/GuarantorAPP/Controllers/HomeController.cs b/Course/GuarantorAPP/Controllers/HomeController.cs index 0870158..6c4ea18 100644 --- a/Course/GuarantorAPP/Controllers/HomeController.cs +++ b/Course/GuarantorAPP/Controllers/HomeController.cs @@ -1,4 +1,5 @@ -using Contracts.BusinessLogicsContracts; +using Contracts.BindingModels; +using Contracts.BusinessLogicsContracts; using Contracts.ViewModels; using GuarantorAPP.Models; using Microsoft.AspNetCore.Mvc; @@ -9,173 +10,280 @@ namespace GuarantorAPP.Controllers public class HomeController : Controller { private readonly ILogger _logger; - private readonly IGuarantorLogic _userLogic; - private readonly IMachineLogic _machineLogic; - private readonly IWorkerLogic _workerLogic; - private readonly IWorkshopLogic _workshopLogic; + private readonly GuarantorData _data; - public HomeController(ILogger logger) + public HomeController(ILogger logger, GuarantorData data) { _logger = logger; + _data = data; + } + private bool IsLoggedIn { get { return UserGuarantor.user != null; } } + private int UserId { get { return UserGuarantor.user!.Id; } } + public IActionResult IndexNonReg() + { + if (!IsLoggedIn) + return View(); + return RedirectToAction("Index"); } public IActionResult Index() { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); return View(); } - public IActionResult Enter() - { - return View(); - } + [HttpGet] + public IActionResult Enter() + { + if (!IsLoggedIn) + return View(); + return RedirectToAction("Index"); + } + [HttpPost] + public void Enter(string login, string password) + { + var user = _data.Login(login, password); + if (user != null) + { + UserGuarantor.user = user; + Response.Redirect("Index"); + } + } + [HttpGet] public IActionResult Register() { return View(); } + public IActionResult Logout() + { + UserGuarantor.user = null; + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public void Register(string name, string login, string email, string password1, string password2) + { + if (password1 == password2 && _data.Register(new() { Email = email, Login = login, Name = name, Password = password1 })) + { + Response.Redirect("Index"); + } + } + [HttpGet] public IActionResult IndexMachine() { - List machines = new List + if (UserGuarantor.user != null) { - new MachineViewModel - { - Id = 1, - Title = "Токарный станок", - Country = "Китай", - UserId = 1 - }, - new MachineViewModel - { - Id = 2, - Title = "Фрезерный станок", - Country = "Россия", - UserId = 2 + var machines = _data.GetMachines(UserGuarantor.user.Id); + return View(machines); } - }; - return View(machines); + return RedirectToAction("IndexNonReg"); } - public IActionResult CreateMachine() + [HttpPost] + public IActionResult IndexMachine(int id) { - var workers = new List(); - workers.Add(new WorkerViewModel - { - Id = 1, - Name = "Фролов Феодосий Валерьевич", - Birthday = new DateTime(1989, 03, 29), - Specialization = "Металлург", - Salary = 55000, - UserId = 1 - }); - workers.Add(new WorkerViewModel - { - Id = 2, - Name = "Медведков Андрей Алексеевич", - Birthday = new DateTime(2004, 02, 29), - Specialization = "Слесарь", - Salary = 25000, - UserId = 2 - }); - return View(workers); - } + _data.DeleteMachine(id); + return RedirectToAction("IndexMachine"); + } + [HttpGet] + public IActionResult CreateMachine(int id) + { + var workers = _data.GetWorkers(UserGuarantor.user!.Id); + ViewBag.AllWorkers = workers; + if (id != 0) + { + var value = _data.GetMachine(id); + if (value != null) + return View(value); + } + return View(new MachineViewModel()); + } + [HttpPost] + public IActionResult CreateMachine(int id, string title, int[] workerIds) + { + MachineBindingModel model = new MachineBindingModel(); + model.Id = id; + model.Title = title; + model.DateCreate = DateTime.Now; + model.UserId = UserGuarantor.user!.Id; + var workers = _data.GetWorkers(UserGuarantor.user!.Id); + for (int i = 0; i < workerIds.Length; i++) + { + var worker = workers!.FirstOrDefault(x => x.Id == workerIds[i]); + model.MachineWorker[workerIds[i]] = worker; + } + bool changed = false; + if (model.MachineWorker.Count > 0) + { + if (id != 0) + { + changed = _data.UpdateMachine(model); + } + else + { + changed = _data.CreateMachine(model); + } + } + if (changed) + return RedirectToAction("IndexMachine"); + else + { + ViewBag.AllWorkers = workers; + return View(model); + } + } + [HttpGet] public IActionResult IndexWorker() { - var workers = new List(); - workers.Add(new WorkerViewModel - { - Id = 1, - Name = "Фролов Феодосий Валерьевич", - Birthday = new DateTime(1989, 03, 29), - Specialization = "Металлург", - Salary = 55000, - UserId = 1 - }); - workers.Add(new WorkerViewModel - { - Id = 2, - Name = "Медведков Андрей Алексеевич", - Birthday = new DateTime(2004, 02, 29), - Specialization = "Слесарь", - Salary = 25000, - UserId = 2 - }); - return View(workers); + if (UserGuarantor.user != null) + { + var list = _data.GetWorkers(UserGuarantor.user.Id); + if (list != null) + return View(list); + return View(new List()); + } + return RedirectToAction("IndexNonReg"); } - public IActionResult CreateWorker() + [HttpPost] + public void IndexWorker(int id) { + if (UserGuarantor.user != null) + { + _data.DeleteWorker(id); + } + Response.Redirect("IndexWorker"); + } + [HttpGet] + public IActionResult CreateWorker(int id) + { + if (id != 0) + { + var value = _data.GetWorker(id); + if (value != null) + return View(value); + } + return View(new WorkerViewModel()); + } + [HttpPost] + public IActionResult CreateWorker(WorkerBindingModel model) + { + if (model.Id == 0) + { + model.UserId = UserGuarantor.user!.Id; + if (_data.CreateWorker(model)) + return RedirectToAction("IndexWorker"); + } + else + { + if (_data.UpdateWorker(model)) + return RedirectToAction("IndexWorker"); + } return View(); } + [HttpGet] public IActionResult IndexWorkshop() { - List workshops = new List + if (IsLoggedIn) { - new WorkshopViewModel - { - Id = 1, - Title = "Механический цех", - Address = "Ул. Пушкина, колотушкина", - Director = "Главный Андрей цеха", - UserId = 1, - ProductionId = 1, - }, - new WorkshopViewModel - { - Id = 2, - Title = "Сварочный цех", - Address = "Ул. Пушкина, колотушкина 22", - Director = "Фрезер Давыд Анатольевич", - UserId = 2, - ProductionId = 2, - } - }; - return View(workshops); + var workshops = _data.GetWorkshops(UserGuarantor.user!.Id); + return View(workshops); + } + return RedirectToAction("IndexNonReg"); } - public IActionResult CreateWorkshop() + [HttpPost] + public IActionResult IndexWorkshop(int id) { - var workers = new List(); - workers.Add(new WorkerViewModel - { - Id = 1, - Name = "Фролов Феодосий Валерьевич", - Birthday = new DateTime(1989, 03, 29), - Specialization = "Металлург", - Salary = 55000, - UserId = 1 - }); - workers.Add(new WorkerViewModel - { - Id = 2, - Name = "Медведков Андрей Алексеевич", - Birthday = new DateTime(2004, 02, 29), - Specialization = "Слесарь", - Salary = 25000, - UserId = 2 - }); - return View(workers); - } + _data.DeleteWorkshop(id); + return RedirectToAction("IndexWorkshop"); + } + [HttpGet] + public IActionResult CreateWorkshop(int id) + { + var workers = _data.GetWorkers(UserGuarantor.user!.Id); + ViewBag.AllWorkers = workers; + if (id != 0) + { + var value = _data.GetWorkshop(id); + if (value != null) + return View(value); + } + return View(new WorkshopViewModel()); + } + [HttpPost] + public IActionResult CreateWorkshop(int id, string title, int[] workerIds) + { + WorkshopBindingModel model = new WorkshopBindingModel(); + model.Id = id; + model.Title = title; + model.DateCreate = DateTime.Now; + model.UserId = UserGuarantor.user!.Id; + var workers = _data.GetWorkers(UserGuarantor.user!.Id); + for (int i = 0; i < workerIds.Length; i++) + { + var worker = workers!.FirstOrDefault(x => x.Id == workerIds[i])!; + model.WorkshopWorker[workerIds[i]] = (worker); + } + if (model.WorkshopWorker.Count == 0) + return RedirectToAction("IndexWorkshop"); + if (id != 0) + { + _data.UpdateWorkshop(model); + } + else + { + _data.CreateWorkshop(model); + } + return RedirectToAction("IndexWorkshop"); + } + [HttpGet] public IActionResult Privacy() { - GuarantorViewModel user = new() + if (IsLoggedIn) + return View(UserGuarantor.user); + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult Privacy(int id, string login, string email, string password, string name) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + GuarantorBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name }; + if (_data.UpdateUser(user)) { - Email = "mailtatar@mail.ru", - Login = "tatar", - Password = "password", - Name = "User", - }; + UserGuarantor.user = new GuarantorViewModel { Id = id, Login = login, Password = password, Name = name, Email = email }; + } return View(user); } + [HttpGet] + public IActionResult MachineWorkshopTimeChoose() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + 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() { - List machineWorkshopTimeReports = new List - { - new MachineWorkshopTimeReport - { - WorkshopName = "Цех А", - Machines = new List { "Фрезерный станок", "Токарный станок" } - }, - new MachineWorkshopTimeReport - { - WorkshopName = "Цех В", - Machines = new List { "Станок А", "Станок В" } - } - }; - return View(machineWorkshopTimeReports); + var startDateStr = HttpContext.Session.GetString("StartDate"); + var endDateStr = HttpContext.Session.GetString("EndDate"); + var startDate = DateTime.Parse(startDateStr); + var endDate = DateTime.Parse(endDateStr).AddDays(1); + + var values = _data.GetTimeReport(startDate, endDate, UserId); + ViewBag.StartDate = startDate; + ViewBag.EndDate = endDate; + return View(values); } public IActionResult WorkerProductReport() { @@ -198,26 +306,27 @@ namespace GuarantorAPP.Controllers { return View(); } - public IActionResult WorkshopProductionAdd() + [HttpGet] + public IActionResult WorkshopProductionAdd(int id) { - List production = new List - { - new ProductionViewModel - { - Id = 1, - Name = "Производство старое", - Cost = 1, - UserId = 1, - }, - new ProductionViewModel - { - Id = 2, - Name = "Производство новое", - Cost = 2, - UserId = 2, - } - }; - return View(production); + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var workshop = _data.GetWorkshop(id); + ViewBag.Workshop = workshop; + var productions = _data.GetProductions(); + return View(productions); + } + [HttpPost] + public IActionResult WorkshopProductionAdd(int workshopId, int productionId) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + 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); + return RedirectToAction("IndexWorkshop"); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() diff --git a/Course/GuarantorAPP/GuarantorAPP.csproj b/Course/GuarantorAPP/GuarantorAPP.csproj index 78db959..f2ea86a 100644 --- a/Course/GuarantorAPP/GuarantorAPP.csproj +++ b/Course/GuarantorAPP/GuarantorAPP.csproj @@ -7,7 +7,13 @@ + + + + + + diff --git a/Course/GuarantorAPP/GuarantorData.cs b/Course/GuarantorAPP/GuarantorData.cs new file mode 100644 index 0000000..cf8a9ba --- /dev/null +++ b/Course/GuarantorAPP/GuarantorData.cs @@ -0,0 +1,132 @@ +using Contracts.BindingModels; +using Contracts.BusinessLogicsContracts; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace GuarantorAPP +{ + public class GuarantorData + { + private readonly ILogger _logger; + private readonly IGuarantorLogic _guarantorLogic; + private readonly IWorkerLogic _workerLogic; + private readonly IMachineLogic _machineLogic; + private readonly IWorkshopLogic _workshopLogic; + private readonly IProductionLogic _productionLogic; + + public GuarantorData(ILogger logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic) + { + _logger = logger; + _guarantorLogic = guarantorLogic; + _workerLogic = workerLogic; + _machineLogic = machineLogic; + _workshopLogic = workshopLogic; + _productionLogic = productionLogic; + } + + public GuarantorViewModel? Login(string login, string password) + { + return _guarantorLogic.ReadElement(new() + { + Login = login, + Password = password + }); + } + + public bool Register(GuarantorBindingModel model) + { + return _guarantorLogic.Create(model); + } + + public bool UpdateUser(GuarantorBindingModel model) + { + return _guarantorLogic.Update(model); + } + + public List? GetWorkers(int userId) + { + return _workerLogic.ReadList(new WorkerSearchModel() { UserId = userId }); + } + public bool DeleteWorker(int workerId) + { + return _workerLogic.Delete(new() { Id = workerId }); + } + public bool CreateWorker(WorkerBindingModel model) + { + return _workerLogic.Create(model); + } + public bool UpdateWorker(WorkerBindingModel model) + { + return _workerLogic.Update(model); + } + public WorkerViewModel? GetWorker(int id) + { + return _workerLogic.ReadElement(new() { Id = id }); + } + + public List? GetWorkshops(int userId) + { + return _workshopLogic.ReadList(new WorkshopSearchModel() { UserId = userId }); + } + public WorkshopViewModel? GetWorkshop(int id) + { + return _workshopLogic.ReadElement(new() { Id = id }); + } + public bool UpdateWorkshop(WorkshopBindingModel model) + { + return _workshopLogic.Update(model); + } + public bool DeleteWorkshop(int workshopId) + { + return _workshopLogic.Delete(new() { Id = workshopId }); + } + public bool CreateWorkshop(WorkshopBindingModel model) + { + return _workshopLogic.Create(model); + } + + public List? GetMachines(int userId) + { + return _machineLogic.ReadList(new() { UserId = userId }); + } + public MachineViewModel? GetMachine(int id) + { + return _machineLogic.ReadElement(new() { Id = id }); + } + public bool CreateMachine(MachineBindingModel model) + { + return _machineLogic.Create(model); + } + public bool UpdateMachine(MachineBindingModel model) + { + return _machineLogic.Update(model); + } + public bool DeleteMachine(int machineId) + { + return _machineLogic.Delete(new() { Id = machineId }); + } + + public List? GetProductions() + { + return _productionLogic.ReadList(null); + } + + public List GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId) + { + var workshops = _workshopLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId }); + if (workshops == null) + return new(); + List machineWorkshopTimeReports = new List(); + foreach (var workshop in workshops) + { + var report = new MachineWorkshopTimeReport(); + report.WorkshopName = workshop.Title; + var machines = _machineLogic.ReadList(new() { WorkshopId = workshop.Id, UserId = UserId }); + if (machines != null) + report.Machines = machines.Select(p => p.Title).ToList(); + machineWorkshopTimeReports.Add(report); + } + return machineWorkshopTimeReports; + } + } +} diff --git a/Course/GuarantorAPP/Program.cs b/Course/GuarantorAPP/Program.cs index ec94c61..cb14496 100644 --- a/Course/GuarantorAPP/Program.cs +++ b/Course/GuarantorAPP/Program.cs @@ -1,7 +1,35 @@ +using BusinessLogic.BusinessLogic; +using Contracts.BusinessLogicsContracts; +using Contracts.StoragesContracts; +using DatabaseImplement.Implements; +using GuarantorAPP; + var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllersWithViews(); +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddSession(options => +{ + options.IdleTimeout = TimeSpan.FromMinutes(30); + options.Cookie.HttpOnly = true; + options.Cookie.IsEssential = true; +}); + var app = builder.Build(); if (!app.Environment.IsDevelopment()) @@ -15,10 +43,11 @@ app.UseStaticFiles(); app.UseRouting(); +app.UseSession(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/Course/GuarantorAPP/UserGuarantor.cs b/Course/GuarantorAPP/UserGuarantor.cs new file mode 100644 index 0000000..8e25ac2 --- /dev/null +++ b/Course/GuarantorAPP/UserGuarantor.cs @@ -0,0 +1,9 @@ +using Contracts.ViewModels; + +namespace GuarantorAPP +{ + public static class UserGuarantor + { + public static GuarantorViewModel? user { get; set; } + } +} diff --git a/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml b/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml index b6f5a06..17ff507 100644 --- a/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml +++ b/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml @@ -1,20 +1,163 @@ -@{ +@using Contracts.ViewModels; +@model MachineViewModel; +@{ ViewData["Title"] = "CreateMachine"; + ViewBag.Workers = Model.WorkerMachines; }

Создание станка

-
-
-
Название:
-
-
-
-
Страна производства:
-
-
-
-
-
-
-
\ No newline at end of file +
+
+
Название станка:
+
+ + +
+
+
+
Страна производитель:
+
+ + +
+
+
+
Работники, управляющие станком
+
+ + + + + + + + + + + @foreach (var worker in ViewBag.Workers) + { + + + + + + + } + +
ИмяДолжностьЗарплатаУдалить
+ + @worker.Value.Name + @worker.Value.Position@worker.Value.Salary
+
+ + +
+
+
Общая зарплата:
+
+
+
+
+
+
+
+ + + + diff --git a/Course/GuarantorAPP/Views/Home/CreateWorker.cshtml b/Course/GuarantorAPP/Views/Home/CreateWorker.cshtml index 1e7e77a..0b0a3ea 100644 --- a/Course/GuarantorAPP/Views/Home/CreateWorker.cshtml +++ b/Course/GuarantorAPP/Views/Home/CreateWorker.cshtml @@ -1,28 +1,85 @@ -@{ +@using Contracts.ViewModels; +@{ ViewData["Title"] = "CreateWorker"; } +@model WorkerViewModel;
-

Создание работника

+

работник

-
-
-
Имя:
-
-
-
-
Дата рождения:
-
-
-
-
Специальность:
-
-
-
-
Зарплата:
-
-
-
-
-
-
-
\ No newline at end of file +
+ +
+
Имя работника:
+
+ + +
+
+
+
Дата рождения:
+
+ + +
+
+
+
Специальность:
+
+ + +
+
+
+
Заработная плата:
+
+ + +
+
+
+
+
+
+
+ + + diff --git a/Course/GuarantorAPP/Views/Home/CreateWorkshop.cshtml b/Course/GuarantorAPP/Views/Home/CreateWorkshop.cshtml index f17852d..d251e5f 100644 --- a/Course/GuarantorAPP/Views/Home/CreateWorkshop.cshtml +++ b/Course/GuarantorAPP/Views/Home/CreateWorkshop.cshtml @@ -1,24 +1,187 @@ -@{ +@using Contracts.ViewModels; +@model WorkshopViewModel; +@{ ViewData["Title"] = "CreateWorkshop"; + ViewBag.Workers = Model.WorkerWorkshops; }

Создание цеха

-
-
-
Название:
-
-
-
-
Адрес цеха:
-
-
-
-
Директор цеха:
-
-
-
-
-
-
-
\ No newline at end of file +
+
+
Название цеха:
+
+ + +
+
+
+
Адрес цеха:
+
+ + +
+
+
+
ФИО директора цеха:
+
+ + +
+
+
+
Название продукции:
+
+ + +
+
+
+
Работники цеха
+
+ + + + + + + + + + + @foreach (var worker in ViewBag.Workers) + { + + + + + + + } + +
ИмяДолжностьЗарплатаУдалить
+ + @worker.Value.Name + @worker.Value.Position@worker.Value.Salary + +
+
+ + +
+
+
Общая зарплата:
+
+
+
+
+
+
+
+ + + + diff --git a/Course/GuarantorAPP/Views/Home/Index.cshtml b/Course/GuarantorAPP/Views/Home/Index.cshtml index af6c18f..c39ca93 100644 --- a/Course/GuarantorAPP/Views/Home/Index.cshtml +++ b/Course/GuarantorAPP/Views/Home/Index.cshtml @@ -3,13 +3,12 @@ }
-

Приложение "Завод "Иди работать". Исполнитель"

+

Главное меню

diff --git a/Course/GuarantorAPP/Views/Home/IndexMachine.cshtml b/Course/GuarantorAPP/Views/Home/IndexMachine.cshtml index ca00164..0b83791 100644 --- a/Course/GuarantorAPP/Views/Home/IndexMachine.cshtml +++ b/Course/GuarantorAPP/Views/Home/IndexMachine.cshtml @@ -19,7 +19,7 @@ return; }

- Создать станок + Создать станок

@@ -58,7 +58,10 @@ Изменить } diff --git a/Course/GuarantorAPP/Views/Home/IndexNonReg.cshtml b/Course/GuarantorAPP/Views/Home/IndexNonReg.cshtml new file mode 100644 index 0000000..b092f77 --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/IndexNonReg.cshtml @@ -0,0 +1,10 @@ +@{ + ViewData["Title"] = "Home Page"; +} + + \ No newline at end of file diff --git a/Course/GuarantorAPP/Views/Home/IndexWorker.cshtml b/Course/GuarantorAPP/Views/Home/IndexWorker.cshtml index 1ef5047..e830a0e 100644 --- a/Course/GuarantorAPP/Views/Home/IndexWorker.cshtml +++ b/Course/GuarantorAPP/Views/Home/IndexWorker.cshtml @@ -19,7 +19,7 @@ return; }

- Создать работника + Создать работника

- Удалить +
+ + +
@@ -70,7 +70,10 @@ Изменить } diff --git a/Course/GuarantorAPP/Views/Home/IndexWorkshop.cshtml b/Course/GuarantorAPP/Views/Home/IndexWorkshop.cshtml index 29b4289..daaf175 100644 --- a/Course/GuarantorAPP/Views/Home/IndexWorkshop.cshtml +++ b/Course/GuarantorAPP/Views/Home/IndexWorkshop.cshtml @@ -19,7 +19,7 @@ return; }

- Создать цех + Создать цех

- Удалить +
+ + +
@@ -37,10 +37,16 @@ Директор цеха + + @@ -60,11 +66,17 @@ + } diff --git a/Course/GuarantorAPP/Views/Home/MachineWorkshopTimeChoose.cshtml b/Course/GuarantorAPP/Views/Home/MachineWorkshopTimeChoose.cshtml new file mode 100644 index 0000000..0de5dd3 --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/MachineWorkshopTimeChoose.cshtml @@ -0,0 +1,76 @@ +@{ + ViewData["Title"] = "Создание отчета"; +} + +
+

Создание отчета

+
+ +
+
+ +
+
+ + +
+
+
+
+ +
+
+ + +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/Course/GuarantorAPP/Views/Home/Privacy.cshtml b/Course/GuarantorAPP/Views/Home/Privacy.cshtml index af4fb19..f8807b5 100644 --- a/Course/GuarantorAPP/Views/Home/Privacy.cshtml +++ b/Course/GuarantorAPP/Views/Home/Privacy.cshtml @@ -1,6 +1,88 @@ @{ ViewData["Title"] = "Privacy Policy"; } -

@ViewData["Title"]

+
+

Личные данные

+
+ + +
+
Логин:
+
+ + +
+
+
+
Почта:
+
+ + +
+
+
+
Пароль:
+
+ + +
+
+
+
ФИО:
+
+ + +
+
+
+
+
+
+ -

Use this page to detail your site's privacy policy.

+ + diff --git a/Course/GuarantorAPP/Views/Home/Register.cshtml b/Course/GuarantorAPP/Views/Home/Register.cshtml index 924d990..89f83cc 100644 --- a/Course/GuarantorAPP/Views/Home/Register.cshtml +++ b/Course/GuarantorAPP/Views/Home/Register.cshtml @@ -3,31 +3,101 @@ }
-

Регистрация

+

Регистрация

- -
-
Имя:
-
-
-
-
Логин:
-
-
-
-
Почта:
-
-
-
-
Пароль:
-
-
-
-
Повтор пароля:
-
-
-
-
-
-
- \ No newline at end of file + +
+
Имя:
+
+ + +
+
+
+
Логин:
+
+ + +
+
+
+
Почта:
+
+ + +
+
+
+
Пароль:
+
+ + +
+
+
+
Повтор пароля:
+
+ + +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/Course/GuarantorAPP/Views/Home/ReportsMenu.cshtml b/Course/GuarantorAPP/Views/Home/ReportsMenu.cshtml index 6291390..4454e65 100644 --- a/Course/GuarantorAPP/Views/Home/ReportsMenu.cshtml +++ b/Course/GuarantorAPP/Views/Home/ReportsMenu.cshtml @@ -5,8 +5,7 @@ diff --git a/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml b/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml index 6babefd..ff59377 100644 --- a/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml +++ b/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml @@ -7,7 +7,7 @@ }
-

Цех - @ViewBag.Workshop

+

Цех - @ViewBag.Workshop.Name

@@ -19,8 +19,9 @@
@production.Name
-
- + + +
diff --git a/Course/GuarantorAPP/Views/Shared/_Layout.cshtml b/Course/GuarantorAPP/Views/Shared/_Layout.cshtml index 3ff5de6..91c809d 100644 --- a/Course/GuarantorAPP/Views/Shared/_Layout.cshtml +++ b/Course/GuarantorAPP/Views/Shared/_Layout.cshtml @@ -1,4 +1,7 @@ - +@{ + ViewData["Name"] = UserGuarantor.user == null ? "Пользователь" : UserGuarantor.user.Name; +} + @@ -13,7 +16,8 @@ diff --git a/Course/GuarantorAPP/log4net.config b/Course/GuarantorAPP/log4net.config new file mode 100644 index 0000000..f3963a1 --- /dev/null +++ b/Course/GuarantorAPP/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file
- Изменить работника + Работник - Удалить работника + Привязка производства к цеху + + Изменить цех + + Удалить цех
@Html.DisplayFor(modelItem => item.Director) + @Html.DisplayFor(modelItem => item.ProductionName) + Изменить - Удалить +
+ + +