From da20060b05b5d954ed620248fbcde35d9fd8c62c Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Tue, 28 May 2024 21:41:19 +0400 Subject: [PATCH] MoveAllViews --- .../Implements/ImplementerStorage.cs | 5 +- .../Controllers/DetailController.cs | 77 +++ .../Controllers/HomeController.cs | 476 +++--------------- .../Controllers/ProductController.cs | 118 +++++ .../Controllers/ProductionController.cs | 93 ++++ .../Controllers/ReportController.cs | 153 ++++++ Course/ImplementerApp/ImplementerData.cs | 4 + .../{Home => Detail}/CreateDetail.cshtml | 2 +- .../Views/{Home => Detail}/IndexDetail.cshtml | 6 +- Course/ImplementerApp/Views/Home/Enter.cshtml | 2 +- Course/ImplementerApp/Views/Home/Index.cshtml | 9 +- .../ImplementerApp/Views/Home/Privacy.cshtml | 8 +- .../ImplementerApp/Views/Home/Register.cshtml | 26 +- .../{Home => Product}/CreateProduct.cshtml | 2 +- .../{Home => Product}/IndexProduct.cshtml | 8 +- .../ProductMachineAdd.cshtml | 2 +- .../CreateProduction.cshtml | 2 +- .../IndexProduction.cshtml | 6 +- .../{Home => Report}/DetailTimeChoose.cshtml | 6 +- .../{Home => Report}/DetailTimeReport.cshtml | 2 +- .../DetailWorkshopChoose.cshtml | 2 +- .../DetailWorkshopReport.cshtml | 0 .../Views/{Home => Report}/ReportsMenu.cshtml | 4 +- .../Views/Shared/_Layout.cshtml | 4 +- Course/ImplementerApp/wwwroot/css/site.css | 10 + 25 files changed, 595 insertions(+), 432 deletions(-) create mode 100644 Course/ImplementerApp/Controllers/DetailController.cs create mode 100644 Course/ImplementerApp/Controllers/ProductController.cs create mode 100644 Course/ImplementerApp/Controllers/ProductionController.cs create mode 100644 Course/ImplementerApp/Controllers/ReportController.cs rename Course/ImplementerApp/Views/{Home => Detail}/CreateDetail.cshtml (96%) rename Course/ImplementerApp/Views/{Home => Detail}/IndexDetail.cshtml (79%) rename Course/ImplementerApp/Views/{Home => Product}/CreateProduct.cshtml (99%) rename Course/ImplementerApp/Views/{Home => Product}/IndexProduct.cshtml (75%) rename Course/ImplementerApp/Views/{Home => Product}/ProductMachineAdd.cshtml (89%) rename Course/ImplementerApp/Views/{Home => Production}/CreateProduction.cshtml (98%) rename Course/ImplementerApp/Views/{Home => Production}/IndexProduction.cshtml (79%) rename Course/ImplementerApp/Views/{Home => Report}/DetailTimeChoose.cshtml (93%) rename Course/ImplementerApp/Views/{Home => Report}/DetailTimeReport.cshtml (94%) rename Course/ImplementerApp/Views/{Home => Report}/DetailWorkshopChoose.cshtml (94%) rename Course/ImplementerApp/Views/{Home => Report}/DetailWorkshopReport.cshtml (100%) rename Course/ImplementerApp/Views/{Home => Report}/ReportsMenu.cshtml (65%) diff --git a/Course/DatabaseImplement/Implements/ImplementerStorage.cs b/Course/DatabaseImplement/Implements/ImplementerStorage.cs index 05db08c..cd641c9 100644 --- a/Course/DatabaseImplement/Implements/ImplementerStorage.cs +++ b/Course/DatabaseImplement/Implements/ImplementerStorage.cs @@ -23,7 +23,10 @@ namespace DatabaseImplement.Implements { if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login)) { return null; } using var context = new FactoryGoWorkDatabase(); - return context.Implementers.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.Implementers.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel; + else + return context.Implementers.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(ImplementerSearchModel model) diff --git a/Course/ImplementerApp/Controllers/DetailController.cs b/Course/ImplementerApp/Controllers/DetailController.cs new file mode 100644 index 0000000..ce46fca --- /dev/null +++ b/Course/ImplementerApp/Controllers/DetailController.cs @@ -0,0 +1,77 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace ImplementerApp.Controllers +{ + public class DetailController : Controller + { + private readonly ILogger _logger; + private readonly ImplementerData _data; + public DetailController(ILogger logger, ImplementerData data) + { + _logger = logger; + _data = data; + } + private bool IsLoggedIn { get { return UserImplementer.user != null; } } + private int UserId { get { return UserImplementer.user!.Id; } } + + + [HttpGet] + public IActionResult IndexDetail() + { + if (UserImplementer.user != null) + { + var list = _data.GetDetails(UserImplementer.user.Id); + if (list != null) + return View(list); + return View(new List()); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public void IndexDetail(int id) + { + if (UserImplementer.user != null) + { + _data.DeleteDetail(id); + } + Response.Redirect("IndexDetail"); + } + [HttpGet] + public IActionResult CreateDetail(int id) + { + if (id != 0) + { + var value = _data.GetDetail(id); + if (value != null) + return View(value); + } + return View(new DetailViewModel()); + } + [HttpPost] + public IActionResult CreateDetail(DetailBindingModel model) + { + if (model.Id == 0) + { + model.DateCreate = DateTime.Now; + model.UserId = UserImplementer.user!.Id; + if (_data.CreateDetail(model)) + return RedirectToAction("IndexDetail"); + } + else + { + if (_data.UpdateDetail(model)) + return RedirectToAction("IndexDetail"); + } + return View(); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(); + } + } +} diff --git a/Course/ImplementerApp/Controllers/HomeController.cs b/Course/ImplementerApp/Controllers/HomeController.cs index 0cd3d4e..4177736 100644 --- a/Course/ImplementerApp/Controllers/HomeController.cs +++ b/Course/ImplementerApp/Controllers/HomeController.cs @@ -12,405 +12,89 @@ namespace ImplementerApp.Controllers { public class HomeController : Controller { - private readonly ILogger _logger; - private readonly ImplementerData _data; - public HomeController(ILogger logger, ImplementerData data) - { - _logger = logger; - _data = data; - } - private bool IsLoggedIn { get { return UserImplementer.user != null; } } - private int UserId { get { return UserImplementer.user!.Id; } } - public IActionResult IndexNonReg() - { - if (!IsLoggedIn) - return View(); - return RedirectToAction("Index"); - } - public IActionResult Index() - { - if (!IsLoggedIn) - return RedirectToAction("IndexNonReg"); - 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) - { - UserImplementer.user = user; - Response.Redirect("Index"); - } - } - [HttpGet] - public IActionResult Register() - { - return View(); - } - public IActionResult Logout() - { - UserImplementer.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 IndexDetail() - { - if (UserImplementer.user != null) - { - var list = _data.GetDetails(UserImplementer.user.Id); - if (list != null) - return View(list); - return View(new List()); - } - return RedirectToAction("IndexNonReg"); - } - [HttpPost] - public void IndexDetail(int id) - { - if (UserImplementer.user != null) - { - _data.DeleteDetail(id); - } - Response.Redirect("IndexDetail"); - } - [HttpGet] - public IActionResult CreateDetail(int id) - { - if (id != 0) - { - var value = _data.GetDetail(id); - if (value != null) - return View(value); - } - return View(new DetailViewModel()); - } - [HttpPost] - public IActionResult CreateDetail(DetailBindingModel model) - { - if (model.Id == 0) - { - model.DateCreate = DateTime.Now; - model.UserId = UserImplementer.user!.Id; - if (_data.CreateDetail(model)) - return RedirectToAction("IndexDetail"); - } - else - { - if (_data.UpdateDetail(model)) - return RedirectToAction("IndexDetail"); - } - return View(); - } - [HttpGet] - public IActionResult IndexProduct() - { - if (IsLoggedIn) { - var products = _data.GetProducts(UserImplementer.user!.Id); - return View(products); - } - return RedirectToAction("IndexNonReg"); - } - [HttpPost] - public IActionResult IndexProduct(int id) - { - _data.DeleteProduct(id); - return RedirectToAction("IndexProduct"); - } - [HttpGet] - public IActionResult CreateProduct(int id) - { - var details = _data.GetDetails(UserImplementer.user!.Id); - ViewBag.AllDetails = details; - if (id != 0) - { - var value = _data.GetProduct(id); - if (value != null) - return View(value); - } - return View(new ProductViewModel()); - } - [HttpPost] - public IActionResult CreateProduct(int id, string title, int[] detailIds, int[] counts) - { - ProductBindingModel model = new ProductBindingModel(); - model.Id = id; - model.Name = title; - model.UserId = UserImplementer.user!.Id; - var details = _data.GetDetails(UserImplementer.user!.Id); - double sum = 0; - for (int i = 0; i < detailIds.Length; i++) - { - var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!; - if (counts[i] <= 0) - continue; - model.ProductDetails[detailIds[i]] = (detail, counts[i]); - sum += detail.Cost * counts[i]; - } - if (model.ProductDetails.Count == 0) - return RedirectToAction("IndexProduct"); - model.Cost = sum; - if (id != 0) - { - _data.UpdateProduct(model); - } - else - { - _data.CreateProduct(model); - } - return RedirectToAction("IndexProduct"); - } - [HttpGet] - public IActionResult IndexProduction() - { - if (UserImplementer.user != null) - { - var productions = _data.GetProductions(UserImplementer.user.Id); - return View(productions); - } - return RedirectToAction("IndexNonReg"); - } - [HttpPost] - public IActionResult IndexProduction(int id) - { - _data.DeleteProduction(id); - return RedirectToAction("IndexProduction"); - } - [HttpGet] - public IActionResult CreateProduction(int id) - { - var details = _data.GetDetails(UserImplementer.user!.Id); - ViewBag.AllDetails = details; - if (id != 0) - { - var value = _data.GetProduction(id); - if (value != null) - return View(value); - } - return View(new ProductionViewModel()); - } - [HttpPost] - public IActionResult CreateProduction(int id, string title, int[] detailIds) - { - ProductionBindingModel model = new ProductionBindingModel(); - model.Id = id; - model.Name = title; - model.UserId = UserImplementer.user!.Id; - var details = _data.GetDetails(UserImplementer.user!.Id); - double sum = 0; - for (int i = 0; i < detailIds.Length; i++) - { - var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!; - model.ProductionDetails[detailIds[i]] = detail; - sum += detail.Cost; - } - model.Cost = sum; - bool changed = false; - if (model.ProductionDetails.Count > 0) - { - if (id != 0) - { - changed = _data.UpdateProduction(model); - } - else - { - changed = _data.CreateProduction(model); - } - } - if (changed) - return RedirectToAction("IndexProduction"); - else - { - ViewBag.AllDetails = details; - return View(model); - } - } - [HttpGet] - public IActionResult Privacy() - { - if (IsLoggedIn) - return View(UserImplementer.user); - return RedirectToAction("IndexNonReg"); - } - [HttpPost] - public IActionResult Privacy(int id, string login, string email, string password, string name) - { - if (!IsLoggedIn) - return RedirectToAction("IndexNonReg"); - ImplementerBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name }; - if (_data.UpdateUser(user)) - { - UserImplementer.user = new ImplementerViewModel { Id = id, Login = login, Password = password, Name = name, Email = email }; - } - return View(user); - } - [HttpGet] - public IActionResult DetailTimeChoose() - { - 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("DetailTimeReport"); - } - [HttpGet] - public IActionResult DetailTimeReport() - { - 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); - } - [HttpPost] - public void DetailTimeMail() - { - var startDateStr = HttpContext.Session.GetString("StartDate"); - var endDateStr = HttpContext.Session.GetString("EndDate"); - var startDate = DateTime.Parse(startDateStr); - var endDate = DateTime.Parse(endDateStr).AddDays(1); - using (MemoryStream memoryStream = new MemoryStream()) { - _data.SendMailReport(startDate, endDate, UserId, memoryStream); - } - Response.Redirect("DetailTimeReport"); + private readonly ILogger _logger; + private readonly ImplementerData _data; + public HomeController(ILogger logger, ImplementerData data) + { + _logger = logger; + _data = data; } - [HttpGet] - public IActionResult DetailWorkshopChoose() - { - if (!IsLoggedIn) - return RedirectToAction("IndexNonReg"); - var details = _data.GetDetails(UserId); - return View(details); - } - [HttpPost] - public IActionResult DetailWorkshopChoose(List selectedItems, string reportType) - { - string value = string.Join("/", selectedItems); - HttpContext.Session.SetString("Details", value); - if (reportType.Equals("default")) - return RedirectToAction("DetailWorkshopReport"); - else if (reportType.Equals("excel")) - return RedirectToAction("ExcelGenerate"); - else - return RedirectToAction("WordGenerate"); - } - public async Task ExcelGenerate() - { - var value = HttpContext.Session.GetString("Details"); - if (value != null) - { - List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); - using (MemoryStream memoryStream = new MemoryStream()) - { - _data.SaveReportExcel(rawReports, memoryStream); - memoryStream.Seek(0, SeekOrigin.Begin); - var outputStream = new MemoryStream(); - await memoryStream.CopyToAsync(outputStream); - outputStream.Seek(0, SeekOrigin.Begin); - return File(outputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ReportExcel.xlsx"); - } - } - return RedirectToAction("DetailWorkshopChoose"); - } - public async Task WordGenerate() - { - var value = HttpContext.Session.GetString("Details"); - if (value != null) + private bool IsLoggedIn { get { return UserImplementer.user != null; } } + private int UserId { get { return UserImplementer.user!.Id; } } + + + public IActionResult IndexNonReg() + { + if (!IsLoggedIn) + return View(); + return RedirectToAction("Index"); + } + public IActionResult Index() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + 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) { - List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); - using (MemoryStream memoryStream = new MemoryStream()) - { - _data.SaveReportWord(rawReports, memoryStream); - memoryStream.Seek(0, SeekOrigin.Begin); - var outputStream = new MemoryStream(); - await memoryStream.CopyToAsync(outputStream); - outputStream.Seek(0, SeekOrigin.Begin); - return File(outputStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "ReportWord.docx"); - } + UserImplementer.user = user; + Response.Redirect("Index"); } - return RedirectToAction("DetailWorkshopChoose"); + Response.Redirect("Enter"); + } + [HttpGet] + public IActionResult Register() + { + return View(); + } + public IActionResult Logout() + { + UserImplementer.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 Privacy() + { + if (IsLoggedIn) + return View(UserImplementer.user); + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult Privacy(int id, string login, string email, string password, string name) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + ImplementerBindingModel user = new() { Id = id, Login = login, Email = email, Password = password, Name = name }; + if (_data.UpdateUser(user)) + { + UserImplementer.user = new ImplementerViewModel { Id = id, Login = login, Password = password, Name = name, Email = email }; + } + return View(user); } - [HttpGet] - public IActionResult DetailWorkshopReport() - { - var value = HttpContext.Session.GetString("Details"); - if (value != null) - { - List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); - var reports = _data.GetWorkshopReports(rawReports); - return View(reports); - } - return View(new List()); - } - public IActionResult ReportsMenu() - { - return View(); - } - [HttpGet] - public IActionResult ProductMachineAdd(int id) - { - if (!IsLoggedIn) - return RedirectToAction("IndexNonReg"); - var product = _data.GetProduct(id); - ViewBag.Product = product; - var machines = _data.GetMachines(); - return View(machines); - } - [HttpPost] - public IActionResult ProductMachineAdd(int productId, int machineId) - { - if (!IsLoggedIn) - return RedirectToAction("IndexNonReg"); - var product = _data.GetProduct(productId); - if (product == null) - return RedirectToAction("Index"); - ProductBindingModel productBinding = new() { Id = productId, Cost = product.Cost, Name = product.Name, UserId = product.UserId, ProductDetails = product.DetailProducts, MachineId = machineId }; - _data.UpdateProduct(productBinding); - return RedirectToAction("IndexProduct"); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(); + } + } } \ No newline at end of file diff --git a/Course/ImplementerApp/Controllers/ProductController.cs b/Course/ImplementerApp/Controllers/ProductController.cs new file mode 100644 index 0000000..463ec3c --- /dev/null +++ b/Course/ImplementerApp/Controllers/ProductController.cs @@ -0,0 +1,118 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace ImplementerApp.Controllers +{ + public class ProductController : Controller + { + private readonly ILogger _logger; + private readonly ImplementerData _data; + public ProductController(ILogger logger, ImplementerData data) + { + _logger = logger; + _data = data; + } + private bool IsLoggedIn { get { return UserImplementer.user != null; } } + private int UserId { get { return UserImplementer.user!.Id; } } + + + [HttpGet] + public IActionResult IndexProduct() + { + if (IsLoggedIn) + { + var products = _data.GetProducts(UserImplementer.user!.Id); + return View(products); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult IndexProduct(int id) + { + _data.DeleteProduct(id); + return RedirectToAction("IndexProduct"); + } + [HttpGet] + public IActionResult CreateProduct(int id) + { + var details = _data.GetDetails(UserImplementer.user!.Id); + ViewBag.AllDetails = details; + if (id != 0) + { + var value = _data.GetProduct(id); + if (value != null) + return View(value); + } + return View(new ProductViewModel()); + } + [HttpPost] + public IActionResult CreateProduct(int id, string title, int[] detailIds, int[] counts) + { + ProductBindingModel model = new ProductBindingModel(); + model.Id = id; + model.Name = title; + model.UserId = UserImplementer.user!.Id; + var details = _data.GetDetails(UserImplementer.user!.Id); + double sum = 0; + for (int i = 0; i < detailIds.Length; i++) + { + var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!; + if (counts[i] <= 0) + continue; + model.ProductDetails[detailIds[i]] = (detail, counts[i]); + sum += detail.Cost * counts[i]; + } + if (model.ProductDetails.Count == 0) + return RedirectToAction("IndexProduct"); + model.Cost = sum; + try + { + if (id != 0) + { + _data.UpdateProduct(model); + } + else + { + _data.CreateProduct(model); + } + } + catch (InvalidOperationException ex) + { + ViewBag.ErrorMessage = "Такое название изделия уже существует"; + return View(); + } + return RedirectToAction("IndexProduct"); + } + [HttpGet] + public IActionResult ProductMachineAdd(int id) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var product = _data.GetProduct(id); + ViewBag.Product = product; + var machines = _data.GetMachines(); + return View(machines); + } + [HttpPost] + public IActionResult ProductMachineAdd(int productId, int machineId) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var product = _data.GetProduct(productId); + if (product == null) + return RedirectToAction("Index"); + ProductBindingModel productBinding = new() { Id = productId, Cost = product.Cost, Name = product.Name, UserId = product.UserId, ProductDetails = product.DetailProducts, MachineId = machineId }; + _data.UpdateProduct(productBinding); + return RedirectToAction("IndexProduct"); + + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(); + } + } +} diff --git a/Course/ImplementerApp/Controllers/ProductionController.cs b/Course/ImplementerApp/Controllers/ProductionController.cs new file mode 100644 index 0000000..0980968 --- /dev/null +++ b/Course/ImplementerApp/Controllers/ProductionController.cs @@ -0,0 +1,93 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace ImplementerApp.Controllers +{ + public class ProductionController : Controller + { + private readonly ILogger _logger; + private readonly ImplementerData _data; + public ProductionController(ILogger logger, ImplementerData data) + { + _logger = logger; + _data = data; + } + private bool IsLoggedIn { get { return UserImplementer.user != null; } } + private int UserId { get { return UserImplementer.user!.Id; } } + + + [HttpGet] + public IActionResult IndexProduction() + { + if (UserImplementer.user != null) + { + var productions = _data.GetProductions(UserImplementer.user.Id); + return View(productions); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult IndexProduction(int id) + { + _data.DeleteProduction(id); + return RedirectToAction("IndexProduction"); + } + [HttpGet] + public IActionResult CreateProduction(int id) + { + var details = _data.GetDetails(UserImplementer.user!.Id); + ViewBag.AllDetails = details; + if (id != 0) + { + var value = _data.GetProduction(id); + if (value != null) + return View(value); + } + return View(new ProductionViewModel()); + } + [HttpPost] + public IActionResult CreateProduction(int id, string title, int[] detailIds) + { + ProductionBindingModel model = new ProductionBindingModel(); + model.Id = id; + model.Name = title; + model.UserId = UserImplementer.user!.Id; + var details = _data.GetDetails(UserImplementer.user!.Id); + double sum = 0; + for (int i = 0; i < detailIds.Length; i++) + { + var detail = details!.FirstOrDefault(x => x.Id == detailIds[i])!; + model.ProductionDetails[detailIds[i]] = detail; + sum += detail.Cost; + } + model.Cost = sum; + bool changed = false; + if (model.ProductionDetails.Count > 0) + { + if (id != 0) + { + changed = _data.UpdateProduction(model); + } + else + { + changed = _data.CreateProduction(model); + } + } + if (changed) + return RedirectToAction("IndexProduction"); + else + { + ViewBag.AllDetails = details; + return View(model); + } + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(); + } + } +} diff --git a/Course/ImplementerApp/Controllers/ReportController.cs b/Course/ImplementerApp/Controllers/ReportController.cs new file mode 100644 index 0000000..7403caa --- /dev/null +++ b/Course/ImplementerApp/Controllers/ReportController.cs @@ -0,0 +1,153 @@ +using Contracts.ViewModels; +using DocumentFormat.OpenXml.Spreadsheet; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace ImplementerApp.Controllers +{ + public class ReportController : Controller + { + private readonly ILogger _logger; + private readonly ImplementerData _data; + public ReportController(ILogger logger, ImplementerData data) + { + _logger = logger; + _data = data; + } + private bool IsLoggedIn { get { return UserImplementer.user != null; } } + private int UserId { get { return UserImplementer.user!.Id; } } + + + [HttpGet] + public IActionResult DetailTimeChoose() + { + 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("DetailTimeReport"); + } + [HttpGet] + public IActionResult DetailTimeReport() + { + 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); + } + [HttpPost] + public void DetailTimeMail() + { + var startDateStr = HttpContext.Session.GetString("StartDate"); + var endDateStr = HttpContext.Session.GetString("EndDate"); + var startDate = DateTime.Parse(startDateStr); + var endDate = DateTime.Parse(endDateStr).AddDays(1); + using (MemoryStream memoryStream = new MemoryStream()) + { + _data.SendMailReport(startDate, endDate, UserId, memoryStream); + } + Response.Redirect("DetailTimeReport"); + } + [HttpGet] + public IActionResult DetailWorkshopChoose() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var details = _data.GetDetails(UserId); + return View(details); + } + [HttpPost] + public IActionResult DetailWorkshopChoose(List selectedItems, string reportType) + { + string value = string.Join("/", selectedItems); + HttpContext.Session.SetString("Details", value); + if (reportType.Equals("default")) + return RedirectToAction("DetailWorkshopReport"); + else if (reportType.Equals("excel")) + return RedirectToAction("ExcelGenerate"); + else + return RedirectToAction("WordGenerate"); + } + public async Task ExcelGenerate() + { + var value = HttpContext.Session.GetString("Details"); + if (value != null) + { + List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); + using (MemoryStream memoryStream = new MemoryStream()) + { + _data.SaveReportExcel(rawReports, memoryStream); + memoryStream.Seek(0, SeekOrigin.Begin); + var outputStream = new MemoryStream(); + await memoryStream.CopyToAsync(outputStream); + outputStream.Seek(0, SeekOrigin.Begin); + return File(outputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ReportExcel.xlsx"); + } + } + return RedirectToAction("DetailWorkshopChoose"); + } + public async Task WordGenerate() + { + var value = HttpContext.Session.GetString("Details"); + if (value != null) + { + List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); + using (MemoryStream memoryStream = new MemoryStream()) + { + _data.SaveReportWord(rawReports, memoryStream); + memoryStream.Seek(0, SeekOrigin.Begin); + var outputStream = new MemoryStream(); + await memoryStream.CopyToAsync(outputStream); + outputStream.Seek(0, SeekOrigin.Begin); + return File(outputStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "ReportWord.docx"); + } + } + return RedirectToAction("DetailWorkshopChoose"); + } + [HttpGet] + public IActionResult DetailWorkshopReport() + { + var value = HttpContext.Session.GetString("Details"); + if (value != null) + { + List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); + var reports = _data.GetWorkshopReports(rawReports); + return View(reports); + } + return View(new List()); + } + public IActionResult ReportsMenu() + { + return View(); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(); + } + } +} diff --git a/Course/ImplementerApp/ImplementerData.cs b/Course/ImplementerApp/ImplementerData.cs index 699b340..6146b60 100644 --- a/Course/ImplementerApp/ImplementerData.cs +++ b/Course/ImplementerApp/ImplementerData.cs @@ -64,6 +64,10 @@ namespace ImplementerApp { return _implementerLogic.Update(model); } + public bool CheckLogin(string login) + { + return _implementerLogic.ReadElement(new() { Login = login }) == null; + } public List? GetDetails(int userId) { diff --git a/Course/ImplementerApp/Views/Home/CreateDetail.cshtml b/Course/ImplementerApp/Views/Detail/CreateDetail.cshtml similarity index 96% rename from Course/ImplementerApp/Views/Home/CreateDetail.cshtml rename to Course/ImplementerApp/Views/Detail/CreateDetail.cshtml index 3bb2e17..2db2010 100644 --- a/Course/ImplementerApp/Views/Home/CreateDetail.cshtml +++ b/Course/ImplementerApp/Views/Detail/CreateDetail.cshtml @@ -6,7 +6,7 @@

Деталь

-
+
Название:
diff --git a/Course/ImplementerApp/Views/Home/IndexDetail.cshtml b/Course/ImplementerApp/Views/Detail/IndexDetail.cshtml similarity index 79% rename from Course/ImplementerApp/Views/Home/IndexDetail.cshtml rename to Course/ImplementerApp/Views/Detail/IndexDetail.cshtml index f24d465..70f8cc9 100644 --- a/Course/ImplementerApp/Views/Home/IndexDetail.cshtml +++ b/Course/ImplementerApp/Views/Detail/IndexDetail.cshtml @@ -18,7 +18,7 @@ return; }

