начало crud работ
This commit is contained in:
parent
6073dbda35
commit
c7cb372280
@ -1,5 +1,7 @@
|
||||
using CarServiceBusinessLogic.BusinessLogics;
|
||||
using CarServiceContracts.BindingModels;
|
||||
using CarServiceContracts.BusinessLogicsContracts;
|
||||
using CarServiceContracts.SearchModels;
|
||||
using CarServiceDatabase.Models;
|
||||
using CarServiceWebApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
@ -10,13 +12,18 @@ namespace CarServiceWebApp.Controllers
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IWorkLogic _workLogic;
|
||||
private readonly IWorkerLogic _workerLogic;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, IWorkLogic workLogic)
|
||||
public HomeController(ILogger<HomeController> logger, IWorkLogic workLogic, IWorkerLogic workerLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_workLogic = workLogic;
|
||||
_workerLogic = workerLogic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Главная страница
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (CurrentUser.UserId < 1)
|
||||
@ -25,18 +32,119 @@ namespace CarServiceWebApp.Controllers
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Отображение формы для входа
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ввод данных в форму для входа
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult Enter(WorkerSearchModel model)
|
||||
{
|
||||
var existingWorker = _workerLogic.ReadElement(new() { Login = model.Login, Password = model.Password });
|
||||
if (existingWorker != null)
|
||||
{
|
||||
CurrentUser.UserId = existingWorker.Id;
|
||||
return Redirect("~/Home/Index");
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewBag.Exception = "Неверный логин или пароль";
|
||||
return View();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Список работ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Works()
|
||||
{
|
||||
ViewBag.Works = _workLogic.ReadList(new() { Id = 1 });
|
||||
if (CurrentUser.UserId < 1)
|
||||
{
|
||||
return Redirect("~/Home/Index");
|
||||
}
|
||||
var Works = _workLogic.ReadList(new() { Id = CurrentUser.UserId });
|
||||
ViewBag.Works = Works;
|
||||
if (Works?.Count == 0)
|
||||
{
|
||||
ViewBag.Exception = "Пока нет работ";
|
||||
}
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выход из учётной записи
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Logout()
|
||||
{
|
||||
CurrentUser.UserId = 0;
|
||||
return Redirect("~/Home/Index");
|
||||
}
|
||||
/// <summary>
|
||||
/// Отображение формы для регистрации
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// Ввод данных при регистрации пользователя
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult Register(WorkerBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_workerLogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ViewBag.Exception = ex.Message;
|
||||
return View();
|
||||
}
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Work(int Id)
|
||||
{
|
||||
ViewBag.Work = _workLogic.ReadElement(new() { Id = Id });
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult UpdateWork(Work work)
|
||||
{
|
||||
//ViewBag.Work = _workLogic.ReadElement(new() { Id = Id });
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult DeleteWork(int Id)
|
||||
{
|
||||
ViewBag.Work = _workLogic.ReadElement(new() { Id = Id });
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Вывод ошибок
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
|
@ -11,6 +11,8 @@ builder.Logging.AddLog4Net("log4net.config");
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddTransient<IWorkLogic, WorkLogic>();
|
||||
builder.Services.AddTransient<IWorkStorage, WorkStorage>();
|
||||
builder.Services.AddTransient<IWorkerLogic, WorkerLogic>();
|
||||
builder.Services.AddTransient<IWorkerStorage, WorkerStorage>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
@ -8,14 +8,19 @@
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
<div class="col-8"><input type="text" name="Login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
<div class="col-8"><input type="password" name="Password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div>
|
||||
<div><button asp-controller="Home" asp-action="Enter" type="submit" class="btn btn-primary">Вход</button></div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
<form method="get">
|
||||
<div><button asp-controller="Home" asp-action="Register" class="btn btn-primary">Регистрация</button></div>
|
||||
</form>
|
||||
<div>
|
||||
<div>@ViewBag.Exception</div>
|
||||
</div>
|
@ -1,5 +1,5 @@
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
ViewData["Title"] = "Регистрация";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
@ -8,22 +8,25 @@
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
<div class="col-8"><input type="text" name="Login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
<div class="col-8"><input type="password" name="Password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Имя:</div>
|
||||
<div class="col-8"><input type="text" name="fio" /></div>
|
||||
<div class="col-8"><input type="text" name="Name" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Фамилия:</div>
|
||||
<div class="col-8"><input type="text" name="fio" /></div>
|
||||
<div class="col-8"><input type="text" name="Surname" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
<div>
|
||||
<div>@ViewBag.Exception</div>
|
||||
</div>
|
24
CarService/CarServiceWebApp/Views/Home/Work.cshtml
Normal file
24
CarService/CarServiceWebApp/Views/Home/Work.cshtml
Normal file
@ -0,0 +1,24 @@
|
||||
<form method="post">
|
||||
<div hidden><input type="text" name="Id" value="@ViewBag.Work.Id" /></div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8"><input type="text" name="Name" value="@ViewBag.Work.Name" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Цена:</div>
|
||||
<div class="col-8"><input type="text" name="Price" value="@ViewBag.Work.Price" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Длительность:</div>
|
||||
<div class="col-8"><input type="text" name="Duration" value="@ViewBag.Work.Duration" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div><button asp-controller="Home" asp-action="UpdateWork"class="btn btn-primary">Изменить</button></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div><button asp-controller="Home" asp-action="DeleteWork"class="btn btn-primary">Удалить</button></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div><button asp-controller="Home" asp-action="Works" type="submit" class="btn btn-primary">Отмена</button></div>
|
||||
</div>
|
||||
</form>
|
@ -4,23 +4,28 @@
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Работы</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Название</th>
|
||||
<th>Цена (в рублях)</th>
|
||||
<th>Длительность (в часах)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var work in ViewBag.Works)
|
||||
{
|
||||
@if (ViewBag.Works.Count != 0)
|
||||
{
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>@work.Name</td>
|
||||
<td>@work.Price</td>
|
||||
<td>@work.Duration</td>
|
||||
<th>Название</th>
|
||||
<th>Цена (в рублях)</th>
|
||||
<th>Длительность (в часах)</th>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var work in ViewBag.Works)
|
||||
{
|
||||
<tr>
|
||||
<td>@work.Name</td>
|
||||
<td>@work.Price</td>
|
||||
<td>@work.Duration</td>
|
||||
<td><a href="/Home/Work/@work.Id">Изменить</a></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
<div>@ViewBag.Exception</div>
|
||||
</div>
|
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - CarServiceWebApp</title>
|
||||
<title>@ViewData["Title"]</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/CarServiceWebApp.styles.css" asp-append-version="true" />
|
||||
@ -31,6 +31,9 @@
|
||||
<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" asp-area="" asp-controller="Home" asp-action="Logout">Выход</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user