2024-04-28 17:11:40 +04:00
|
|
|
|
using ImplementerApp.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Diagnostics;
|
2024-04-28 21:35:19 +04:00
|
|
|
|
using BusinessLogic.BusinessLogic;
|
|
|
|
|
using Contracts.BusinessLogicsContracts;
|
2024-04-29 22:21:21 +04:00
|
|
|
|
using Contracts.ViewModels;
|
2024-04-30 00:44:32 +04:00
|
|
|
|
using DataModels.Models;
|
2024-05-23 20:02:34 +04:00
|
|
|
|
using Contracts.BindingModels;
|
2024-04-28 17:11:40 +04:00
|
|
|
|
|
|
|
|
|
namespace ImplementerApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2024-05-23 20:02:34 +04:00
|
|
|
|
private readonly ImplementerData _data;
|
|
|
|
|
public HomeController(ILogger<HomeController> logger, ImplementerData data)
|
2024-04-28 17:11:40 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-23 20:02:34 +04:00
|
|
|
|
_data = data;
|
|
|
|
|
}
|
|
|
|
|
public IActionResult IndexNonReg()
|
|
|
|
|
{
|
|
|
|
|
if (UserImplementer.user == null)
|
|
|
|
|
return View();
|
|
|
|
|
return RedirectToAction("Index");
|
2024-04-28 17:11:40 +04:00
|
|
|
|
}
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2024-05-23 20:02:34 +04:00
|
|
|
|
if (UserImplementer.user == null)
|
|
|
|
|
return RedirectToAction("IndexNonReg");
|
2024-04-28 17:11:40 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-05-23 20:02:34 +04:00
|
|
|
|
[HttpGet]
|
2024-04-28 21:35:19 +04:00
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
2024-05-23 20:02:34 +04:00
|
|
|
|
if (UserImplementer.user == null)
|
|
|
|
|
return View();
|
|
|
|
|
return RedirectToAction("Index");
|
2024-04-28 21:35:19 +04:00
|
|
|
|
}
|
2024-05-23 20:02:34 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
var user = _data.Login(login, password);
|
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
UserImplementer.user = user;
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
2024-04-28 21:35:19 +04:00
|
|
|
|
public IActionResult Register()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2024-05-23 20:02:34 +04:00
|
|
|
|
[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]
|
2024-04-28 17:11:40 +04:00
|
|
|
|
public IActionResult IndexDetail()
|
|
|
|
|
{
|
2024-05-23 20:02:34 +04:00
|
|
|
|
if (UserImplementer.user != null)
|
2024-04-30 00:44:32 +04:00
|
|
|
|
{
|
2024-05-23 20:02:34 +04:00
|
|
|
|
var list = _data.GetDetails(UserImplementer.user.Id);
|
|
|
|
|
if (list != null)
|
|
|
|
|
return View(list);
|
|
|
|
|
return View(new List<DetailViewModel>());
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("IndexNonReg");
|
2024-04-28 17:11:40 +04:00
|
|
|
|
}
|
2024-05-23 20:02:34 +04:00
|
|
|
|
[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());
|
2024-04-28 17:11:40 +04:00
|
|
|
|
}
|
2024-05-23 20:02:34 +04:00
|
|
|
|
[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]
|
2024-04-28 17:11:40 +04:00
|
|
|
|
public IActionResult IndexProduct()
|
|
|
|
|
{
|
2024-05-23 20:02:34 +04:00
|
|
|
|
if (UserImplementer.user != null) {
|
|
|
|
|
var products = _data.GetProducts(UserImplementer.user.Id);
|
|
|
|
|
return View(products);
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("IndexNonReg");
|
|
|
|
|
}
|
2024-04-28 17:11:40 +04:00
|
|
|
|
public IActionResult CreateProduct()
|
|
|
|
|
{
|
2024-04-30 00:44:32 +04:00
|
|
|
|
var details = new List<DetailViewModel>();
|
|
|
|
|
details.Add(new DetailViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Name = "Test",
|
|
|
|
|
Cost = 55.5,
|
|
|
|
|
UserId = 1
|
|
|
|
|
});
|
|
|
|
|
details.Add(new DetailViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
|
|
|
|
Name = "Test1",
|
|
|
|
|
Cost = 32,
|
|
|
|
|
UserId = 2
|
|
|
|
|
});
|
|
|
|
|
return View(details);
|
2024-04-28 17:11:40 +04:00
|
|
|
|
}
|
2024-05-23 20:02:34 +04:00
|
|
|
|
[HttpGet]
|
2024-04-28 17:11:40 +04:00
|
|
|
|
public IActionResult IndexProduction()
|
|
|
|
|
{
|
2024-05-23 20:02:34 +04:00
|
|
|
|
if (UserImplementer.user != null)
|
2024-04-30 17:03:49 +04:00
|
|
|
|
{
|
2024-05-23 20:02:34 +04:00
|
|
|
|
var productions = _data.GetProductions(UserImplementer.user.Id);
|
|
|
|
|
return View(productions);
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("IndexNonReg");
|
|
|
|
|
}
|
2024-04-28 17:11:40 +04:00
|
|
|
|
public IActionResult CreateProduction()
|
|
|
|
|
{
|
2024-04-30 00:44:32 +04:00
|
|
|
|
var details = new List<DetailViewModel>();
|
|
|
|
|
details.Add(new DetailViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Name = "Test",
|
|
|
|
|
Cost = 55.5,
|
|
|
|
|
UserId = 1
|
|
|
|
|
});
|
|
|
|
|
details.Add(new DetailViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
|
|
|
|
Name = "Test1",
|
|
|
|
|
Cost = 32,
|
|
|
|
|
UserId = 2
|
|
|
|
|
});
|
|
|
|
|
return View(details);
|
2024-04-28 17:11:40 +04:00
|
|
|
|
}
|
|
|
|
|
public IActionResult Privacy()
|
2024-04-30 17:03:49 +04:00
|
|
|
|
{
|
|
|
|
|
ImplementerViewModel user = new()
|
|
|
|
|
{
|
|
|
|
|
Email = "mail@mail.ru",
|
|
|
|
|
Login = "Login",
|
|
|
|
|
Password = "password",
|
|
|
|
|
Name = "User"
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View(user);
|
2024-04-28 17:11:40 +04:00
|
|
|
|
}
|
2024-04-30 00:44:32 +04:00
|
|
|
|
public IActionResult DetailTimeReport()
|
|
|
|
|
{
|
2024-04-30 17:03:49 +04:00
|
|
|
|
List<DetailTimeReport> detailTimeReports = new List<DetailTimeReport>
|
|
|
|
|
{
|
|
|
|
|
new DetailTimeReport
|
|
|
|
|
{
|
|
|
|
|
DetailName = "Деталь А",
|
|
|
|
|
Productions = new List<string> { "Производство 1", "Производство 2" },
|
2024-04-30 22:06:53 +04:00
|
|
|
|
Products = new List<string> { "Машина X", "Машина Y" }
|
2024-04-30 17:03:49 +04:00
|
|
|
|
},
|
|
|
|
|
new DetailTimeReport
|
|
|
|
|
{
|
|
|
|
|
DetailName = "Деталь B",
|
|
|
|
|
Productions = new List<string> { "Производство 3", "Производство 4" },
|
2024-04-30 22:06:53 +04:00
|
|
|
|
Products = new List<string> { "Машина Z", "Машина W" }
|
2024-04-30 17:03:49 +04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return View(detailTimeReports);
|
2024-04-30 00:44:32 +04:00
|
|
|
|
}
|
|
|
|
|
public IActionResult DetailWorkshopReport()
|
|
|
|
|
{
|
2024-04-30 17:03:49 +04:00
|
|
|
|
List<DetailWorkshopReportViewModel> detailWorkshopReports = new List<DetailWorkshopReportViewModel>
|
|
|
|
|
{
|
|
|
|
|
new DetailWorkshopReportViewModel
|
|
|
|
|
{
|
|
|
|
|
DetailName = "Деталь X",
|
|
|
|
|
WorkShops = new List<string> { "Цех 1", "Цех 2" }
|
|
|
|
|
},
|
|
|
|
|
new DetailWorkshopReportViewModel
|
|
|
|
|
{
|
|
|
|
|
DetailName = "Деталь Y",
|
|
|
|
|
WorkShops = new List<string> { "Цех 3", "Цех 4" }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return View(detailWorkshopReports);
|
2024-04-30 00:44:32 +04:00
|
|
|
|
}
|
|
|
|
|
public IActionResult ReportsMenu()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
public IActionResult ProductMachineAdd()
|
|
|
|
|
{
|
|
|
|
|
List<MachineViewModel> machines = new List<MachineViewModel>
|
|
|
|
|
{
|
|
|
|
|
new MachineViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Title = "Токарный станок",
|
|
|
|
|
Country = "Германия",
|
|
|
|
|
UserId = 1,
|
|
|
|
|
WorkerMachines = new()
|
|
|
|
|
},
|
|
|
|
|
new MachineViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
|
|
|
|
Title = "Фрезерный станок",
|
|
|
|
|
Country = "Япония",
|
|
|
|
|
UserId = 2,
|
|
|
|
|
WorkerMachines = new()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return View(machines);
|
|
|
|
|
}
|
2024-04-28 17:11:40 +04:00
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|