diff --git a/Course/Contracts/ViewModels/MachineWorkshopTimeReport.cs b/Course/Contracts/ViewModels/MachineWorkshopTimeReport.cs new file mode 100644 index 0000000..4f1fbac --- /dev/null +++ b/Course/Contracts/ViewModels/MachineWorkshopTimeReport.cs @@ -0,0 +1,9 @@ + +namespace Contracts.ViewModels +{ + public class MachineWorkshopTimeReport + { + public string WorkshopName { get; set; } = string.Empty; + public List Machines { get; set; } = new(); + } +} diff --git a/Course/Contracts/ViewModels/WorkerProductReportViewModel.cs b/Course/Contracts/ViewModels/WorkerProductReportViewModel.cs new file mode 100644 index 0000000..3f31284 --- /dev/null +++ b/Course/Contracts/ViewModels/WorkerProductReportViewModel.cs @@ -0,0 +1,9 @@ + +namespace Contracts.ViewModels +{ + public class WorkerProductReportViewModel + { + public string WorkerName { get; set; } = string.Empty; + public List Products { get; set; } = new(); + } +} diff --git a/Course/DatabaseImplement/Implements/MachineStorage.cs b/Course/DatabaseImplement/Implements/MachineStorage.cs index 2bf4a81..4808a36 100644 --- a/Course/DatabaseImplement/Implements/MachineStorage.cs +++ b/Course/DatabaseImplement/Implements/MachineStorage.cs @@ -3,6 +3,7 @@ using Contracts.SearchModels; using Contracts.StoragesContracts; using Contracts.ViewModels; using DatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace DatabaseImplement.Implements { @@ -14,6 +15,7 @@ namespace DatabaseImplement.Implements var newMachine = context.Machines.FirstOrDefault(x => x.Id == model.Id); if (newMachine == null) return null; + newMachine.UpdateWorkers(context, model); context.Machines.Remove(newMachine); context.SaveChanges(); return newMachine.GetViewModel; @@ -22,35 +24,24 @@ namespace DatabaseImplement.Implements public MachineViewModel? GetElement(MachineSearchModel model) { using var context = new FactoryGoWorkDatabase(); - return context.Machines.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } + return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } public List GetFilteredList(MachineSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Title) && !model.UserId.HasValue) + if (!model.UserId.HasValue) { return new(); } using var context = new FactoryGoWorkDatabase(); - if (model.Id.HasValue) - { - return context.Machines.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); - } - else if (model.UserId.HasValue) - { - return context.Machines.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); - } - else - { - return context.Machines.Where(x => model.Title == x.Title).Select(x => x.GetViewModel).ToList(); - } - } + return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); + } public List GetFullList() { using var context = new FactoryGoWorkDatabase(); - return context.Machines.Select(x => x.GetViewModel).ToList(); - } + return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).Select(x => x.GetViewModel).ToList(); + } public MachineViewModel? Insert(MachineBindingModel model) { @@ -70,6 +61,7 @@ namespace DatabaseImplement.Implements if (newMachine == null) return null; newMachine.Update(model); + newMachine.UpdateWorkers(context, model); context.SaveChanges(); return newMachine.GetViewModel; } diff --git a/Course/DatabaseImplement/Implements/WorkerStorage.cs b/Course/DatabaseImplement/Implements/WorkerStorage.cs index 400c5be..9b14839 100644 --- a/Course/DatabaseImplement/Implements/WorkerStorage.cs +++ b/Course/DatabaseImplement/Implements/WorkerStorage.cs @@ -27,24 +27,13 @@ namespace DatabaseImplement.Implements public List GetFilteredList(WorkerSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Name) && !model.UserId.HasValue) - { - return new(); - } - using var context = new FactoryGoWorkDatabase(); - if (model.Id.HasValue) - { - return context.Workers.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); - } - else if (model.UserId.HasValue) - { - return context.Workers.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); - } - else - { - return context.Workers.Where(x => model.Name == x.Name).Select(x => x.GetViewModel).ToList(); - } - } + if (!model.UserId.HasValue) + { + return new(); + } + using var context = new FactoryGoWorkDatabase(); + return context.Workers.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); + } public List GetFullList() { diff --git a/Course/DatabaseImplement/Implements/WorkshopStorage.cs b/Course/DatabaseImplement/Implements/WorkshopStorage.cs index 219008a..573f155 100644 --- a/Course/DatabaseImplement/Implements/WorkshopStorage.cs +++ b/Course/DatabaseImplement/Implements/WorkshopStorage.cs @@ -4,6 +4,7 @@ using Contracts.SearchModels; using Contracts.StoragesContracts; using Contracts.ViewModels; using DatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace DatabaseImplement.Implements { @@ -15,6 +16,7 @@ namespace DatabaseImplement.Implements var newWorkshop = context.Workshops.FirstOrDefault(x => x.Id == model.Id); if (newWorkshop == null) return null; + newWorkshop.UpdateWorkers(context, model); context.Workshops.Remove(newWorkshop); context.SaveChanges(); return newWorkshop.GetViewModel; @@ -23,35 +25,24 @@ namespace DatabaseImplement.Implements public WorkshopViewModel? GetElement(WorkshopSearchModel model) { using var context = new FactoryGoWorkDatabase(); - return context.Workshops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } + return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && x.Title.Contains(model.Title)) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } public List GetFilteredList(WorkshopSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Title) && !model.UserId.HasValue) + if (!model.UserId.HasValue) { return new(); } using var context = new FactoryGoWorkDatabase(); - if (model.Id.HasValue) - { - return context.Workshops.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); - } - else if (model.UserId.HasValue) - { - return context.Workshops.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); - } - else - { - return context.Workshops.Where(x => model.Title == x.Title).Select(x => x.GetViewModel).ToList(); - } - } + return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); + } public List GetFullList() { using var context = new FactoryGoWorkDatabase(); - return context.Workshops.Select(x => x.GetViewModel).ToList(); - } + return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).Select(x => x.GetViewModel).ToList(); + } public WorkshopViewModel? Insert(WorkshopBindingModel model) { @@ -71,6 +62,7 @@ namespace DatabaseImplement.Implements if (newWorkshop == null) return null; newWorkshop.Update(model); + newWorkshop.UpdateWorkers(context, model); context.SaveChanges(); return newWorkshop.GetViewModel; } diff --git a/Course/DatabaseImplement/Models/Worker.cs b/Course/DatabaseImplement/Models/Worker.cs index 6bce5eb..55c1bac 100644 --- a/Course/DatabaseImplement/Models/Worker.cs +++ b/Course/DatabaseImplement/Models/Worker.cs @@ -57,6 +57,7 @@ namespace DatabaseImplement.Models if (model == null) return; Name = model.Name; + Birthday = model.Birthday; Specialization = model.Specialization; Salary = model.Salary; } diff --git a/Course/DatabaseImplement/Models/Workshop.cs b/Course/DatabaseImplement/Models/Workshop.cs index 94c8178..ef24b57 100644 --- a/Course/DatabaseImplement/Models/Workshop.cs +++ b/Course/DatabaseImplement/Models/Workshop.cs @@ -17,11 +17,12 @@ namespace DatabaseImplement.Models public string Director { get; set; } = string.Empty; [Required] public int UserId { get; set; } + public virtual Guarantor User { get; set; } public int? ProductionId { get; set; } public virtual Production? Production { get; set; } private Dictionary? _workerWorkshops = null; [NotMapped] - public Dictionary? WorkerWorkshops + public Dictionary WorkerWorkshops { get { diff --git a/Course/GuarantorAPP/Controllers/HomeController.cs b/Course/GuarantorAPP/Controllers/HomeController.cs index d086968..ed6b421 100644 --- a/Course/GuarantorAPP/Controllers/HomeController.cs +++ b/Course/GuarantorAPP/Controllers/HomeController.cs @@ -1,4 +1,5 @@ -using Contracts.BusinessLogicsContracts; +using AspNetCore; +using Contracts.BusinessLogicsContracts; using Contracts.ViewModels; using GuarantorAPP.Models; using Microsoft.AspNetCore.Mvc; @@ -32,15 +33,70 @@ namespace GuarantorAPP.Controllers } public IActionResult IndexMachine() { - return View(new List()); + List machines = new List + { + new MachineViewModel + { + Id = 1, + Title = "Токарный станок", + Country = "Китай", + UserId = 1 + }, + new MachineViewModel + { + Id = 2, + Title = "Фрезерный станок", + Country = "Россия", + UserId = 2 + } + }; + return View(machines); } public IActionResult CreateMachine() { - return View(); - } + var workers = new List(); + workers.Add(new WorkerViewModel + { + Id = 1, + Name = "Фролов Феодосий Валерьевич", + Birthday = new DateTime(1989, 03, 29), + Specialization = "Металлург", + Salary = 55000, + UserId = 1 + }); + workers.Add(new WorkerViewModel + { + Id = 2, + Name = "Медведков Андрей Алексеевич", + Birthday = new DateTime(2004, 02, 29), + Specialization = "Слесарь", + Salary = 25000, + UserId = 2 + }); + return View(workers); + } public IActionResult IndexWorker() { - return View(new List()); + var workers = new List(); + workers.Add(new WorkerViewModel + { + Id = 1, + Name = "Фролов Феодосий Валерьевич", + Birthday = new DateTime(1989, 03, 29), + Specialization = "Металлург", + Salary = 55000, + UserId = 1 + }); + workers.Add(new WorkerViewModel + { + Id = 2, + Name = "Медведков Андрей Алексеевич", + Birthday = new DateTime(2004, 02, 29), + Specialization = "Слесарь", + Salary = 25000, + UserId = 2 + }); + return View(workers); } public IActionResult CreateWorker() { @@ -48,16 +104,122 @@ namespace GuarantorAPP.Controllers } public IActionResult IndexWorkshop() { - return View(new List()); + List workshops = new List + { + new WorkshopViewModel + { + Id = 1, + Title = "Механический цех", + Address = "Ул. Пушкина, колотушкина", + Director = "Главный Андрей цеха", + UserId = 1, + ProductionId = 1, + }, + new WorkshopViewModel + { + Id = 2, + Title = "Сварочный цех", + Address = "Ул. Пушкина, колотушкина 22", + Director = "Фрезер Давыд Анатольевич", + UserId = 2, + ProductionId = 2, + } + }; + return View(workshops); } public IActionResult CreateWorkshop() { - return View(); - } + var workers = new List(); + workers.Add(new WorkerViewModel + { + Id = 1, + Name = "Фролов Феодосий Валерьевич", + Birthday = new DateTime(1989, 03, 29), + Specialization = "Металлург", + Salary = 55000, + UserId = 1 + }); + workers.Add(new WorkerViewModel + { + Id = 2, + Name = "Медведков Андрей Алексеевич", + Birthday = new DateTime(2004, 02, 29), + Specialization = "Слесарь", + Salary = 25000, + UserId = 2 + }); + return View(workers); + } public IActionResult Privacy() + { + GuarantorViewModel user = new() + { + Email = "mailtatar@mail.ru", + Login = "tatar", + Password = "password", + Name = "User", + }; + return View(user); + } + public IActionResult MachineWorkshopTimeReport() + { + List machineWorkshopTimeReports = new List + { + new MachineWorkshopTimeReport + { + WorkshopName = "Цех А", + Machines = new List { "Фрезерный станок", "Токарный станок" } + }, + new MachineWorkshopTimeReport + { + WorkshopName = "Цех В", + Machines = new List { "Станок А", "Станок В" } + } + }; + return View(machineWorkshopTimeReports); + } + public IActionResult WorkerProductReport() + { + List workerProductReports = new List + { + new WorkerProductReportViewModel + { + WorkerName = "Работник 1", + Products = new List { "Изделие первое", "Изделие второе" } + }, + new WorkerProductReportViewModel + { + WorkerName = "Работник 2", + Products = new List { "Изделие одно", "Изделие второе" } + } + }; + return View(workerProductReports); + } + public IActionResult ReportsMenu() { return View(); } + public IActionResult WorkshopProductionAdd() + { + List production = new List + { + new ProductionViewModel + { + Id = 1, + Name = "Производство старое", + Cost = 1, + UserId = 1, + }, + new ProductionViewModel + { + Id = 2, + Name = "Производство новое", + Cost = 2, + UserId = 2, + } + }; + return View(production); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Course/GuarantorAPP/Views/Home/MachineWorkshopTimeReport.cshtml b/Course/GuarantorAPP/Views/Home/MachineWorkshopTimeReport.cshtml new file mode 100644 index 0000000..b1baac0 --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/MachineWorkshopTimeReport.cshtml @@ -0,0 +1,41 @@ +@using Contracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Machines and Workshops on Time Reports"; +} + +
+

Список цехов и станков в диапазоне времени

+
+ +
+ +
+ + + + + + + + + + + @foreach (var workshop in Model) + { + + + + + } + +
ЦехСтанки
@workshop.WorkshopName +
    + @foreach (var machine in workshop.Machines) + { +
  • @machine
  • + } +
+
diff --git a/Course/GuarantorAPP/Views/Home/WorkerProductReport.cshtml b/Course/GuarantorAPP/Views/Home/WorkerProductReport.cshtml new file mode 100644 index 0000000..d842847 --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/WorkerProductReport.cshtml @@ -0,0 +1,42 @@ +@using Contracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Workers - Product Reports"; +} +
+

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

+
+ +
+ +
+
+ +
+ + + + + + + + + + @foreach (var worker in Model) + { + + + + + } + +
РаботникИзделие
@worker.WorkerName +
    + @foreach (var product in worker.Products) + { +
  • @product
  • + } +
+
diff --git a/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml b/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml new file mode 100644 index 0000000..6babefd --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml @@ -0,0 +1,31 @@ +@using Contracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Workshop-Add-Production"; +} + +
+

Цех - @ViewBag.Workshop

+
+ +
+

Список цехов

+
+ @foreach (var production in Model) + { +
+
+
+
@production.Name
+
+ + +
+
+
+
+ } +
+
\ No newline at end of file diff --git a/Course/GuarantorAPP/Views/Shared/_Layout.cshtml b/Course/GuarantorAPP/Views/Shared/_Layout.cshtml index a5bee38..3ff5de6 100644 --- a/Course/GuarantorAPP/Views/Shared/_Layout.cshtml +++ b/Course/GuarantorAPP/Views/Shared/_Layout.cshtml @@ -12,7 +12,8 @@