implementation of storekeeper many-to-many relation
This commit is contained in:
parent
f9eae8c2da
commit
8d3a39c256
@ -4,6 +4,7 @@ using FactoryContracts.SearchModels;
|
||||
using FactoryContracts.StoragesContracts;
|
||||
using FactoryContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FactoryBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -97,9 +98,9 @@ namespace FactoryBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина клиента", nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^[a-z0-9._%+-]+\@([a-z0-9-]+\.)+[a-z]{2,4}$"))
|
||||
{
|
||||
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
|
||||
throw new ArgumentException("Почта не соответствует требованиям", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
|
@ -1,9 +1,7 @@
|
||||
using DocumentFormat.OpenXml.Office.CustomUI;
|
||||
using FactoryContracts.BindingModels;
|
||||
using FactoryContracts.BindingModels;
|
||||
using FactoryContracts.BusinessLogicsContracts;
|
||||
using FactoryContracts.SearchModels;
|
||||
using FactoryContracts.ViewModels;
|
||||
using FactoryDatabaseImplement.Models;
|
||||
using FactoryDataModels.Enums;
|
||||
using FactoryDataModels.Models;
|
||||
using FactoryStorekepeerApp.Models;
|
||||
@ -19,16 +17,18 @@ namespace FactoryStorekeeperApp.Controllers
|
||||
private readonly IMachineLogic machineLogic;
|
||||
private readonly IRequirementLogic requirementLogic;
|
||||
private readonly IProductLogic productLogic;
|
||||
private readonly IPlanProductionLogic planProductionLogic;
|
||||
|
||||
private bool IsLoggedIn { get { return Client.client != null; } }
|
||||
private static bool IsLoggedIn { get { return Client.client != null; } }
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic)
|
||||
public HomeController(ILogger<HomeController> logger, IClientLogic clientLogic, IRequirementLogic requirementLogic, IProductLogic productLogic, IMachineLogic machineLogic, IPlanProductionLogic planProductionLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
this.clientLogic = clientLogic;
|
||||
this.requirementLogic = requirementLogic;
|
||||
this.productLogic = productLogic;
|
||||
this.machineLogic = machineLogic;
|
||||
this.planProductionLogic = planProductionLogic;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -83,7 +83,7 @@ namespace FactoryStorekeeperApp.Controllers
|
||||
{
|
||||
if (!password.Equals(passwordConfirm))
|
||||
{
|
||||
return Error();
|
||||
throw new ArgumentException("Пароли не совпадают");
|
||||
}
|
||||
clientLogic.Create(new ClientBindingModel
|
||||
{
|
||||
@ -160,7 +160,10 @@ namespace FactoryStorekeeperApp.Controllers
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (id != 0)
|
||||
{
|
||||
machineLogic.Delete(new MachineBindingModel { Id = id });
|
||||
}
|
||||
return Redirect("~/Home/Machines");
|
||||
}
|
||||
[HttpGet]
|
||||
@ -234,6 +237,7 @@ namespace FactoryStorekeeperApp.Controllers
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (id != 0)
|
||||
productLogic.Delete(new ProductBindingModel { Id = id });
|
||||
return Redirect("~/Home/Products");
|
||||
}
|
||||
@ -306,10 +310,79 @@ namespace FactoryStorekeeperApp.Controllers
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
if (id != 0)
|
||||
requirementLogic.Delete(new RequirementBindingModel { Id = id });
|
||||
return Redirect("~/Home/Requirements");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult MachinePlanProductions()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
var planProductions = planProductionLogic.ReadList(new PlanProductionSearchModel
|
||||
{
|
||||
ClientId = Client.client.Id,
|
||||
});
|
||||
var machines = machineLogic.ReadList(new MachineSearchModel
|
||||
{
|
||||
ClientId = Client.client.Id,
|
||||
});
|
||||
ViewBag.planProductions = planProductions;
|
||||
ViewBag.machines = machines;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult MachinePlanProductions(int machine, List<int> planproductions, int count)
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
var existMachine = machineLogic.ReadElement(new MachineSearchModel
|
||||
{
|
||||
Id = machine,
|
||||
ClientId = Client.client.Id
|
||||
});
|
||||
var planProductions = planProductionLogic.ReadList(new PlanProductionSearchModel
|
||||
{
|
||||
ClientId = Client.client.Id,
|
||||
}).Where(x => planproductions.Contains(x.Id))
|
||||
.ToList();
|
||||
if (existMachine != null && planProductions.Count > 0)
|
||||
{
|
||||
foreach (var planId in planproductions)
|
||||
{
|
||||
var currPlan = planProductions.Where(x => x.Id == planId).FirstOrDefault();
|
||||
if (currPlan != null)
|
||||
{
|
||||
if (existMachine.MachinePlanProductions.ContainsKey(planId))
|
||||
{
|
||||
var currTuple = existMachine.MachinePlanProductions[planId];
|
||||
existMachine.MachinePlanProductions[planId] = (currTuple.Item1, currTuple.Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
existMachine.MachinePlanProductions.Add(planId, (currPlan, count));
|
||||
}
|
||||
}
|
||||
}
|
||||
machineLogic.Update(new MachineBindingModel
|
||||
{
|
||||
Id = existMachine.Id,
|
||||
MachineName = existMachine.MachineName,
|
||||
ClientId = Client.client.Id,
|
||||
ExploitationStartDate = existMachine.ExploitationStartDate,
|
||||
Lifetime = existMachine.Lifetime,
|
||||
MachinePlanProductions = existMachine.MachinePlanProductions,
|
||||
});
|
||||
}
|
||||
return Redirect("~/Home/Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Reports()
|
||||
{
|
||||
|
@ -12,12 +12,14 @@ builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
|
||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||
builder.Services.AddTransient<IRequirementLogic, RequirementLogic>();
|
||||
builder.Services.AddTransient<IPlanProductionLogic, PlanProductionLogic>();
|
||||
builder.Services.AddTransient<IStorekeeperReportLogic, StorekeeperReportLogic>();
|
||||
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IMachineStorage, MachineStorage>();
|
||||
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||
builder.Services.AddTransient<IRequirementStorage, RequirementStorage>();
|
||||
builder.Services.AddTransient<IPlanProductionStorage, PlanProductionStorage>();
|
||||
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
@ -10,37 +10,17 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Станок:</div>
|
||||
<div class="col-8">
|
||||
<select id="machine" name="machine" class="form-control"></select>
|
||||
<select id="machine" name="machine" class="form-control border border-dark rounded" asp-items="@(new SelectList(ViewBag.machines, "Id", "MachineName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<h3>Список планов производства</h3>
|
||||
<div class="container">
|
||||
<div>Заготовки</div>
|
||||
<div class="table-responsive-lg">
|
||||
<table id="detailsTable" class="display">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Выбор </th>
|
||||
<th>Название </th>
|
||||
<th>Количество</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var planProduction in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" name="planproductions" value="@planProduction.Id" />
|
||||
</td>
|
||||
<td>@planProduction.ProductionName</td>
|
||||
<td>
|
||||
<input type="number" name="count" value="0" min="0" class="form-control" />
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<input type="number" name="count"/>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Список планов производств:</div>
|
||||
<select name="planproductions" id="planproductions" class="form-control border border-dark rounded" multiple size="5" asp-items="@(new SelectList(ViewBag.planProductions, "Id", "ProductionName"))">
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user