diff --git a/CarCenter/CarCenterAdministratorAPP/AdministratorData.cs b/CarCenter/CarCenterAdministratorAPP/AdministratorData.cs new file mode 100644 index 0000000..bc20a77 --- /dev/null +++ b/CarCenter/CarCenterAdministratorAPP/AdministratorData.cs @@ -0,0 +1,135 @@ +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.ViewModels; +using CarCenterContracts.BindingModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.SearchModels; +using CarCenterDataBaseImplement.Models; + +namespace AdministratorApp +{ + public class AdministratorData + { + private readonly ILogger _logger; + private readonly IAdministratorLogic _administratorLogic; + private readonly ICarSalesLogic _carSaleLogic; + private readonly ICompletionsLogic _completionsLogic; + private readonly IInspectionLogic _inspectionLogic; + private readonly IEmployeeLogic _employeeLogic; + + public AdministratorData(ILogger logger, IAdministratorLogic AdministratorLogic, ICarSalesLogic CarSaleLogic, ICompletionsLogic CompletionsLogic, IInspectionLogic InspectionLogic, IEmployeeLogic EmployeeLogic) + { + _logger = logger; + _administratorLogic = AdministratorLogic; + _carSaleLogic = CarSaleLogic; + _completionsLogic = CompletionsLogic; + _inspectionLogic = InspectionLogic; + _employeeLogic = EmployeeLogic; + } + + public AdministratorViewModel? Login(string login, string password) + { + return _administratorLogic.ReadElement(new() + { + AdministratorLogin = login, + AdministratorPassword = password + }); + } + public bool Register(AdministratorBindingModel model) + { + return _administratorLogic.Create(model); + } + public bool UpdateUser(AdministratorBindingModel model) + { + return _administratorLogic.Update(model); + } + + public List? GetCarSales(int administratorId) + { + return _carSaleLogic.ReadList(new CarSalesSearchModel() { AdministratorId = administratorId }); + } + public bool DeleteCarSale(int CarSaleId) + { + return _carSaleLogic.Delete(new() { Id = CarSaleId }); + } + public bool CreateCarSale(CarSalesBindingModel model) + { + return _carSaleLogic.Create(model); + } + public bool UpdateCarSale(CarSalesBindingModel model) + { + return _carSaleLogic.Update(model); + } + public CarSalesViewModel? GetCarSale(int id) + { + return _carSaleLogic.ReadElement(new() { Id= id }); + } + + public List? GetInspections(int administratorId) + { + return _inspectionLogic.ReadList(new InspectionSearchModel() { AdministratorId = administratorId }); + } + public InspectionViewModel? GetInspection(int id) + { + return _inspectionLogic.ReadElement(new() { Id = id }); + } + public bool UpdateInspection(InspectionBindingModel model) + { + return _inspectionLogic.Update(model); + } + public bool DeleteInspection(int inspectionId) + { + return _inspectionLogic.Delete(new() { Id = inspectionId }); + } + public bool CreateInspection(InspectionBindingModel model) + { + return _inspectionLogic.Create(model); + } + + public List? GetCompletionss(int administratorId) + { + return _completionsLogic.ReadList(new() { AdministratorId = administratorId }); + } + public CompletionsViewModel? GetCompletions(int id) + { + return _completionsLogic.ReadElement(new() { Id = id }); + } + public bool CreateCompletions(CompletionsBindingModel model) + { + return _completionsLogic.Create(model); + } + public bool UpdateCompletions(CompletionsBindingModel model) + { + return _completionsLogic.Update(model); + } + public bool DeleteCompletions(int CompletionsId) + { + return _completionsLogic.Delete(new() { Id = CompletionsId}); + } + + public List? GetEmployees() + { + return _employeeLogic.ReadList(null); + } + + public List GetTimeReport(DateTime? startDate, DateTime? endDate, int administratorId) + { + var CarSales = _carSaleLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, AdministratorId = administratorId }); + if (CarSales == null) + return new(); + List CarSaleTimeReports = new List(); + foreach (var CarSale in CarSales) + { + var report = new CarsPeriodReportViewModel(); + report.CarBrand = CarSale.CarBrand; + var Inspections = _inspectionLogic.ReadList(new() { CarSalesId = CarSale.Id, AdministratorId = administratorId }); + if (Inspections != null) + report.Inspections = Inspections.Select(p => p.InspectionName).ToList(); + var Completions = _completionsLogic.ReadList(new() { CarSalesId = CarSale.Id, AdministratorId = administratorId }); + if (Completions != null) + report.Completions = Completions.Select(p => p.СompletionName).ToList(); + CarSaleTimeReports.Add(report); + } + return CarSaleTimeReports; + } + } +} diff --git a/CarCenter/CarCenterAdministratorAPP/CarCenterAdministratorAPP.csproj b/CarCenter/CarCenterAdministratorAPP/CarCenterAdministratorAPP.csproj index 2dcd59b..43249c5 100644 --- a/CarCenter/CarCenterAdministratorAPP/CarCenterAdministratorAPP.csproj +++ b/CarCenter/CarCenterAdministratorAPP/CarCenterAdministratorAPP.csproj @@ -7,7 +7,9 @@ - + + + diff --git a/CarCenter/CarCenterAdministratorAPP/Controllers/HomeController.cs b/CarCenter/CarCenterAdministratorAPP/Controllers/HomeController.cs index afe4b46..27f9cb6 100644 --- a/CarCenter/CarCenterAdministratorAPP/Controllers/HomeController.cs +++ b/CarCenter/CarCenterAdministratorAPP/Controllers/HomeController.cs @@ -1,200 +1,354 @@ -using CarCenterAdministratorAPP.Models; +using AdministratorApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using CarCenterBusinessLogic.BusinessLogics; using CarCenterContracts.BusinessLogicsContracts; using CarCenterContracts.ViewModels; using CarCenterDataModels.Models; +using CarCenterContracts.BindingModels; using CarCenterDataBaseImplement.Models; -namespace ImplementerApp.Controllers +namespace AdministratorApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; - private readonly ICompletionsLogic _completionsLogic; - private readonly IAdministratorLogic _adminLogic; - private readonly ICarSalesLogic _carLogic; - private readonly IInspectionLogic _inspectionLogic; - - - public HomeController(ILogger logger) + private readonly AdministratorData _data; + public HomeController(ILogger logger, AdministratorData data) { _logger = logger; + _data = data; + } + private bool IsLoggedIn { get { return UserAdministrator.admin != null; } } + private int AdminId { get { return UserAdministrator.admin!.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() { - return View(); + if (!IsLoggedIn) + return View(); + return RedirectToAction("Index"); } + [HttpPost] + public void Enter(string login, string password) + { + var admin = _data.Login(login, password); + if (admin != null) + { + UserAdministrator.admin = admin; + Response.Redirect("Index"); + } + } + [HttpGet] public IActionResult Register() { return View(); } - public IActionResult IndexCompletions() + public IActionResult Logout() { - List completions = new List(); - completions.Add(new CompletionsViewModel - { - Id = 1, - СompletionName = "Name1", - СompletionFeatures = "Feature1", - СompletionPrice = 500.0, - AdministratorId = 1, - СompletionCars = new() - }); - completions.Add(new CompletionsViewModel - { - Id = 2, - СompletionName = "Name2", - СompletionFeatures = "Feature2", - СompletionPrice = 1000.0, - AdministratorId = 2 - }); - return View(completions); + UserAdministrator.admin = null; + return RedirectToAction("IndexNonReg"); } - public IActionResult CreateCompletions() + [HttpPost] + public void Register(string fio, string login, string email, string number, string password1, string password2) { - var cars = new List(); - cars.Add(new CarSalesViewModel + if (password1 == password2 && _data.Register(new() { AdministratorEmail = email, AdministratorLogin = login, AdministratorFIO = fio, AdministratorNumber = number, AdministratorPassword = password1 })) { - Id = 1, - CarBrand = "Brand1", - CarModel = "Model1", - CarCost = 50000.9, - AdministratorId = 1 - }); - cars.Add(new CarSalesViewModel - { - Id = 2, - CarBrand = "Brand2", - CarModel = "Model2", - CarCost = 100000.9, - AdministratorId = 2 - }); - return View(cars); + Response.Redirect("Index"); + } } - + [HttpGet] public IActionResult IndexCarSales() { - var cars = new List(); - cars.Add(new CarSalesViewModel + if (UserAdministrator.admin != null) { - Id = 1, - CarBrand = "Brand1", - CarModel = "Model1", - CarCost = 50000.9, - AdministratorId = 1 - }); - cars.Add(new CarSalesViewModel - { - Id = 2, - CarBrand = "Brand2", - CarModel = "Model2", - CarCost = 100000.9, - AdministratorId = 2 - }); - return View(cars); + var list = _data.GetCarSales(UserAdministrator.admin.Id); + if (list != null) + return View(list); + return View(new List()); + } + return RedirectToAction("IndexNonReg"); } - public IActionResult CreateCarSales() + [HttpPost] + public void IndexCarSales(int id) { - return View(); + if (UserAdministrator.admin != null) + { + _data.DeleteCarSale(id); + } + Response.Redirect("IndexCarSales"); } - public IActionResult IndexInspection() + [HttpGet] + public IActionResult CreateCarSales(int id) { - List inspections = new List(); - inspections.Add(new InspectionViewModel + if (id != 0) { - Id = 1, - InspectionName = "Inspection1", - InspectionCost = 100.5, - InspectionDate = DateTime.Now, - AdministratorId = 1, - EmployeeId = 1, - InspectionCars = new() - }); - inspections.Add(new InspectionViewModel - { - Id = 2, - InspectionName = "Inspection2", - InspectionCost = 1000.0, - InspectionDate = DateTime.Now, - AdministratorId = 2, - EmployeeId = 2, - InspectionCars = new() - }); - return View(inspections); + var value = _data.GetCarSale(id); + if (value != null) + return View(value); + } + return View(new CarSalesViewModel()); } - public IActionResult CreateInspection() + [HttpPost] + public IActionResult CreateCarSales(int id, string brand, string model, double cost) { - var cars = new List(); - cars.Add(new CarSalesViewModel + CarSalesBindingModel models = new CarSalesBindingModel(); + models.Id = id; + models.CarBrand = brand; + models.CarModel = model; + models.CarCost = cost; + if (models.Id == 0) { - Id = 1, - CarBrand = "Brand1", - CarModel = "Model1", - CarCost = 50000.9, - AdministratorId = 1 - }); - cars.Add(new CarSalesViewModel + models.DateCreate = DateTime.Now; + models.AdministratorId = UserAdministrator.admin!.Id; + if (_data.CreateCarSale(models)) + return RedirectToAction("IndexCarSales"); + } + else { - Id = 2, - CarBrand = "Brand2", - CarModel = "Model2", - CarCost = 100000.9, - AdministratorId = 2 - }); - return View(cars); - } - public IActionResult Privacy() - { + if (_data.UpdateCarSale(models)) + return RedirectToAction("IndexCarSales"); + } return View(); } + + [HttpGet] + public IActionResult IndexInspection() + { + if (IsLoggedIn) + { + var Inspections = _data.GetInspections(UserAdministrator.admin!.Id); + return View(Inspections); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult IndexInspection(int id) + { + _data.DeleteInspection(id); + return RedirectToAction("IndexInspection"); + } + [HttpGet] + public IActionResult CreateInspection(int id) + { + var CarSales = _data.GetCarSales(UserAdministrator.admin!.Id); + ViewBag.AllCarSales = CarSales; + if (id != 0) + { + var value = _data.GetInspection(id); + if (value != null) + return View(value); + } + return View(new InspectionViewModel()); + } + [HttpPost] + public IActionResult CreateInspection(int id, string name, int[] CarSaleIds) + { + InspectionBindingModel model = new InspectionBindingModel(); + model.Id = id; + model.InspectionName = name; + model.AdministratorId = UserAdministrator.admin!.Id; + var CarSales = _data.GetCarSales(UserAdministrator.admin!.Id); + double sum = 0; + for (int i = 0; i < CarSaleIds.Length; i++) + { + var CarSale = CarSales!.FirstOrDefault(x => x.Id == CarSaleIds[i])!; + model.InspectionCars[CarSaleIds[i]] = (CarSale); + sum += CarSale.CarCost; + } + if (model.InspectionCars.Count == 0) + return RedirectToAction("IndexInspection"); + model.InspectionCost = sum; + if (id != 0) + { + _data.UpdateInspection(model); + } + else + { + _data.CreateInspection(model); + } + return RedirectToAction("IndexInspection"); + } + [HttpGet] + public IActionResult IndexCompletions() + { + if (UserAdministrator.admin != null) + { + var Completionss = _data.GetCompletionss(UserAdministrator.admin.Id); + return View(Completionss); + } + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult IndexCompletions(int id) + { + _data.DeleteCompletions(id); + return RedirectToAction("IndexCompletions"); + } + [HttpGet] + public IActionResult CreateCompletions(int id) + { + var CarSales = _data.GetCarSales(UserAdministrator.admin!.Id); + ViewBag.AllCarSales = CarSales; + if (id != 0) + { + var value = _data.GetCompletions(id); + if (value != null) + return View(value); + } + return View(new CompletionsViewModel()); + } + [HttpPost] + public IActionResult CreateCompletions(int id, string name, string features, int[] CarSaleIds) + { + CompletionsBindingModel model = new CompletionsBindingModel(); + model.Id = id; + model.СompletionName = name; + model.СompletionFeatures = features; + model.AdministratorId = UserAdministrator.admin!.Id; + var CarSales = _data.GetCarSales(UserAdministrator.admin!.Id); + double sum = 0; + for (int i = 0; i < CarSaleIds.Length; i++) + { + var CarSale = CarSales!.FirstOrDefault(x => x.Id == CarSaleIds[i])!; + model.СompletionCars[CarSaleIds[i]] = CarSale; + sum += CarSale.CarCost; + } + model.СompletionPrice = sum; + bool changed = false; + if (model.СompletionCars.Count > 0) + { + if (id != 0) + { + changed = _data.UpdateCompletions(model); + } + else + { + changed = _data.CreateCompletions(model); + } + } + if (changed) + return RedirectToAction("IndexCompletions"); + else + { + ViewBag.AllCarSales = CarSales; + return View(model); + } + } + [HttpGet] + public IActionResult Privacy() + { + if (IsLoggedIn) + return View(UserAdministrator.admin); + return RedirectToAction("IndexNonReg"); + } + [HttpPost] + public IActionResult Privacy(int id, string login, string email, string password, string fio, string number) + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + AdministratorBindingModel user = new() { Id = id, AdministratorLogin = login, AdministratorEmail = email, AdministratorPassword = password, AdministratorFIO = fio, AdministratorNumber = number }; + if (_data.UpdateUser(user)) + { + UserAdministrator.admin = new AdministratorViewModel { Id = id, AdministratorLogin = login, AdministratorPassword = password, AdministratorFIO = fio, AdministratorEmail = email, AdministratorNumber = number }; + } + return View(user); + } + [HttpGet] + public IActionResult CarSaleTimeChoose() + { + 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("CarSaleTimeReport"); + } + [HttpGet] + public IActionResult CarSaleTimeReport() + { + 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, AdminId); + + ViewBag.StartDate = startDate; + ViewBag.EndDate = endDate; + + return View(values); + } + public IActionResult CarsPreSaleWorkReport() + { + List CarSalePreSaleWorkReports = new List + { + new CarsPreSaleWorkReportViewModel + { + CarBrand = "бэха", + PreSaleWork = new List { "Цех 1", "Цех 2" } + }, + new CarsPreSaleWorkReportViewModel + { + CarBrand = "мерс", + PreSaleWork = new List { "Цех 3", "Цех 4" } + } + }; + return View(CarSalePreSaleWorkReports); + } public IActionResult ReportsMenu() { return View(); } - - public IActionResult CarsPreSaleWorkReport() + [HttpGet] + public IActionResult InspectionEmployeeAdd(int id) { - List CarsPreSaleWork = new List - { - new CarsPreSaleWorkReportViewModel - { - CarBrand = "CarBrand1", - PreSaleWork = new List { "PreSaleWork1", "PreSaleWork2" }, - }, - new CarsPreSaleWorkReportViewModel - { - CarBrand = "CarBrand2", - PreSaleWork = new List { "PreSaleWork3", "PreSaleWork4" }, - } - }; - return View(CarsPreSaleWork); + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var Inspection = _data.GetInspection(id); + ViewBag.Inspection = Inspection; + var Employees = _data.GetEmployees(); + return View(Employees); } - public IActionResult CarsPeriodReport() + [HttpPost] + public IActionResult InspectionEmployeeAdd(int InspectionId, int EmployeeId) { - List CarsPeriod = new List - { - new CarsPeriodReportViewModel - { - CarBrand = "CarBrand1", - Completions = new List { "Completions1", "Completions2" }, - Employees = new List { "Employees1", "Employees2" }, - }, - new CarsPeriodReportViewModel - { - CarBrand = "CarBrand2", - Completions = new List { "Completions3", "Completions4" }, - Employees = new List { "Employees3", "Employees4" }, - } - }; - return View(CarsPeriod); + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var Inspection = _data.GetInspection(InspectionId); + if (Inspection == null) + return RedirectToAction("Index"); + InspectionBindingModel InspectionBinding = new() { Id = InspectionId, InspectionCost = Inspection.InspectionCost, InspectionName = Inspection.InspectionName, AdministratorId = Inspection.AdministratorId, InspectionCars = Inspection.InspectionCars, EmployeeId = EmployeeId }; + _data.UpdateInspection(InspectionBinding); + return RedirectToAction("IndexInspection"); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] diff --git a/CarCenter/CarCenterAdministratorAPP/Models/ErrorViewModel.cs b/CarCenter/CarCenterAdministratorAPP/Models/ErrorViewModel.cs index 75e7cd9..f1a1405 100644 --- a/CarCenter/CarCenterAdministratorAPP/Models/ErrorViewModel.cs +++ b/CarCenter/CarCenterAdministratorAPP/Models/ErrorViewModel.cs @@ -1,4 +1,4 @@ -namespace CarCenterAdministratorAPP.Models +namespace AdministratorApp.Models { public class ErrorViewModel { diff --git a/CarCenter/CarCenterAdministratorAPP/Program.cs b/CarCenter/CarCenterAdministratorAPP/Program.cs index 0727468..001aa48 100644 --- a/CarCenter/CarCenterAdministratorAPP/Program.cs +++ b/CarCenter/CarCenterAdministratorAPP/Program.cs @@ -1,15 +1,42 @@ +using CarCenterBusinessLogic.BusinessLogics; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.StoragesContracts; +using CarCenterDataBaseImplement.Implements; +using CarCenterDataBaseImplement.Implemets; +using AdministratorApp; +using Microsoft.Extensions.Options; + var builder = WebApplication.CreateBuilder(args); -// Add services to the container. -builder.Services.AddControllersWithViews(); +builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation(); + +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(); -// Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } @@ -17,11 +44,11 @@ app.UseHttpsRedirection(); 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/CarCenter/CarCenterAdministratorAPP/UserAdministrator.cs b/CarCenter/CarCenterAdministratorAPP/UserAdministrator.cs new file mode 100644 index 0000000..b81523c --- /dev/null +++ b/CarCenter/CarCenterAdministratorAPP/UserAdministrator.cs @@ -0,0 +1,9 @@ +using CarCenterContracts.ViewModels; + +namespace AdministratorApp +{ + public static class UserAdministrator + { + public static AdministratorViewModel? admin { get; set; } + } +} diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Home/CarsPeriodReport.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Home/CarsPeriodReport.cshtml index 2b760de..f27a372 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/Home/CarsPeriodReport.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/Home/CarsPeriodReport.cshtml @@ -37,12 +37,7 @@ -
    - @foreach (var employee in cars.Employees) - { -
  • @employee
  • - } -
+ } diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCarSales.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCarSales.cshtml index fab555b..6dd8389 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCarSales.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCarSales.cshtml @@ -1,24 +1,70 @@ -@{ - ViewData["Title"] = "CreateCarSales"; +@using CarCenterContracts.ViewModels; +@{ + ViewData["Title"] = "CreateCar"; } +@model CarSalesViewModel;
-

Создание продаваемой машины

+

Продаваемая машина

-
-
-
Производитель:
-
-
-
-
Модель:
-
-
-
-
Стоимость:
-
-
-
-
-
-
-
\ No newline at end of file +
+ +
+
Бренд машины:
+
+ + +
+
+
+
Модель машины:
+
+ + +
+
+
+
Стоимость:
+
+ + +
+
+
+
+
+
+
+ + + diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCompletions.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCompletions.cshtml index cc5e60d..57a417c 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCompletions.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/Home/CreateCompletions.cshtml @@ -1,41 +1,70 @@ @using CarCenterContracts.ViewModels -@model List +@model CompletionsViewModel @{ - ViewData["Title"] = "CreateCompletions"; + ViewData["Title"] = "CreateProduction"; + ViewBag.Cars = Model.СompletionCars; }
-

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

+

Создание комплектации

-
+
-
Название:
-
+
Название комплектации:
+
+ + +
+
Особенности комплектации:
+
+ + +
-
Completions
+
Машины
- - + + + + - @foreach (var cars in Model) + @foreach (var car in ViewBag.cars) { - + - + + + }
ВыборНазваниеБрендМодельСтоимостьУдалить
- + + @car.Value.CarBrand @cars.CarBrand + + @car.Value.CarModel + @car.Value.CarCost
+ + +
+
+
Сумма:
+
diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Home/IndexCarSales.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Home/IndexCarSales.cshtml index 831d95d..ecbb066 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/Home/IndexCarSales.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/Home/IndexCarSales.cshtml @@ -61,7 +61,10 @@ Изменить - Удалить + + + + } diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Home/IndexNonReg.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Home/IndexNonReg.cshtml new file mode 100644 index 0000000..3d737d5 --- /dev/null +++ b/CarCenter/CarCenterAdministratorAPP/Views/Home/IndexNonReg.cshtml @@ -0,0 +1,10 @@ +@{ + ViewData["Title"] = "Home Page"; +} + + diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Home/Privacy.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Home/Privacy.cshtml index af4fb19..226bcbf 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/Home/Privacy.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/Home/Privacy.cshtml @@ -1,6 +1,119 @@ @{ ViewData["Title"] = "Privacy Policy"; } -

@ViewData["Title"]

-

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

+
+

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

+
+
+
+
Имя:
+
+ + +
+
+
+
Логин:
+
+ + +
+
+
+
Почта:
+
+ + +
+
+
+
Номер телефона:
+
+ + +
+
+
+
Пароль:
+
+ + +
+
+
+
Повтор пароля:
+
+ + +
+
+
+
+
+
+
+ + + diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Home/Register.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Home/Register.cshtml index 837b222..a636035 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/Home/Register.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/Home/Register.cshtml @@ -1,29 +1,119 @@ @{ - ViewData["Title"] = "Register"; + ViewData["Title"] = "Register"; }
-

Регистрация

+

Регистрация

-
-
-
ФИО:
-
-
-
-
Логин:
-
-
-
-
Почта:
-
-
-
-
Пароль:
-
-
-
-
-
-
-
\ No newline at end of file +
+
+
ФИО:
+
+ + +
+
+
+
Логин:
+
+ + +
+
+
+
Почта:
+
+ + +
+
+
+
Номер телефона:
+
+ + +
+
+
+
Пароль:
+
+ + +
+
+
+
Повтор пароля:
+
+ + +
+
+
+
+
+
+
+ + + diff --git a/CarCenter/CarCenterAdministratorAPP/Views/Shared/_Layout.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/Shared/_Layout.cshtml index 330893b..c3cf25b 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/Shared/_Layout.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/Shared/_Layout.cshtml @@ -1,4 +1,7 @@ - +@{ + ViewData["Login"] = UserAdministrator.admin == null ? "Пользователь" : UserAdministrator.admin.AdministratorLogin; +} + @@ -12,7 +15,9 @@
diff --git a/CarCenter/CarCenterAdministratorAPP/Views/_ViewImports.cshtml b/CarCenter/CarCenterAdministratorAPP/Views/_ViewImports.cshtml index f808249..21b4e9e 100644 --- a/CarCenter/CarCenterAdministratorAPP/Views/_ViewImports.cshtml +++ b/CarCenter/CarCenterAdministratorAPP/Views/_ViewImports.cshtml @@ -1,3 +1,3 @@ -@using CarCenterAdministratorAPP -@using CarCenterAdministratorAPP.Models +@using AdministratorApp +@using AdministratorApp.Models @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/CarCenter/CarCenterAdministratorAPP/log4net.config b/CarCenter/CarCenterAdministratorAPP/log4net.config new file mode 100644 index 0000000..1fd1998 --- /dev/null +++ b/CarCenter/CarCenterAdministratorAPP/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/AdministratorLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/AdministratorLogic.cs index 8d3f660..461190d 100644 --- a/CarCenter/CarCenterBusinessLogic/BusinessLogics/AdministratorLogic.cs +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/AdministratorLogic.cs @@ -53,7 +53,7 @@ namespace CarCenterBusinessLogic.BusinessLogics return true; } - public AdministratorViewModel? ReadElement(AdministratorSearchModel model) + public AdministratorViewModel? ReadElement(AdministratorSearchModel? model) { if (model == null) { diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs index 4e5a969..4c20fd3 100644 --- a/CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -13,13 +13,11 @@ namespace CarCenterBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IEmployeeStorage _employeeStorage; - private readonly IManagerLogic _managerLogic; - public EmployeeLogic(ILogger logger, IEmployeeStorage EmployeeStorage, IManagerLogic ManagerLogic) + public EmployeeLogic(ILogger logger, IEmployeeStorage EmployeeStorage) { _logger = logger; _employeeStorage = EmployeeStorage; - _managerLogic = ManagerLogic; } public bool Create(EmployeeBindingModel model) { diff --git a/CarCenter/CarCenterContracts/ViewModels/CarsPeriodReportViewModel.cs b/CarCenter/CarCenterContracts/ViewModels/CarsPeriodReportViewModel.cs index f2f2d70..26d2f03 100644 --- a/CarCenter/CarCenterContracts/ViewModels/CarsPeriodReportViewModel.cs +++ b/CarCenter/CarCenterContracts/ViewModels/CarsPeriodReportViewModel.cs @@ -10,6 +10,6 @@ namespace CarCenterContracts.ViewModels { public string CarBrand { get; set; } = string.Empty; public List Completions { get; set; } = new(); - public List Employees { get; set; } = new(); + public List Inspections { get; set; } = new(); } } diff --git a/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs b/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs index bcab7d9..56119d9 100644 --- a/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs +++ b/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs @@ -9,7 +9,7 @@ namespace CarCenterDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter2;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); diff --git a/CarCenter/CarCenterDataBaseImplement/Implements/AdministratorStorage.cs b/CarCenter/CarCenterDataBaseImplement/Implements/AdministratorStorage.cs index e965e31..f71b889 100644 --- a/CarCenter/CarCenterDataBaseImplement/Implements/AdministratorStorage.cs +++ b/CarCenter/CarCenterDataBaseImplement/Implements/AdministratorStorage.cs @@ -6,6 +6,7 @@ using CarCenterDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,114 +15,65 @@ namespace CarCenterDataBaseImplement.Implements { public class AdministratorStorage : IAdministratorStorage { - public List GetFullList() + public AdministratorViewModel? Delete(AdministratorBindingModel model) { using var context = new CarCenterDataBase(); - - return context.Administrators - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFilteredList(AdministratorSearchModel model) - { - if (string.IsNullOrEmpty(model.AdministratorFIO)) - { - return new(); - } - - using var context = new CarCenterDataBase(); - - return context.Administrators - .Include(x => x.Inspections) - .Include(x => x.Cars) - .Include(x => x.Equipments) - .Where(x => x.AdministratorLogin.Contains(model.AdministratorLogin) && x.AdministratorPassword == model.AdministratorPassword) - .Select(x => x.GetViewModel) - .ToList(); + var newAdministrator = context.Administrators.FirstOrDefault(x => x.Id == model.Id); + if (newAdministrator == null) + return null; + context.Administrators.Remove(newAdministrator); + context.SaveChanges(); + return newAdministrator.GetViewModel; } public AdministratorViewModel? GetElement(AdministratorSearchModel model) { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.AdministratorLogin)) { return null; } using var context = new CarCenterDataBase(); + return context.Administrators.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.AdministratorLogin) && !string.IsNullOrEmpty(model.AdministratorPassword) && x.AdministratorLogin.Equals(model.AdministratorLogin) && x.AdministratorPassword.Equals(model.AdministratorPassword)))?.GetViewModel; ; + } + public List GetFilteredList(AdministratorSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.AdministratorLogin)) + return new(); + using var context = new CarCenterDataBase(); if (model.Id.HasValue) - return context.Administrators - .Include(x => x.Inspections) - .Include(x => x.Cars) - .Include(x => x.Equipments) - .FirstOrDefault(x => x.Id == model.Id)? - .GetViewModel; + { + return context.Administrators.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + else + { + return context.Administrators.Where(x => x.AdministratorLogin.Equals(model.AdministratorLogin)).Select(x => x.GetViewModel).ToList(); + } + } - if (!string.IsNullOrEmpty(model.AdministratorEmail) && !string.IsNullOrEmpty(model.AdministratorPassword)) - return context.Administrators - .Include(x => x.Inspections) - .Include(x => x.Cars) - .Include(x => x.Equipments) - .FirstOrDefault(x => x.AdministratorEmail.Equals(model.AdministratorEmail) && x.AdministratorPassword.Equals(model.AdministratorPassword))? - .GetViewModel; - - if (!string.IsNullOrEmpty(model.AdministratorEmail)) - return context.Administrators - .Include(x => x.Inspections) - .Include(x => x.Cars) - .Include(x => x.Equipments) - .FirstOrDefault(x => x.AdministratorEmail.Equals(model.AdministratorEmail))? - .GetViewModel; - - return null; + public List GetFullList() + { + using var context = new CarCenterDataBase(); + return context.Administrators.Select(x => x.GetViewModel).ToList(); } public AdministratorViewModel? Insert(AdministratorBindingModel model) { - var newAdministrator = Administrator.Create(model); - - if (newAdministrator == null) - { - return null; - } - using var context = new CarCenterDataBase(); - + var newAdministrator = Administrator.Create(model); + if (newAdministrator == null) + return null; context.Administrators.Add(newAdministrator); context.SaveChanges(); - return newAdministrator.GetViewModel; } public AdministratorViewModel? Update(AdministratorBindingModel model) { using var context = new CarCenterDataBase(); - - var administrator = context.Administrators - .FirstOrDefault(x => x.Id == model.Id); - - if (administrator == null) - { + var newAdministrator = context.Administrators.FirstOrDefault(x => x.Id == model.Id); + if (newAdministrator == null) return null; - } - - administrator.Update(model); + newAdministrator.Update(model); context.SaveChanges(); - - return administrator.GetViewModel; - } - - public AdministratorViewModel? Delete(AdministratorBindingModel model) - { - using var context = new CarCenterDataBase(); - - var element = context.Administrators.FirstOrDefault(rec => rec.Id == model.Id); - - if (element != null) - { - context.Administrators.Remove(element); - context.SaveChanges(); - - return element.GetViewModel; - } - - return null; + return newAdministrator.GetViewModel; } } } diff --git a/CarCenter/CarCenterDataBaseImplement/Migrations/20240527163409_InitialCreate.Designer.cs b/CarCenter/CarCenterDataBaseImplement/Migrations/20240527184458_InitialCreate.Designer.cs similarity index 99% rename from CarCenter/CarCenterDataBaseImplement/Migrations/20240527163409_InitialCreate.Designer.cs rename to CarCenter/CarCenterDataBaseImplement/Migrations/20240527184458_InitialCreate.Designer.cs index 1604173..9bb093f 100644 --- a/CarCenter/CarCenterDataBaseImplement/Migrations/20240527163409_InitialCreate.Designer.cs +++ b/CarCenter/CarCenterDataBaseImplement/Migrations/20240527184458_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace CarCenterDataBaseImplement.Migrations { [DbContext(typeof(CarCenterDataBase))] - [Migration("20240527163409_InitialCreate")] + [Migration("20240527184458_InitialCreate")] partial class InitialCreate { /// diff --git a/CarCenter/CarCenterDataBaseImplement/Migrations/20240527163409_InitialCreate.cs b/CarCenter/CarCenterDataBaseImplement/Migrations/20240527184458_InitialCreate.cs similarity index 100% rename from CarCenter/CarCenterDataBaseImplement/Migrations/20240527163409_InitialCreate.cs rename to CarCenter/CarCenterDataBaseImplement/Migrations/20240527184458_InitialCreate.cs