This commit is contained in:
Дмитрий Блохин 2024-05-29 17:12:35 +04:00
commit ed24d5e00e
8 changed files with 288 additions and 166 deletions

View File

@ -40,7 +40,7 @@ namespace DatabaseImplement.Models
public virtual List<WorkerMachine> Workers { get; set; } = new();
public virtual Guarantor Guarantor { get; set; }
[ForeignKey("MachineId")]
public virtual List<Product> Products { get; set; }
public virtual List<Product> Products { get; set; } = new();
public static Machine Create(MachineBindingModel model, FactoryGoWorkDatabase context)
{
return new Machine()

View File

@ -20,19 +20,24 @@ namespace ImplementerApp.Controllers
[HttpGet]
public IActionResult IndexDetail()
{
if (UserImplementer.user != null)
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg", "Home");
try
{
var list = _data.GetDetails(UserImplementer.user.Id);
var list = _data.GetDetails(UserImplementer.user!.Id);
if (list != null)
return View(list);
return View(new List<DetailViewModel>());
}
return RedirectToAction("IndexNonReg");
catch (Exception)
{
return View(new List<DetailViewModel>()); ;
}
return View(new List<DetailViewModel>());
}
[HttpPost]
public void IndexDetail(int id)
{
if (UserImplementer.user != null)
if (IsLoggedIn)
{
_data.DeleteDetail(id);
}
@ -41,6 +46,10 @@ namespace ImplementerApp.Controllers
[HttpGet]
public IActionResult CreateDetail(int id)
{
if (!IsLoggedIn)
{
return RedirectToAction("IndexNonReg", "Home");
}
if (id != 0)
{
var value = _data.GetDetail(id);
@ -51,25 +60,26 @@ namespace ImplementerApp.Controllers
}
[HttpPost]
public IActionResult CreateDetail(DetailBindingModel model)
{
try
{
if (model.Id == 0)
{
model.DateCreate = DateTime.Now;
model.UserId = UserImplementer.user!.Id;
try {
model.UserId = UserId;
if (_data.CreateDetail(model))
return RedirectToAction("IndexDetail");
} catch (ArgumentException ex)
{
return RedirectToAction("Error", ex.Message);
}
}
else
{
if (_data.UpdateDetail(model))
return RedirectToAction("IndexDetail");
}
return View();
} catch (Exception)
{
return RedirectToAction("IndexDetail");
}
return RedirectToAction("IndexDetail");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

View File

@ -24,10 +24,16 @@ namespace ImplementerApp.Controllers
[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)
@ -50,6 +56,7 @@ namespace ImplementerApp.Controllers
[HttpPost]
public void Enter(string login, string password)
{
try {
var user = _data.Login(login, password);
if (user != null)
{
@ -57,6 +64,11 @@ namespace ImplementerApp.Controllers
Response.Redirect("Index");
}
Response.Redirect("Enter");
} catch (Exception)
{
Response.Redirect("IndexNonReg");
}
}
[HttpGet]
public IActionResult Register()
@ -70,11 +82,17 @@ namespace ImplementerApp.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 Privacy()
@ -88,12 +106,17 @@ namespace ImplementerApp.Controllers
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try {
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);
} catch (Exception)
{
return RedirectToAction("IndexNonReg");
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

View File

@ -23,19 +23,33 @@ namespace ImplementerApp.Controllers
{
if (IsLoggedIn)
{
try {
var products = _data.GetProducts(UserImplementer.user!.Id);
return View(products);
} catch (Exception)
{
return RedirectToAction("IndexNonReg", "Home");
}
return RedirectToAction("IndexNonReg");
}
return RedirectToAction("IndexNonReg", "Home");
}
[HttpPost]
public IActionResult IndexProduct(int id)
{
try
{
_data.DeleteProduct(id);
}
catch (Exception)
{ }
return RedirectToAction("IndexProduct");
}
[HttpGet]
public IActionResult CreateProduct(int id)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg", "Home");
try
{
var details = _data.GetDetails(UserImplementer.user!.Id);
ViewBag.AllDetails = details;
@ -45,10 +59,15 @@ namespace ImplementerApp.Controllers
if (value != null)
return View(value);
}
}
catch (Exception)
{ }
return View(new ProductViewModel());
}
[HttpPost]
public IActionResult CreateProduct(int id, string title, int[] detailIds, int[] counts)
{
try
{
ProductBindingModel model = new ProductBindingModel();
model.Id = id;
@ -67,8 +86,7 @@ namespace ImplementerApp.Controllers
if (model.ProductDetails.Count == 0)
return RedirectToAction("IndexProduct");
model.Cost = sum;
try
{
if (id != 0)
{
_data.UpdateProduct(model);
@ -89,22 +107,29 @@ namespace ImplementerApp.Controllers
public IActionResult ProductMachineAdd(int id)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return RedirectToAction("IndexNonReg", "Home");
try
{
var product = _data.GetProduct(id);
ViewBag.Product = product;
var machines = _data.GetMachines();
return View(machines);
} catch (Exception)
{
return RedirectToAction("IndexProduct");
}
}
[HttpPost]
public IActionResult ProductMachineAdd(int productId, int machineId)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
try {
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);
} catch (Exception)
{ }
return RedirectToAction("IndexProduct");
}

View File

@ -19,21 +19,36 @@ namespace ImplementerApp.Controllers
[HttpGet]
public IActionResult IndexProduction()
{
if (UserImplementer.user != null)
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg", "Home");
try
{
var productions = _data.GetProductions(UserImplementer.user.Id);
var productions = _data.GetProductions(UserImplementer.user!.Id);
return View(productions);
} catch
{
return RedirectToAction("IndexNonReg", "Home");
}
return RedirectToAction("IndexNonReg");
}
[HttpPost]
public IActionResult IndexProduction(int id)
{
try
{
_data.DeleteProduction(id);
return RedirectToAction("IndexProduction");
} catch
{
return RedirectToAction("IndexNonReg");
}
}
[HttpGet]
public IActionResult CreateProduction(int id)
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg", "Home");
try
{
var details = _data.GetDetails(UserImplementer.user!.Id);
ViewBag.AllDetails = details;
@ -43,10 +58,16 @@ namespace ImplementerApp.Controllers
if (value != null)
return View(value);
}
} catch
{
return RedirectToAction("IndexProduction");
}
return View(new ProductionViewModel());
}
[HttpPost]
public IActionResult CreateProduction(int id, string title, int[] detailIds)
{
try
{
ProductionBindingModel model = new ProductionBindingModel();
model.Id = id;
@ -80,6 +101,10 @@ namespace ImplementerApp.Controllers
ViewBag.AllDetails = details;
return View(model);
}
} catch
{
return RedirectToAction("IndexProduction");
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

View File

@ -22,22 +22,12 @@ namespace ImplementerApp.Controllers
public IActionResult DetailTimeChoose()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return RedirectToAction("IndexNonReg", "Home");
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());
@ -46,6 +36,9 @@ namespace ImplementerApp.Controllers
[HttpGet]
public IActionResult DetailTimeReport()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg", "Home");
try {
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
var startDate = DateTime.Parse(startDateStr);
@ -57,9 +50,15 @@ namespace ImplementerApp.Controllers
ViewBag.EndDate = endDate;
return View(values);
} catch
{
return RedirectToAction("Index", "Home");
}
}
[HttpPost]
public void DetailTimeMail()
{
try
{
var startDateStr = HttpContext.Session.GetString("StartDate");
var endDateStr = HttpContext.Session.GetString("EndDate");
@ -71,16 +70,30 @@ namespace ImplementerApp.Controllers
}
Response.Redirect("DetailTimeReport");
}
catch
{
Response.Redirect("Error");
}
}
[HttpGet]
public IActionResult DetailWorkshopChoose()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
return RedirectToAction("IndexNonReg", "Home");
try
{
var details = _data.GetDetails(UserId);
return View(details);
}
catch
{
return RedirectToAction("Error");
}
}
[HttpPost]
public IActionResult DetailWorkshopChoose(List<int> selectedItems, string reportType)
{
try
{
string value = string.Join("/", selectedItems);
HttpContext.Session.SetString("Details", value);
@ -91,8 +104,14 @@ namespace ImplementerApp.Controllers
else
return RedirectToAction("WordGenerate");
}
catch
{
return RedirectToAction("Error");
}
}
public async Task<IActionResult> ExcelGenerate()
{
try {
var value = HttpContext.Session.GetString("Details");
if (value != null)
{
@ -109,8 +128,14 @@ namespace ImplementerApp.Controllers
}
return RedirectToAction("DetailWorkshopChoose");
}
catch
{
return RedirectToAction("Error");
}
}
public async Task<IActionResult> WordGenerate()
{
try {
var value = HttpContext.Session.GetString("Details");
if (value != null)
{
@ -127,8 +152,17 @@ namespace ImplementerApp.Controllers
}
return RedirectToAction("DetailWorkshopChoose");
}
catch
{
return RedirectToAction("Error");
}
}
[HttpGet]
public IActionResult DetailWorkshopReport()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg", "Home");
try
{
var value = HttpContext.Session.GetString("Details");
if (value != null)
@ -137,6 +171,11 @@ namespace ImplementerApp.Controllers
var reports = _data.GetWorkshopReports(rawReports);
return View(reports);
}
}
catch
{
return RedirectToAction("Error");
}
return View(new List<DetailWorkshopReportViewModel>());
}
public IActionResult ReportsMenu()
@ -147,7 +186,7 @@ namespace ImplementerApp.Controllers
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View();
return RedirectToAction("IndexNonReg", "Home");
}
}
}