Вход + Регистрация + CRUD интересов

This commit is contained in:
Володя 2023-05-17 18:16:54 +03:00
parent 9a55ee6ee4
commit 6a415df4d9
11 changed files with 437 additions and 32 deletions

View File

@ -0,0 +1,12 @@
{
"profiles": {
"SchoolAgainStudyBusinessLogic": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:57331;http://localhost:57333"
}
}
}

View File

@ -0,0 +1,12 @@
{
"profiles": {
"SchoolAgainStudyContracts": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:57332;http://localhost:57334"
}
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using SchoolAgainStudyContracts.BindingModel; using SchoolAgainStudyContracts.BindingModel;
using SchoolAgainStudyContracts.ViewModel;
using StudentWebClient.Models; using StudentWebClient.Models;
using System.Diagnostics; using System.Diagnostics;
@ -50,7 +51,7 @@ namespace StudentWebClient.Controllers
{ {
throw new Exception("Введите данные"); throw new Exception("Введите данные");
} }
APIClient.PostRequest("api/client/updatedata", new StudentBindingModel APIClient.PostRequest("api/student/updatedata", new StudentBindingModel
{ {
Id = APIClient.Student.Id, Id = APIClient.Student.Id,
Name = name, Name = name,
@ -67,5 +68,208 @@ namespace StudentWebClient.Controllers
APIClient.Student.Class = scClass; APIClient.Student.Class = scClass;
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIClient.Student = APIClient.GetRequest<StudentViewModel>($"api/student/login?login={login}&password={password}");
if (APIClient.Student == null)
{
throw new Exception("Неверный логин/пароль");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string name, string email, string login, string password, int scClass)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || scClass <= 0 || scClass > 11)
{
throw new Exception("Введите логин, пароль и ФИО, класс, почту");
}
APIClient.PostRequest("api/student/register", new StudentBindingModel
{
Name = name,
Email = login,
Password = password,
Login = login,
Class = scClass
});
Response.Redirect("Enter");
return;
}
[HttpGet]
public IActionResult Interests()
{
if (APIClient.Student == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<InterestViewModel>>($"api/main/getinterests?studentId={APIClient.Student.Id}"));
}
[HttpGet]
public IActionResult CreateInterest()
{
return View();
}
[HttpPost]
public void CreateInterest(string title,string description)
{
if (APIClient.Student == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description))
{
throw new Exception("Введите название и описане");
}
APIClient.PostRequest("api/main/createinterest", new InterestBindingModel
{
StudentId = APIClient.Student.Id,
Title = title,
Description = description
});
Response.Redirect("Interests");
}
[HttpGet]
public IActionResult InterestSetting(int id)
{
return View(APIClient.GetRequest<InterestViewModel>($"api/main/getinterest?interestId={id}"));
}
[HttpPost]
public void UpdateInterest(int id,string name, string desc)
{
if (string.IsNullOrEmpty(name))
{
throw new Exception("Нет названия");
}
if (string.IsNullOrEmpty(desc))
{
throw new Exception("Нет описания");
}
APIClient.PostRequest("api/main/UpdateInterest", new InterestBindingModel
{
Id = id,
Title = name,
Description = desc,
StudentId = APIClient.Student.Id,
});
Response.Redirect("/Home/Interests");
}
public void DeleteInterest(int id)
{
APIClient.PostRequest("api/main/DeleteInterest", new InterestBindingModel
{
Id = id,
});
Response.Redirect("/Home/Interests");
}
[HttpGet]
public IActionResult Diyes()
{
if (APIClient.Student == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<DiyViewModel>>($"api/main/GetDiyes?studentId={APIClient.Student.Id}"));
}
[HttpGet]
public IActionResult CreateDiy()
{
ViewBag.Tasks = APIClient.GetRequest<List<TaskViewModel>>("api/shop/GetTaskList");
return View();
}
[HttpPost]
public void CreateDiy(string title, string description, string dateCreate, int task, int[] interests )
{
if (APIClient.Student == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) && task <=0 || interests.Length==0)
{
throw new Exception("Введите название и описане");
}
APIClient.PostRequest("api/main/creatediy", new InterestBindingModel
{
StudentId = APIClient.Student.Id,
Title = title,
Description = description
});
Response.Redirect("Interests");
}
[HttpGet]
public IActionResult DiySetting(int id)
{
return View(APIClient.GetRequest<DiyViewModel>($"api/main/getdiy?diyId={id}"));
}
[HttpPost]
public void UpdateDiy(int id, string name, string desc,string dateCreate, int task, int[] interests)
{
if (string.IsNullOrEmpty(name))
{
throw new Exception("Нет названия");
}
if (string.IsNullOrEmpty(desc))
{
throw new Exception("Нет описания");
}
if (string.IsNullOrEmpty(dateCreate))
{
throw new Exception("Нет даты");
}
if (task <= 0)
{
throw new Exception("Нет задания");
}
if (interests.Length == 0)
{
throw new Exception("Нет интересов");
}
APIClient.PostRequest("api/main/UpdateDiy", new InterestBindingModel
{
Id = id,
Title = name,
Description = desc,
StudentId = APIClient.Student.Id,
});
Response.Redirect("/Home/Diyes");
}
public void DeleteDiy(int id)
{
APIClient.PostRequest("api/main/DeletDiy", new DiyBindingModel
{
Id = id,
});
Response.Redirect("/Home/Diyes");
}
} }
} }

