Compare commits

...

2 Commits

10 changed files with 172 additions and 60 deletions

View File

@ -93,13 +93,13 @@ namespace FactoryDatabaseImplement.Models
}
context.SaveChanges();
}
var machine = context.Machines.First(x => x.Id == Id);
var product = context.Products.First(x => x.Id == Id);
foreach (var pc in model.ProductMachines)
{
context.ProductMachines.Add(new ProductMachine
{
Product = context.Products.First(x => x.Id == pc.Key),
Machine = machine,
Machine = context.Machines.First(x => x.Id == pc.Key),
Product = product,
});
context.SaveChanges();
}

View File

@ -61,6 +61,7 @@ namespace FactoryDatabaseImplement.Models
Id = Id,
ClientId = ClientId,
RequirementName = RequirementName,
Description = Description,
Lifetime = Lifetime,
ProductId = ProductId,
};

View File

@ -1,7 +1,9 @@
using FactoryContracts.BindingModels;
using DocumentFormat.OpenXml.Office.CustomUI;
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using FactoryDataModels.Enums;
using FactoryDataModels.Models;
using FactoryStorekepeerApp.Models;
@ -106,24 +108,29 @@ namespace FactoryStorekeeperApp.Controllers
}));
}
[HttpGet]
public IActionResult Machine()
public IActionResult Machine(int id)
{
if (!IsLoggedIn)
{
return Redirect("~/Home/Enter");
}
return View();
if (id != 0)
{
var machine = machineLogic.ReadElement(new MachineSearchModel { Id = id, ClientId = Client.client.Id });
if (machine != null)
return View(machine);
}
return View(new MachineViewModel());
}
[HttpPost]
public IActionResult Machine(string machinename, DateTime exploitationstartdate, int lifetime)
public IActionResult Machine(int id, string machinename, DateTime exploitationstartdate, int lifetime)
{
var element = machineLogic.ReadElement(new MachineSearchModel
if (!IsLoggedIn)
{
MachineName = machinename,
ClientId = Client.client.Id,
});
if (element == null) {
return Unauthorized();
}
if (id == 0) {
machineLogic.Create(new MachineBindingModel
{
MachineName = machinename,
@ -136,6 +143,7 @@ namespace FactoryStorekeeperApp.Controllers
{
machineLogic.Update(new MachineBindingModel
{
Id = id,
MachineName = machinename,
ExploitationStartDate = exploitationstartdate,
Lifetime = lifetime,
@ -145,6 +153,16 @@ namespace FactoryStorekeeperApp.Controllers
return Redirect("~/Home/Machines");
}
[HttpPost]
public IActionResult DeleteMachine(int id)
{
if (!IsLoggedIn)
{
return Unauthorized();
}
machineLogic.Delete(new MachineBindingModel { Id = id });
return Redirect("~/Home/Machines");
}
[HttpGet]
public IActionResult Products()
{
@ -158,28 +176,35 @@ namespace FactoryStorekeeperApp.Controllers
}));
}
[HttpGet]
public IActionResult Product()
public IActionResult Product(int id)
{
if (!IsLoggedIn)
{
return Enter();
}
return View(machineLogic.ReadList(new MachineSearchModel
var machines = machineLogic.ReadList(new MachineSearchModel
{
ClientId = Client.client.Id
}
));
);
ViewBag.machines = machines;
if (id != 0)
{
var product = productLogic.ReadElement(new ProductSearchModel { Id = id, ClientId = Client.client.Id });
if (product != null)
return View(product);
}
return View(new ProductViewModel());
}
[HttpPost]
public IActionResult Product(string productname, int price, List<int> machines)
public IActionResult Product(int id, string productname, int price, List<int> machines)
{
var element = productLogic.ReadElement(new ProductSearchModel
{
ProductName = productname,
ClientId = Client.client.Id,
});
if (!IsLoggedIn)
{
return Unauthorized();
}
var machineList = machineLogic.ReadListByIds(machines);
if (element == null)
if (id == 0)
{
productLogic.Create(new ProductBindingModel
{
@ -193,6 +218,7 @@ namespace FactoryStorekeeperApp.Controllers
{
productLogic.Update(new ProductBindingModel
{
Id = id,
ProductName = productname,
Price = price,
ProductMachines = machineList.ToDictionary(recPC => recPC.Id, recPC => recPC as IMachineModel),
@ -201,7 +227,17 @@ namespace FactoryStorekeeperApp.Controllers
}
return Redirect("~/Home/Products");
}
[HttpGet]
[HttpPost]
public IActionResult DeleteProduct(int id)
{
if (!IsLoggedIn)
{
return Unauthorized();
}
productLogic.Delete(new ProductBindingModel { Id = id });
return Redirect("~/Home/Products");
}
[HttpGet]
public IActionResult Requirements()
{
if (!IsLoggedIn)
@ -211,49 +247,69 @@ namespace FactoryStorekeeperApp.Controllers
return View(requirementLogic.ReadList(new RequirementSearchModel { ClientId = Client.client.Id}));
}
[HttpGet]
public IActionResult Requirement()
public IActionResult Requirement(int id)
{
if (!IsLoggedIn)
{
return Redirect("~/Home/Enter");
}
return View();
ViewBag.Products = productLogic.ReadList(new ProductSearchModel() { ClientId = Client.client.Id});
if (id !=0)
{
var requirement = requirementLogic.ReadElement(new RequirementSearchModel
{
Id = id,
ClientId = Client.client.Id,
});
if (requirement != null)
return View(requirement);
}
return View(new RequirementViewModel());
}
[HttpPost]
public IActionResult Requirement(string requirementname, string description, int lifetime)
public IActionResult Requirement(int id, int productid, string requirementname, string description, int lifetime)
{
if (!IsLoggedIn)
{
return Redirect("~/Home/Enter");
return Unauthorized();
}
var element = requirementLogic.ReadElement(new RequirementSearchModel
{
RequirementName = requirementname,
ClientId = Client.client.Id
});
if (element == null)
if (id == 0)
{
requirementLogic.Create(new RequirementBindingModel
{
RequirementName = requirementname,
Description = description,
Lifetime = lifetime,
ClientId = Client.client.Id
ClientId = Client.client.Id,
ProductId = productid
});
}
else
{
requirementLogic.Update(new RequirementBindingModel
{
Id = id,
RequirementName = requirementname,
Description = description,
Lifetime = lifetime,
ClientId = Client.client.Id
ClientId = Client.client.Id,
ProductId= productid
});
}
return Redirect("~/Home/Requirements");
}
[HttpPost]
public IActionResult DeleteRequirement(int id)
{
if (!IsLoggedIn)
{
return Unauthorized();
}
requirementLogic.Delete(new RequirementBindingModel { Id = id });
return Redirect("~/Home/Requirements");
}
[HttpGet]
public IActionResult Reports()
{

View File

@ -1,4 +1,6 @@
using FactoryBusinessLogic.BusinessLogics;
using FactoryBusinessLogic.OfficePackage;
using FactoryBusinessLogic.OfficePackage.Implements;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.StoragesContracts;
using FactoryDatabaseImplement.Implements;
@ -17,6 +19,10 @@ builder.Services.AddTransient<IMachineStorage, MachineStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<IRequirementStorage, RequirementStorage>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddControllersWithViews();
var app = builder.Build();

View File

@ -2,24 +2,32 @@
@{
ViewData["Title"] = "Создание станка";
}
@model MachineViewModel
<div class="text-center">
<h2 class="display-4">Создание станка</h2>
@if (Model == null)
{
<h2 class="display-4">Создание станка</h2>
}
@if (Model != null) {
<h2 class="display-4">Изменение станка</h2>
}
</div>
<form method="post">
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="machinename" id="machinename" /></div>
<div class="col-8"><input type="text" name="machinename" id="machinename" value="@Model.MachineName"/></div>
</div>
<div class="row">
<div class="col-4">Ввод в экспулатацию:</div>
<div class="col-8"><input type="date" id="exploitationstartdate" name="exploitationstartdate"/></div>
<div class="col-8"><input type="date" id="exploitationstartdate" name="exploitationstartdate" value="@Model.ExploitationStartDate"/></div>
</div>
<div class="row">
<div class="col-4">Срок службы:</div>
<div class="col-8"><input type="number" name="lifetime" id="lifetime" /></div>
<div class="col-8"><input type="number" name="lifetime" id="lifetime" value="@Model.Lifetime"/></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -24,13 +24,13 @@
<table class="table">
<thead>
<tr>
<th>
<th class="w-50">
Название станка
</th>
<th>
<th class="w-50">
Ввод в эксплуатацию
</th>
<th>
<th class="w-50">
Срок службы
</th>
<th>
@ -58,7 +58,9 @@
<a asp-action="Machine" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>
<td>
<a asp-action="DeleteMachine" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
<form method="post" asp-action="DeleteMachine" asp-route-id="@item.Id">
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td>
</tr>
}

View File

@ -2,24 +2,44 @@
@{
ViewData["Title"] = "Создание изделия";
}
@model ProductViewModel;
<div class="text-center">
<h2 class="display-4">Создание изделия</h2>
@if (Model == null)
{
<h2 class="display-4">Создание изделия</h2>
}
@if (Model != null)
{
<h2 class="display-4">Изменение изделия</h2>
}
</div>
<form method="post">
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="productname" id="productname" /></div>
<div class="col-8"><input type="text" name="productname" id="productname" value="@Model.ProductName"/></div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8"><input type="number" id="price" name="price"/></div>
<div class="col-8"><input type="number" id="price" name="price" value="@Model.Price"/></div>
</div>
<div class="row">
<div class="col-4">Станки:</div>
<select id="machines" name="machines" class="form-control border border-dark rounded" multiple size="5" asp-items="@(new SelectList(Model, "Id", "MachineName"))"></select>
<select name="machines" id="machines" class="form-control border border-dark rounded" multiple size="5">
@foreach (var mach in ViewBag.machines)
{
@if (Model.ProductMachines.Values.Any(x => mach.Id == x.Id))
{
<option value="@mach.Id" selected="selected">@mach.MachineName</option>
}
else
{
<option value="@mach.Id">@mach.MachineName</option>
}
}
</select>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -25,10 +25,10 @@
<table class="table">
<thead>
<tr>
<th>
<th class="w-50">
Название изделия
</th>
<th>
<th class="w-50">
Цена
</th>
<th>
@ -53,7 +53,9 @@
<a asp-action="Product" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>
<td>
<a asp-action="DeleteProduct" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
<form method="post" asp-action="DeleteProduct" asp-route-id="@item.Id">
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td>
</tr>
}

View File

@ -2,30 +2,45 @@
@{
ViewData["Title"] = "Создание требования";
}
@model RequirementViewModel
<div class="text-center">
<h2 class="display-4">Создание требования к изделию</h2>
@if (Model == null)
{
<h2 class="display-4">Создание требования к изделию</h2>
}
@if (Model != null)
{
<h2 class="display-4">Изменение требования к изделию</h2>
}
</div>
<form method="post">
<div class="row">
<div class="col-4">Изделие:</div>
<div class="col-8">
<select id="product" name="product" class="form-control" asp-items="@(Model)"></select>
<select name="productid" id="productid" class="form-control border border-dark rounded">
<option value="">Выберите изделие</option>
@foreach (var prod in ViewBag.Products)
{
<option value="@prod.Id">@prod.ProductName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="requirementname" id="requirementname" /></div>
<div class="col-8"><input type="text" name="requirementname" id="requirementname" value="@Model.RequirementName"/></div>
</div>
<div class="row">
<div class="col-4">Описание изделия:</div>
<div class="col-8"><input type="text" name="description" id="description" /></div>
<div class="col-8"><input type="text" name="description" id="description" value="@Model.Description"/></div>
</div>
<div class="row">
<div class="col-4">Срок службы:</div>
<div class="col-8"><input type="number" id="lifetime" name="lifetime" readonly /></div>
<div class="col-8"><input type="number" id="lifetime" name="lifetime" value="@Model.Lifetime" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -18,7 +18,7 @@
}
<p>
<a asp-action="Product">Создать требование</a>
<a asp-action="Requirement">Создать требование</a>
</p>
@ -59,7 +59,9 @@
<a asp-action="Requirement" asp-route-id="@item.Id" class="btn btn-primary">Изменить</a>
</td>
<td>
<a asp-action="DeleteRequirement" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
<form method="post" asp-action="DeleteRequirement" asp-route-id="@item.Id">
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td>
</tr>
}