Compare commits

...

2 Commits

12 changed files with 334 additions and 64 deletions

View File

@ -0,0 +1,9 @@

namespace Contracts.ViewModels
{
public class MachineWorkshopTimeReport
{
public string WorkshopName { get; set; } = string.Empty;
public List<string> Machines { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@

namespace Contracts.ViewModels
{
public class WorkerProductReportViewModel
{
public string WorkerName { get; set; } = string.Empty;
public List<string> Products { get; set; } = new();
}
}

View File

@ -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<MachineViewModel> 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<MachineViewModel> 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;
}

View File

@ -27,24 +27,13 @@ namespace DatabaseImplement.Implements
public List<WorkerViewModel> 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<WorkerViewModel> GetFullList()
{

View File

@ -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<WorkshopViewModel> 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<WorkshopViewModel> 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;
}

View File

@ -57,6 +57,7 @@ namespace DatabaseImplement.Models
if (model == null)
return;
Name = model.Name;
Birthday = model.Birthday;
Specialization = model.Specialization;
Salary = model.Salary;
}

View File

@ -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<int, IWorkerModel>? _workerWorkshops = null;
[NotMapped]
public Dictionary<int, IWorkerModel>? WorkerWorkshops
public Dictionary<int, IWorkerModel> WorkerWorkshops
{
get
{

View File

@ -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<MachineViewModel>());
List<MachineViewModel> machines = new List<MachineViewModel>
{
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<WorkerViewModel>();
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<WorkerViewModel>());
var workers = new List<WorkerViewModel>();
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<WorkshopViewModel>());
List<WorkshopViewModel> workshops = new List<WorkshopViewModel>
{
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<WorkerViewModel>();
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<MachineWorkshopTimeReport> machineWorkshopTimeReports = new List<MachineWorkshopTimeReport>
{
new MachineWorkshopTimeReport
{
WorkshopName = "Цех А",
Machines = new List<string> { "Фрезерный станок", "Токарный станок" }
},
new MachineWorkshopTimeReport
{
WorkshopName = "Цех В",
Machines = new List<string> { "Станок А", "Станок В" }
}
};
return View(machineWorkshopTimeReports);
}
public IActionResult WorkerProductReport()
{
List<WorkerProductReportViewModel> workerProductReports = new List<WorkerProductReportViewModel>
{
new WorkerProductReportViewModel
{
WorkerName = "Работник 1",
Products = new List<string> { "Изделие первое", "Изделие второе" }
},
new WorkerProductReportViewModel
{
WorkerName = "Работник 2",
Products = new List<string> { "Изделие одно", "Изделие второе" }
}
};
return View(workerProductReports);
}
public IActionResult ReportsMenu()
{
return View();
}
public IActionResult WorkshopProductionAdd()
{
List<ProductionViewModel> production = new List<ProductionViewModel>
{
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()
{

View File

@ -0,0 +1,41 @@
@using Contracts.ViewModels
@model List<MachineWorkshopTimeReport>
@{
ViewData["Title"] = "Machines and Workshops on Time Reports";
}
<div class="text-center">
<h1 class="display-4">Список цехов и станков в диапазоне времени</h1>
</div>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Отправить отчет на почту</button>
</form>
<table class="table">
<thead>
<tr>
<th>Цех</th>
<th>Станки</th>
</tr>
</thead>
<tbody>
@foreach (var workshop in Model)
{
<tr>
<td>@workshop.WorkshopName</td>
<td>
<ul>
@foreach (var machine in workshop.Machines)
{
<li>@machine</li>
}
</ul>
</td>
</tr>
}
</tbody>
</table>

View File

@ -0,0 +1,42 @@
@using Contracts.ViewModels
@model List<WorkerProductReportViewModel>
@{
ViewData["Title"] = "Workers - Product Reports";
}
<div class="text-center">
<h1 class="display-4">Список работников с отображением изделий</h1>
</div>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Сгенерировать отчет в Word</button>
</form>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Сгенерировать отчет в Excel</button>
</form>
<table class="table">
<thead>
<tr>
<th>Работник</th>
<th>Изделие</th>
</tr>
</thead>
<tbody>
@foreach (var worker in Model)
{
<tr>
<td>@worker.WorkerName</td>
<td>
<ul>
@foreach (var product in worker.Products)
{
<li>@product</li>
}
</ul>
</td>
</tr>
}
</tbody>
</table>

View File

@ -0,0 +1,31 @@
@using Contracts.ViewModels
@model List<ProductionViewModel>
@{
ViewData["Title"] = "Workshop-Add-Production";
}
<div class="text-center">
<h1 class="display-4">Цех - @ViewBag.Workshop</h1>
</div>
<div class="container">
<h1>Список цехов</h1>
<div class="row">
@foreach (var production in Model)
{
<div class="col-md-4">
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">@production.Name</h5>
<form asp-controller="Cart" asp-action="AddToCart" method="post">
<input type="hidden" name="workshopId" value="@production.Id" />
<button type="submit" class="btn btn-primary">Выбрать</button>
</form>
</div>
</div>
</div>
}
</div>
</div>

View File

@ -12,7 +12,8 @@
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Завод "Иди работать". Поручитель</a>
<img src="~/images/Work-transformed.png" width="150" height="150" alt="Логотип">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Поручитель</a>
</div>
</nav>
</header>