Coursach/Course/ImplementerApp/Controllers/HomeController.cs

252 lines
6.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ImplementerApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using BusinessLogic.BusinessLogic;
using Contracts.BusinessLogicsContracts;
using Contracts.ViewModels;
using DataModels.Models;
using Contracts.BindingModels;
namespace ImplementerApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly ImplementerData _data;
public HomeController(ILogger<HomeController> logger, ImplementerData data)
{
_logger = logger;
_data = data;
}
public IActionResult IndexNonReg()
{
if (UserImplementer.user == null)
return View();
return RedirectToAction("Index");
}
public IActionResult Index()
{
if (UserImplementer.user == null)
return RedirectToAction("IndexNonReg");
return View();
}
[HttpGet]
public IActionResult Enter()
{
if (UserImplementer.user == null)
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();
}
[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<DetailViewModel>());
}
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 (UserImplementer.user != null) {
var products = _data.GetProducts(UserImplementer.user.Id);
return View(products);
}
return RedirectToAction("IndexNonReg");
}
public IActionResult CreateProduct()
{
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);
}
[HttpGet]
public IActionResult IndexProduction()
{
if (UserImplementer.user != null)
{
var productions = _data.GetProductions(UserImplementer.user.Id);
return View(productions);
}
return RedirectToAction("IndexNonReg");
}
public IActionResult CreateProduction()
{
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);
}
public IActionResult Privacy()
{
ImplementerViewModel user = new()
{
Email = "mail@mail.ru",
Login = "Login",
Password = "password",
Name = "User"
};
return View(user);
}
public IActionResult DetailTimeReport()
{
List<DetailTimeReport> detailTimeReports = new List<DetailTimeReport>
{
new DetailTimeReport
{
DetailName = "Деталь А",
Productions = new List<string> { "Производство 1", "Производство 2" },
Products = new List<string> { "Машина X", "Машина Y" }
},
new DetailTimeReport
{
DetailName = "Деталь B",
Productions = new List<string> { "Производство 3", "Производство 4" },
Products = new List<string> { "Машина Z", "Машина W" }
}
};
return View(detailTimeReports);
}
public IActionResult DetailWorkshopReport()
{
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);
}
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);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}