View File

@ -1,33 +1,8 @@
using SchoolAgainStudyBusinessLogic.BusinessLogic;
using SchoolAgainStudyBusinessLogic.Íîâàÿ_ïàïêà;
using SchoolAgainStudyContracts.BusinessLogicContracts;
using SchoolAgainStudyContracts.StorageContracts;
using SchoolAgainStudyDataBaseImplements.Implements;
using StudentWebClient; using StudentWebClient;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
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>();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration); APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
@ -45,3 +20,4 @@ app.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run(); app.Run();

View File

@ -0,0 +1,33 @@
@{
ViewData["Title"] = "CreateDiy";
}
<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="description" name="description" rows="5"></textarea>:</div>
</div>
<div class="row">
<div class="col-4">Дата создания:</div>
<div class="col-8">@Html.TextBox("dateCreate" ,"" ,new {type="Date"})</div>
</div>
<div class="row">
<div class="col-4">Задание:</div>
<div class="col-8">
<select id="task" name="task" class="form-control" asp-items="@(new SelectList(@ViewBag.Tasks,"Id", "Title"))"></select>
</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"] = "CreateInterest";
}
<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="description" name="description" 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,63 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<DiyViewModel>
@{
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="CreateDiy">Создать поделку</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.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateCreate)
</td>
<td>
@Html.DisplayFor(modelItem => item.TaskName)
</td>
<td>
<a href="@Url.Action("DiySetting","Home", new {id=item.Id })"
class="btn btn-primary btn-lg">U</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,26 @@
@using SchoolAgainStudyContracts.ViewModel;
@model InterestViewModel
@{
ViewData["Title"] = "Setting";
}
<div class="text-center">
<h2 class="display-4">@Model.Title</h2>
</div>
<form method="post" action="@Url.Action("UpdateInterest", "Home", new{id=Model.Id,name="#name",desc="#desc"})">
<div class="row m-3">
<div class="col-8">
<input type="button" 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("DeleteInterest","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="desc" name="desc" rows="5">@Model.Description</textarea>:</div>
</div>
</form>

View File

@ -0,0 +1,51 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<InterestViewModel>
@{
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="CreateInterest">Создать интерес</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("InterestSetting","Home", new {id=item.Id })"
class="btn btn-primary btn-lg">U</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -16,7 +16,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Класс:</div> <div class="col-4">Класс:</div>
<div class="col-8"><input type="number" name="class" /></div> <div class="col-8"><input type="number" name="scClass" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Логин:</div> <div class="col-4">Логин:</div>
@ -26,10 +26,7 @@
<div class="col-4">Пароль:</div> <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>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="fio" /></div>
</div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>

View File

@ -24,7 +24,16 @@
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse"> <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1"> <ul class="navbar-nav flex-grow-1">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Заказы</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="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="Interests">Интересы</a>
</li> </li>
</ul> </ul>