- Создать деталь + Создать деталь

@@ -54,10 +54,10 @@ @Html.DisplayFor(modelItem => item.Cost)
- Изменить + Изменить - + diff --git a/Course/ImplementerApp/Views/Home/Enter.cshtml b/Course/ImplementerApp/Views/Home/Enter.cshtml index 2d351bc..0021500 100644 --- a/Course/ImplementerApp/Views/Home/Enter.cshtml +++ b/Course/ImplementerApp/Views/Home/Enter.cshtml @@ -5,7 +5,7 @@

Вход в приложение

-
+
Логин:
diff --git a/Course/ImplementerApp/Views/Home/Index.cshtml b/Course/ImplementerApp/Views/Home/Index.cshtml index 8c21602..446b85f 100644 --- a/Course/ImplementerApp/Views/Home/Index.cshtml +++ b/Course/ImplementerApp/Views/Home/Index.cshtml @@ -5,12 +5,11 @@ diff --git a/Course/ImplementerApp/Views/Home/Privacy.cshtml b/Course/ImplementerApp/Views/Home/Privacy.cshtml index fa5d1b6..e68278d 100644 --- a/Course/ImplementerApp/Views/Home/Privacy.cshtml +++ b/Course/ImplementerApp/Views/Home/Privacy.cshtml @@ -4,7 +4,7 @@

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

