рабочего кода не существует
This commit is contained in:
parent
cf0999d6eb
commit
d39bbb0e75
@ -4,6 +4,9 @@ using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using WorkerWebApp.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
|
||||
namespace WorkerWebApp.Controllers
|
||||
{
|
||||
@ -11,104 +14,136 @@ namespace WorkerWebApp.Controllers
|
||||
[ApiController]
|
||||
public class ProcedureController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger<ProcedureController> logger;
|
||||
|
||||
private readonly IProcedureLogic _logic;
|
||||
private readonly ICosmeticLogic cosmetic;
|
||||
private readonly IProcedureLogic procedure;
|
||||
|
||||
public ProcedureController(IProcedureLogic logic, ILogger<ProcedureController> logger)
|
||||
public ProcedureController(ILogger<ProcedureController> logger, ICosmeticLogic cosmetic, IProcedureLogic procedure)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
this.logger = logger;
|
||||
this.cosmetic = cosmetic;
|
||||
this.procedure = procedure;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public ProcedureViewModel? GetProcedure(int id)
|
||||
public ProcedureViewModel GetProcedure(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ProcedureSearchModel
|
||||
return procedure.ReadElement(new ProcedureSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения процедуры");
|
||||
logger.LogError(ex, "Ошибка получения процедуры");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ProcedureViewModel>? GetAllProcedures()
|
||||
public IActionResult Procedures()
|
||||
{
|
||||
try
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка процедур");
|
||||
throw;
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View(cosmetic.ReadList(null));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ProcedureViewModel>? GetProcedures(int workerId)
|
||||
public IActionResult CreateProcedures()
|
||||
{
|
||||
try
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
return _logic.ReadList(new ProcedureSearchModel { WorkerId = workerId });
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка процедур сотрудника id={Id}", workerId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel());
|
||||
|
||||
[HttpPost]
|
||||
public void CreateProcedure(ProcedureBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания процедуры");
|
||||
throw;
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateProcedure(ProcedureBindingModel model)
|
||||
public IActionResult CreateProcedures(string name, double price, double duration)
|
||||
{
|
||||
try
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
_logic.Update(model);
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
if (string.IsNullOrEmpty(name) || price <= 0)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления процедуры");
|
||||
throw;
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
procedure.Create(new ProcedureBindingModel
|
||||
{
|
||||
ProcedureName = name,
|
||||
ProcedurePrice = price,
|
||||
ProcedureDuration = duration
|
||||
});
|
||||
|
||||
return RedirectToAction("Procedures");
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteProcedure(ProcedureBindingModel model)
|
||||
[HttpGet]
|
||||
public IActionResult UpdateProcedures(int id)
|
||||
{
|
||||
try
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
_logic.Delete(model);
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel());
|
||||
|
||||
return View(procedure.ReadElement(new ProcedureSearchModel
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления процедуры");
|
||||
throw;
|
||||
}
|
||||
Id = id
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult UpdateProcedures(int id, string name, double price, double duration)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name) || price <= 0)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
procedure.Update(new ProcedureBindingModel
|
||||
{
|
||||
Id = id,
|
||||
ProcedureName = name,
|
||||
ProcedurePrice = price,
|
||||
ProcedureDuration = duration
|
||||
});
|
||||
|
||||
return RedirectToAction("Procedures");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult DeleteProcedure(int id)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
procedure.Delete(new ProcedureBindingModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
|
||||
return RedirectToAction("Procedures");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,13 +8,13 @@
|
||||
|
||||
<div class="d-flex flex-wrap align-items-center justify-content-between">
|
||||
<div class="d-flex mb-2 gap-1">
|
||||
<a asp-controller="Procedure" asp-action="Create" class="button-primary">
|
||||
<a asp-controller="Procedure" asp-action="Create" class="btn button-primary">
|
||||
Создать
|
||||
</a>
|
||||
<a id="update-button" class="button-primary">
|
||||
<button id="update-button" class="btn button-primary">
|
||||
Обновить
|
||||
</a>
|
||||
<button id="delete-button" class="button-primary me-5">
|
||||
</button>
|
||||
<button id="delete-button" class="btn button-primary me-5">
|
||||
Удалить
|
||||
</button>
|
||||
</div>
|
||||
@ -23,7 +23,7 @@
|
||||
<input id="page-input" type="number" min="1" value="@ViewBag.Page" max="@ViewBag.NumberOfPages" class="form-control" style="max-width: 5em">
|
||||
<span class="input-group-text">/ @ViewBag.NumberOfPages</span>
|
||||
</div>
|
||||
<a href="/Home/Procedure?page=@ViewBag.Page" id="go-button" class="button-primary">
|
||||
<a href="/Home/Cars?page=@ViewBag.Page" id="go-button" class="btn btn-lg button-primary">
|
||||
Перейти
|
||||
</a>
|
||||
</div>
|
||||
@ -32,8 +32,9 @@
|
||||
<table class="table mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Наименование процедуры</th>
|
||||
<th>Цена процедуры</th>
|
||||
<th>Название процедуры</th>
|
||||
<th>Стоимость</th>
|
||||
<th>Длительность</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -42,10 +43,11 @@
|
||||
<tr class="table-row" id="row-@item.Id">
|
||||
<td>@item.ProcedureName</td>
|
||||
<td>@item.ProcedurePrice</td>
|
||||
<td>@item.ProcedureDuration</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script src="~/js/procedure.js" asp-append-version="true"></script>
|
||||
<script src="~/js/cosmetic.js" asp-append-version="true"></script>
|
Loading…
Reference in New Issue
Block a user