This commit is contained in:
kagbie3nn@mail.ru 2024-05-31 11:45:10 +04:00
parent 9bcdb0588c
commit 19606c2a5c
10 changed files with 423 additions and 87 deletions

@ -35,7 +35,8 @@ namespace ZooDataBaseImplement.Models
Id = model.Id,
PreserveName = model.PreserveName,
PreservePrice = model.PreservePrice,
};
EmployeeId = model.EmployeeId,
};
}
public void Update(PreserveBindingModel model)
{
@ -51,7 +52,8 @@ namespace ZooDataBaseImplement.Models
Id = Id,
PreserveName = PreserveName,
PreservePrice = PreservePrice,
};
EmployeeId = EmployeeId,
};
}
}

@ -0,0 +1,94 @@
using Microsoft.AspNetCore.Mvc;
using ZooContracts.BindingModels;
using ZooContracts.BuisnessLogicsContracts;
using ZooContracts.SearchModels;
using ZooContracts.ViewModels;
using ZooDataBaseImplement.Models;
namespace ZooRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class PreserveController : Controller
{
private readonly ILogger _logger;
private readonly IPreserveLogic _preserve;
public PreserveController(ILogger<PreserveController> logger, IPreserveLogic preserve)
{
_logger = logger;
_preserve = preserve;
}
[HttpGet]
public List<PreserveViewModel> GetPreserves(int EmployeeId)
{
try
{
return _preserve.ReadList(new PreserveSearchModel { EmployeeId = EmployeeId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка животных");
throw;
}
}
[HttpGet]
public Tuple<PreserveViewModel>? GetPreserve(int PreserveId)
{
try
{
var elem = _preserve.ReadElement(new PreserveSearchModel { Id = PreserveId });
if (elem == null)
{
return null;
}
return Tuple.Create(elem);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения животного по id={Id}", PreserveId);
throw;
}
}
[HttpPost]
public bool CreatePreserve(PreserveBindingModel model)
{
try
{
return _preserve.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать животного");
throw;
}
}
[HttpPost]
public bool UpdatePreserve(PreserveBindingModel model)
{
try
{
return _preserve.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить животное");
throw;
}
}
[HttpPost]
public bool DeletePreserve(PreserveBindingModel model)
{
try
{
return _preserve.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления животного");
throw;
}
}
}
}

@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Mvc;
using ZooContracts.BindingModels;
using ZooContracts.BusinessLogicsContracts;
namespace ZooRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportControllerEmployee : Controller
{
private readonly ILogger _logger;
private readonly IReportEmployeeLogic _report;
public ReportControllerEmployee(ILogger<ReportControllerEmployee> logger, IReportEmployeeLogic report)
{
logger = logger;
_report = report;
}
[Microsoft.AspNetCore.Mvc.HttpGet]
public IActionResult Index(ReportControllerEmployee report)
{
return View();
}
[HttpPost]
public void CreateServiceListWordFile(ReportRouteBindingModel model)
{
try
{
_report.SaveRoutesToWordFile(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void CreateServiceListExcelFile(ReportRouteBindingModel model)
{
try
{
_report.SaveRoutesToExcelFile(model);
}
catch (Exception ex)
{
throw;
}
}
}
}

@ -25,6 +25,11 @@ namespace ZooShowEmployeeApp.Controllers
View(APIEmployee.GetRequest<List<RouteViewModel>>($"api/main/getroutes?EmployeeId={APIEmployee.Employee.Id}"));
}
public IActionResult Reports()
{
return View();
}
[HttpGet]
public IActionResult Privacy()
{
@ -116,32 +121,167 @@ namespace ZooShowEmployeeApp.Controllers
}
[HttpGet]
public IActionResult CreatePreserve()
public IActionResult IndexPreserve()
{
if (APIEmployee.Employee == null)
{
return Redirect("~/Home/Enter");
}
return View(APIEmployee.GetRequest<List<PreserveViewModel>>($"api/Preserve/getPreserves?clientid={APIEmployee.Employee.Id}"));
}
public IActionResult CreatePreserve()
{
if (APIEmployee.Employee == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void CreatePreserve(string name, double price)
{
if (APIEmployee.Employee == null)
{
throw new Exception("Вы как суда попали? Сюда вход только авторизованным");
}
if (string.IsNullOrEmpty(name) || price <= 0 )
{
throw new Exception("Ошибка в введённых данных");
}
APIEmployee.PostRequest("api/Preserve/createPreserve", new PreserveBindingModel
{
PreserveName = name,
PreservePrice = price,
EmployeeId = APIEmployee.Employee.Id
});
Response.Redirect("Index");
}
public IActionResult UpdatePreserve()
{
if (APIEmployee.Employee == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Preserves = APIEmployee.GetRequest<List<PreserveViewModel>>($"api/Preserve/getPreserves?clientid={APIEmployee.Employee.Id}");
return View();
}
[HttpPost]
public void UpdatePreserve(int pet, string name, double price)
{
if (APIEmployee.Employee == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(name) || price <= 0)
{
throw new Exception("Ошибка введённых данных");
}
APIEmployee.PostRequest("api/Preserve/updatePreserve", new PreserveViewModel
{
Id = pet,
PreserveName = name,
PreservePrice = price,
});
Response.Redirect("Index");
}
[HttpGet]
public Tuple<PreserveViewModel>? GetPreserve(int PreserveId)
{
if (APIEmployee.Employee == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIEmployee.GetRequest<Tuple<PreserveViewModel>>($"api/Preserve/getPreserve?PreserveId={PreserveId}");
if (result == null)
{
return default;
}
return result;
}
[HttpPost]
public void IndexPreserve(int id)
{
if (APIEmployee.Employee == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIEmployee.PostRequest("api/Preserve/deletePreserve", new PreserveBindingModel
{
Id = id
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult ListPreserves()
{
ViewBag.Preserves =
APIEmployee.GetRequest<List<PreserveViewModel>>("api/main/getpreservelist");
if (APIEmployee.Employee == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Preserves = APIEmployee.GetRequest<List<PreserveViewModel>>($"api/preserve/GetPreserves?Employeeid={APIEmployee.Employee.Id}");
return View();
}
[HttpPost]
public void CreatePreserve(int preserve, int count)
public void ListPreserves(List<int> preserve, string type)
{
if (APIEmployee.Employee == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (count <= 0)
{
throw new Exception("Количество и сумма должны быть больше 0");
}
APIEmployee.PostRequest("api/main/createpreserve", new
PreserveBindingModel
{
EmployeeId = APIEmployee.Employee.Id
});
Response.Redirect("Index");
if (preserve.Count <= 0)
{
throw new Exception("Количество должно быть больше 0");
}
if (string.IsNullOrEmpty(type))
{
throw new Exception("Неверный тип отчета");
}
if (type == "docx")
{
APIEmployee.PostRequest("api/report/createservicelistwordfile", new ReportPreserveBindingModel
{
Preserve = preserve,
FileName = "C:\\gg\\wordfile.docx"
});
Response.Redirect("GetWordFile");
}
else
{
APIEmployee.PostRequest("api/report/createservicelistexcelfile", new ReportPreserveBindingModel
{
Preserve = preserve,
FileName = "C:\\gg\\excelfile.xlsx"
});
Response.Redirect("GetExcelFile");
}
}
[HttpGet]
public IActionResult GetWordFile()
{
return new PhysicalFileResult("C:\\gg\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult GetExcelFile()
{
return new PhysicalFileResult("C:\\gg\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
}
}

@ -1,66 +1,14 @@
@using ZooContracts.ViewModels
@model List<RouteViewModel>
@{
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Маршруты</h1>
</div>
<a asp-action="CreatePreserve">Создать Маршруты</a>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Заповедники
</th>
<th>
Дата начала
</th>
<th>
Дата окончания
</th>
<th>
Статус
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>
item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.RouteName)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.DateStart)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.DateFinish)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Status)
</td>
</tr>
}
</tbody>
</table>
}
</div>
<h1 class="display-8">Приложение "Зоопарк "Юрский период". Исполнитель"</h1>
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="IndexPreserve">Заповедник</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CreatePreserve">Заповедники</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Reports">Отчеты</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</div>
</div>

@ -0,0 +1,63 @@
@using ZooContracts.ViewModels;
@model List<PreserveViewModel>
@{
ViewData["Title"] = "Preserves";
}
<div class="text-center">
<h1 class="display-4">Заповедник</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreatePreserve">Создать Заповедник</a>
<a asp-action="UpdatePreserve">Обновить Заповедник</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название
</th>
<th>
Стоимость
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.PreserveName)
</td>
<td>
@Html.DisplayFor(modelItem => item.PreservePrice)
</td>
<td>
<form method="post">
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
<input type="submit" class="btn btn-danger" value="Удалить" />
</form>
</td>
</tr>
}
</tbody>
</table>
}
</div>

@ -0,0 +1,35 @@
@using ZooContracts.ViewModels;
@{
ViewData["Title"] = "ServiceListReport";
}
<div class="text-center">
<h2 class="display-4">Создать cписки маршрутов</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">маршрут:</div>
<div class="col-8">
<select name="preserve" class="form-control" multiple size="5" id="preserve">
@foreach (var service in ViewBag.Preserve)
{
<option value="@service.Id">@service.PreserveName</option>
}
</select>
</div>
</div>
<div class="file-format">
<label class="form-label">Выберите формат файла:</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
<label class="form-check-label" for="docx">Word-файл</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
<label class="form-check-label" for="xlsx">Excel-файл</label>
</div>
</div>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-block btn-outline-dark w-100">Создать</button>
</div>
</form>

@ -0,0 +1,12 @@
@{
ViewData["Title"] = "";
}
<div class="text-center">
<h1 class="display-4">Отчеты</h1>
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ListPreserves">Списки маршрутов</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="AnimalVisitsAndDrugs">Посещения и лекарства животных</a>
</div>
</div>

@ -20,12 +20,6 @@
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Index">Заповедники</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>