- +
Логин:
@@ -28,9 +28,9 @@
-
ФИО:
+
Имя:
- +
@@ -47,7 +47,7 @@ var login = $('#login').val(); var email = $('#email').val(); var password = $('#password').val(); - var fio = $('#fio').val(); + var fio = $('#name').val(); var isValid = true; $('#loginError').text(''); diff --git a/Course/ImplementerApp/Views/Home/Register.cshtml b/Course/ImplementerApp/Views/Home/Register.cshtml index 06d2595..20b54f4 100644 --- a/Course/ImplementerApp/Views/Home/Register.cshtml +++ b/Course/ImplementerApp/Views/Home/Register.cshtml @@ -5,7 +5,7 @@

Регистрация

- +
Имя:
@@ -50,6 +50,26 @@ + \ No newline at end of file diff --git a/Course/ImplementerApp/Views/Home/CreateProduct.cshtml b/Course/ImplementerApp/Views/Product/CreateProduct.cshtml similarity index 99% rename from Course/ImplementerApp/Views/Home/CreateProduct.cshtml rename to Course/ImplementerApp/Views/Product/CreateProduct.cshtml index 17473cf..8614189 100644 --- a/Course/ImplementerApp/Views/Home/CreateProduct.cshtml +++ b/Course/ImplementerApp/Views/Product/CreateProduct.cshtml @@ -9,7 +9,7 @@

