Все CRUD-методы

This commit is contained in:
ityurner02@mail.ru 2023-05-18 20:00:05 +04:00
parent 53c6b8fb76
commit 7da42c3539
14 changed files with 497 additions and 19 deletions

View File

@ -68,7 +68,7 @@ namespace TeacherWebClient.Controllers
{
Id = APIClient.Teacher.Id,
Name = name,
Email = login,
Email = email,
Password = password,
Login = login,
Post = post
@ -117,7 +117,7 @@ namespace TeacherWebClient.Controllers
_teacher.Create(new TeacherBindingModel
{
Name = name,
Email = login,
Email = email,
Password = password,
Login = login,
Post = post
@ -212,7 +212,7 @@ namespace TeacherWebClient.Controllers
ViewBag.Products = _product.ReadList(null);
var list = _material.ReadList(new MaterialSearchModel { TeacherId = APIClient.Teacher.Id });
var simpMaterial = list.Select(x => new { MaterialId = x.Id, MaterialName = x.Title });
ViewBag.Interests = new MultiSelectList(simpMaterial, "MaterialId", "MaterialName");
ViewBag.Materials = new MultiSelectList(simpMaterial, "MaterialId", "MaterialName");
return View();
}
[HttpPost]
@ -255,7 +255,7 @@ namespace TeacherWebClient.Controllers
return View(lesson);
}
[HttpPost]
public void UpdateDiy(int idLesson, string title, string dateEvent, int product, int[] materials)
public void UpdateLesson(int idLesson, string title, string dateEvent, int product, int[] materials)
{
@ -289,7 +289,7 @@ namespace TeacherWebClient.Controllers
Title = title,
DateEvent = DateTime.SpecifyKind(DateTime.Parse(dateEvent), DateTimeKind.Utc),
ProductId = product,
ProductName = _task.ReadElement(new TaskSearchModel { Id = product }).Title,
ProductName = _product.ReadElement(new ProductSearchModel { Id = product }).Title,
LessonMaterials = lessonMaterials
});
@ -319,7 +319,7 @@ namespace TeacherWebClient.Controllers
{
var list = _material.ReadList(new MaterialSearchModel { TeacherId = APIClient.Teacher.Id });
var simpMaterial = list.Select(x => new { MaterialId = x.Id, MaterialName = x.Title });
ViewBag.Interests = new MultiSelectList(simpMaterial, "MaterialId", "MaterialName");
ViewBag.Materials = new MultiSelectList(simpMaterial, "MaterialId", "MaterialName");
return View();
}
[HttpPost]
@ -333,6 +333,10 @@ namespace TeacherWebClient.Controllers
{
throw new Exception("Введите название и даты");
}
if(DateTime.SpecifyKind(DateTime.Parse(dateIssue), DateTimeKind.Utc) >= DateTime.SpecifyKind(DateTime.Parse(dateDelivery), DateTimeKind.Utc))
{
throw new Exception("Дата выдачи должна быть раньше срока сдачи");
}
Dictionary<int, IMaterial> taskMaterials = new Dictionary<int, IMaterial>();
foreach (int id in materials)
{
@ -380,6 +384,10 @@ namespace TeacherWebClient.Controllers
{
throw new Exception("Нет материалов");
}
if (DateTime.SpecifyKind(DateTime.Parse(dateIssue), DateTimeKind.Utc) >= DateTime.SpecifyKind(DateTime.Parse(dateDelivery), DateTimeKind.Utc))
{
throw new Exception("Дата выдачи должна быть раньше срока сдачи");
}
Dictionary<int, IMaterial> taskMaterials = new Dictionary<int, IMaterial>();
foreach (int id in materials)

View File

@ -1,10 +1,43 @@
var builder = WebApplication.CreateBuilder(args);
using SchoolAgainStudyBusinessLogic.BusinessLogic;
using SchoolAgainStudyBusinessLogic.OfficePackage.Implements;
using SchoolAgainStudyBusinessLogic.OfficePackage;
using SchoolAgainStudyBusinessLogic.Íîâàÿ_ïàïêà;
using SchoolAgainStudyContracts.BusinessLogicContracts;
using SchoolAgainStudyContracts.StorageContracts;
using SchoolAgainStudyDataBaseImplements.Implements;
using TeacherWebClient;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IStudentStorage, StudentStorage>();
builder.Services.AddTransient<IInterestStorage, InterestStorage>();
builder.Services.AddTransient<IDiyStorage, DiyStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<ITaskStorage, TaskStorage>();
builder.Services.AddTransient<ITeacherStorage, TeacherStorage>();
builder.Services.AddTransient<IMaterialStorage, MaterialStorage>();
builder.Services.AddTransient<ILessonStorage, LessonStorage>();
builder.Services.AddTransient<IStudentLogic, StudentLogic>();
builder.Services.AddTransient<IInterestLogic, InterestLogic>();
builder.Services.AddTransient<IDiyLogic, DiyLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<ITaskLogic, TaskLogic>();
builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<ITeacherLogic, TeacherLogic>();
builder.Services.AddTransient<IMaterialLogic, MaterialLogic>();
builder.Services.AddTransient<ILessonLogic, LessonLogic>();
builder.Services.AddTransient<AbstractSaveToExcelStudent, SaveToExcelStudent>();
builder.Services.AddTransient<AbstractSaveToWordStudent, SaveToWordStudent>();
builder.Services.AddTransient<AbstractSaveToPdfStudent, SaveToPdfStudent>();
builder.Services.AddTransient<AbstractSaveToExcelTeacher, SaveToExcelTeacher>();
builder.Services.AddTransient<AbstractSaveToWordTeacher, SaveToWordTeacher>();
builder.Services.AddTransient<AbstractSaveToPdfTeacher, SaveToPdfTeacher>();
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
@ -12,16 +45,11 @@ if (!app.Environment.IsDevelopment())
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();

View File

@ -0,0 +1,34 @@
@{
ViewData["Title"] = "CreateLesson";
}
<div class="text-center">
<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="title" id="title" /></div>
</div>
<div class="row">
<div class="col-4">Дата проведения:</div>
<div class="col-8">@Html.TextBox("dateEvent" ,"" ,new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Изделие:</div>
<div class="col-8">
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(@ViewBag.Products,"Id", "Title"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Материалы:</div>
<div class="col-8">
@Html.ListBox("materials", (MultiSelectList)ViewBag.Materials)
</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>

View File

@ -0,0 +1,22 @@
@{
ViewData["Title"] = "CreateMaterial";
}
<div class="text-center">
<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="title" id="title" /></div>
</div>
<div class="row m-3">
<div class="col-4">Сфера использования:</div>
<div class="col-8"><textarea cols="50" id="sphereUse" name="sphereUse" rows="5"></textarea>:</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>

View File

@ -0,0 +1,32 @@
@{
ViewData["Title"] = "CreateTask";
}
<div class="text-center">
<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="title" id="title" /></div>
</div>
<div class="row">
<div class="col-4">Дата выдачи:</div>
<div class="col-8">@Html.TextBox("dateIssue" ,"" ,new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Срок сдачи:</div>
<div class="col-8">@Html.TextBox("dateDelivery" ,"" ,new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Материалы:</div>
<div class="col-8">
@Html.ListBox("materials", (MultiSelectList)ViewBag.Materials)
</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>

View File

@ -0,0 +1,21 @@
@{
ViewData["Title"] = "Enter";
}
<div class="text-center">
<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="login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</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>
</form>

View File

@ -0,0 +1,37 @@
@using SchoolAgainStudyContracts.ViewModel;
@model LessonViewModel
@{
ViewData["Title"] = "Setting";
}
<div class="text-center">
<h2 class="display-4">@Model.Title</h2>
</div>
<form method="post" action="@Url.Action("UpdateLesson", "Home", new{idLesson=Model.Id, title="#title", dateEvent="#dateEvent", product="#product", materials="#materials"})">
<div class="row m-3">
<div class="col-8">
<input type="submit" value="Обновить" class="col-md-4 btn btn-primary" />
<input type="button" class="col-md-4 ms-auto btn btn-danger" value="Удалить" onclick="location.href='@Url.Action("DeleteLesson","Home", new {id=Model.Id })'" />
</div>
</div>
<div class="row m-3">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="title" id="title" value="@Model.Title" /></div>
</div>
<div class="row">
<div class="col-4">Дата проведения:</div>
<div class="col-8">@Html.TextBox("dateEvent", Model.DateEvent.Date.ToString("yyyy-MM-dd"),new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Изделие:</div>
<div class="col-8">
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(@ViewBag.Products,"Id", "Title"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Материалы:</div>
<div class="col-8">
@Html.ListBox("materials", (MultiSelectList)ViewBag.Materials)
</div>
</div>
</form>

View File

@ -0,0 +1,69 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<LessonViewModel>
@{
ViewData["Title"] = "Home Page";
}
<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="CreateLesson">Создать занятие</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Название
</th>
<th>
Дата проведения
</th>
<th>
Изделие
</th>
<th>
Материалы
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateEvent)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
<select asp-items="@(new SelectList(item.LessonMaterials,"Key", "Value.Title"))"></select>
</td>
<td>
<a href="@Url.Action("LessonSetting","Home", new {id=item.Id })"
class="btn btn-primary btn-lg">U</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,24 @@
@using SchoolAgainStudyContracts.ViewModel;
@model MaterialViewModel
@{
ViewData["Title"] = "Setting";
}
<div class="text-center">
<h2 class="display-4">@Model.Title</h2>
</div>
<form method="post" action="@Url.Action("UpdateMaterial", "Home", new{id=Model.Id,name="#name",desc="#desc"})">
<div class="row m-3">
<div class="col-8">
<input type="submit" value="Обновить" class="col-md-4 btn btn-primary" />
<input type="button" class="col-md-4 ms-auto btn btn-danger" value="Удалить" onclick="location.href='@Url.Action("DeleteMaterial","Home", new {id=Model.Id })'" />
</div>
</div>
<div class="row m-3">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="name" id="name" value="@Model.Title" /></div>
</div>
<div class="row m-3">
<div class="col-4">Сфера использования:</div>
<div class="col-8"><textarea cols="50" id="sph" name="sph" rows="5">@Model.SphereUse</textarea>:</div>
</div>
</form>

View File

@ -0,0 +1,51 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<MaterialViewModel>
@{
ViewData["Title"] = "Home Page";
}
<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="CreateMaterial">Создать материал</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Название
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
<a href="@Url.Action("MaterialSetting","Home", new {id=item.Id })"
class="btn btn-primary btn-lg">U</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,34 @@
@{
ViewData["Title"] = "Register";
}
<div class="text-center">
<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="name" /></div>
</div>
<div class="row">
<div class="col-4">Должность:</div>
<div class="col-8"><input type="text" name="post" /></div>
</div>
<div class="row">
<div class="col-4">Почта:</div>
<div class="col-8"><input type="text" name="email" /></div>
</div>
<div class="row">
<div class="col-4">Логин:</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>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,35 @@
@using SchoolAgainStudyContracts.ViewModel;
@model TaskViewModel
@{
ViewData["Title"] = "Setting";
}
<div class="text-center">
<h2 class="display-4">@Model.Title</h2>
</div>
<form method="post" action="@Url.Action("UpdateTask", "Home", new{idTask=Model.Id, title="#title", dateIssue="#dateIssue", dateDelivery="#dateDelivery", materials="#materials"})">
<div class="row m-3">
<div class="col-8">
<input type="submit" value="Обновить" class="col-md-4 btn btn-primary" />
<input type="button" class="col-md-4 ms-auto btn btn-danger" value="Удалить" onclick="location.href='@Url.Action("DeleteTask","Home", new {id=Model.Id })'" />
</div>
</div>
<div class="row m-3">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="title" id="title" value="@Model.Title" /></div>
</div>
<div class="row">
<div class="col-4">Дата выдачи:</div>
<div class="col-8">@Html.TextBox("dateIssue" ,Model.DateIssue.Date.ToString("yyyy-MM-dd") ,new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Срок сдачи:</div>
<div class="col-8">@Html.TextBox("dateDelivery" ,Model.DateDelivery.Date.ToString("yyyy-MM-dd") ,new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Материалы:</div>
<div class="col-8">
@Html.ListBox("materials", (MultiSelectList)ViewBag.Materials)
</div>
</div>
</form>

View File

@ -0,0 +1,68 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<TaskViewModel>
@{
ViewData["Title"] = "Home Page";
}
<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="CreateTask">Создать задание</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Название
</th>
<th>
Дата выдачи
</th>
<th>
Срок сдачи
</th>
<th>
Интересы
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateIssue)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateDelivery)
</td>
<td>
<select asp-items="@(new SelectList(item.TaskMaterials,"Key", "Value.Title"))"></select>
</td>
<td>
<a href="@Url.Action("TaskSetting","Home", new {id=item.Id })"
class="btn btn-primary btn-lg">U</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -20,10 +20,25 @@
<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" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">T</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Materials">Материалы</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Lessons">Занятия</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Tasks">Задания</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Reports">Отчеты</a>
</li>
</ul>
</div>