Создание изделия

- +
Название:
diff --git a/Course/ImplementerApp/Views/Home/IndexProduct.cshtml b/Course/ImplementerApp/Views/Product/IndexProduct.cshtml similarity index 75% rename from Course/ImplementerApp/Views/Home/IndexProduct.cshtml rename to Course/ImplementerApp/Views/Product/IndexProduct.cshtml index c75d75f..33200ce 100644 --- a/Course/ImplementerApp/Views/Home/IndexProduct.cshtml +++ b/Course/ImplementerApp/Views/Product/IndexProduct.cshtml @@ -18,7 +18,7 @@ return; }

- Создать изделие + Создать изделие

@@ -63,13 +63,13 @@ @Html.DisplayFor(modelItem => item.MachineName)
- Привязать станок + Привязать станок - Изменить + Изменить - + diff --git a/Course/ImplementerApp/Views/Home/ProductMachineAdd.cshtml b/Course/ImplementerApp/Views/Product/ProductMachineAdd.cshtml similarity index 89% rename from Course/ImplementerApp/Views/Home/ProductMachineAdd.cshtml rename to Course/ImplementerApp/Views/Product/ProductMachineAdd.cshtml index 2ecb2c8..c0d265c 100644 --- a/Course/ImplementerApp/Views/Home/ProductMachineAdd.cshtml +++ b/Course/ImplementerApp/Views/Product/ProductMachineAdd.cshtml @@ -19,7 +19,7 @@
@machine.Title
-
+ diff --git a/Course/ImplementerApp/Views/Home/CreateProduction.cshtml b/Course/ImplementerApp/Views/Production/CreateProduction.cshtml similarity index 98% rename from Course/ImplementerApp/Views/Home/CreateProduction.cshtml rename to Course/ImplementerApp/Views/Production/CreateProduction.cshtml index bb64739..8a7a6a7 100644 --- a/Course/ImplementerApp/Views/Home/CreateProduction.cshtml +++ b/Course/ImplementerApp/Views/Production/CreateProduction.cshtml @@ -9,7 +9,7 @@

Создание производства

- +
Название:
diff --git a/Course/ImplementerApp/Views/Home/IndexProduction.cshtml b/Course/ImplementerApp/Views/Production/IndexProduction.cshtml similarity index 79% rename from Course/ImplementerApp/Views/Home/IndexProduction.cshtml rename to Course/ImplementerApp/Views/Production/IndexProduction.cshtml index 3ef96cf..733a5db 100644 --- a/Course/ImplementerApp/Views/Home/IndexProduction.cshtml +++ b/Course/ImplementerApp/Views/Production/IndexProduction.cshtml @@ -18,7 +18,7 @@ return; }

- Создать производство + Создать производство

@@ -54,10 +54,10 @@ @Html.DisplayFor(modelItem => item.Cost)
- Изменить + Изменить - + diff --git a/Course/ImplementerApp/Views/Home/DetailTimeChoose.cshtml b/Course/ImplementerApp/Views/Report/DetailTimeChoose.cshtml similarity index 93% rename from Course/ImplementerApp/Views/Home/DetailTimeChoose.cshtml rename to Course/ImplementerApp/Views/Report/DetailTimeChoose.cshtml index a6df549..dcb80ca 100644 --- a/Course/ImplementerApp/Views/Home/DetailTimeChoose.cshtml +++ b/Course/ImplementerApp/Views/Report/DetailTimeChoose.cshtml @@ -5,7 +5,7 @@

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

-
+
@@ -74,8 +74,8 @@ if (validateDates()) { var formData = $('#TimeReportWeb').serialize(); - $.post('/Home/TimeReportWeb', formData, function (response) { - window.location.href = '/Home/DetailTimeReport'; + $.post('/Report/TimeReportWeb', formData, function (response) { + window.location.href = '/Report/DetailTimeReport'; }).fail(function () { alert('Произошла ошибка при создании отчета.'); }); diff --git a/Course/ImplementerApp/Views/Home/DetailTimeReport.cshtml b/Course/ImplementerApp/Views/Report/DetailTimeReport.cshtml similarity index 94% rename from Course/ImplementerApp/Views/Home/DetailTimeReport.cshtml rename to Course/ImplementerApp/Views/Report/DetailTimeReport.cshtml index 16a1583..2b31148 100644 --- a/Course/ImplementerApp/Views/Home/DetailTimeReport.cshtml +++ b/Course/ImplementerApp/Views/Report/DetailTimeReport.cshtml @@ -10,7 +10,7 @@

Список деталей в диапазоне времени

- + diff --git a/Course/ImplementerApp/Views/Home/DetailWorkshopChoose.cshtml b/Course/ImplementerApp/Views/Report/DetailWorkshopChoose.cshtml similarity index 94% rename from Course/ImplementerApp/Views/Home/DetailWorkshopChoose.cshtml rename to Course/ImplementerApp/Views/Report/DetailWorkshopChoose.cshtml index 48f35db..bde9d04 100644 --- a/Course/ImplementerApp/Views/Home/DetailWorkshopChoose.cshtml +++ b/Course/ImplementerApp/Views/Report/DetailWorkshopChoose.cshtml @@ -7,7 +7,7 @@

Выберите детали для отчета

-
+ diff --git a/Course/ImplementerApp/Views/Home/DetailWorkshopReport.cshtml b/Course/ImplementerApp/Views/Report/DetailWorkshopReport.cshtml similarity index 100% rename from Course/ImplementerApp/Views/Home/DetailWorkshopReport.cshtml rename to Course/ImplementerApp/Views/Report/DetailWorkshopReport.cshtml diff --git a/Course/ImplementerApp/Views/Home/ReportsMenu.cshtml b/Course/ImplementerApp/Views/Report/ReportsMenu.cshtml similarity index 65% rename from Course/ImplementerApp/Views/Home/ReportsMenu.cshtml rename to Course/ImplementerApp/Views/Report/ReportsMenu.cshtml index 5aacaf2..f3bdc3e 100644 --- a/Course/ImplementerApp/Views/Home/ReportsMenu.cshtml +++ b/Course/ImplementerApp/Views/Report/ReportsMenu.cshtml @@ -5,7 +5,7 @@ diff --git a/Course/ImplementerApp/Views/Shared/_Layout.cshtml b/Course/ImplementerApp/Views/Shared/_Layout.cshtml index ee64ee1..07ba487 100644 --- a/Course/ImplementerApp/Views/Shared/_Layout.cshtml +++ b/Course/ImplementerApp/Views/Shared/_Layout.cshtml @@ -17,7 +17,9 @@ diff --git a/Course/ImplementerApp/wwwroot/css/site.css b/Course/ImplementerApp/wwwroot/css/site.css index f27e5ad..fa3629b 100644 --- a/Course/ImplementerApp/wwwroot/css/site.css +++ b/Course/ImplementerApp/wwwroot/css/site.css @@ -15,4 +15,14 @@ html { body { margin-bottom: 60px; +} + +.custom-link { + color: inherit; + text-decoration: none; +} + +.custom-link:hover { + text-decoration: none; + color: inherit; } \ No newline at end of file