удалиение РестАпи + добавление работы с поделками

This commit is contained in:
Володя 2023-05-17 20:24:33 +03:00
parent 6a415df4d9
commit acbc8696a9
11 changed files with 136 additions and 99 deletions

View File

@ -11,9 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudyDataBaseImp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SchoolAgainStudyBusinessLogic", "SchoolAgainStudyBusinessLogic\SchoolAgainStudyBusinessLogic.csproj", "{B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudentRestAPI", "StudentRestAPI\StudentRestAPI.csproj", "{7B94CDC7-96E7-4DBF-86AA-D0D2864A0AF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudentWebClient", "StudentWebClient\StudentWebClient.csproj", "{CCD3824A-BCF3-4497-930E-D71257858CCC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StudentWebClient", "StudentWebClient\StudentWebClient.csproj", "{CCD3824A-BCF3-4497-930E-D71257858CCC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -37,10 +35,6 @@ Global
{B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4AA1719-2B64-4DE1-9C26-D81E1A2BD7A7}.Release|Any CPU.Build.0 = Release|Any CPU
{7B94CDC7-96E7-4DBF-86AA-D0D2864A0AF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B94CDC7-96E7-4DBF-86AA-D0D2864A0AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B94CDC7-96E7-4DBF-86AA-D0D2864A0AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B94CDC7-96E7-4DBF-86AA-D0D2864A0AF0}.Release|Any CPU.Build.0 = Release|Any CPU
{CCD3824A-BCF3-4497-930E-D71257858CCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCD3824A-BCF3-4497-930E-D71257858CCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCD3824A-BCF3-4497-930E-D71257858CCC}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -10,35 +10,10 @@ using SchoolAgainStudyBusinessLogic.OfficePackage.Implements;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddLog4Net("log4net.config");
// Add services to the container.
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>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

View File

@ -7,43 +7,8 @@ namespace StudentWebClient
{
public class APIClient
{
private static readonly HttpClient _client = new();
public static StudentViewModel? Student { get; set; } = null;
public static void Connect(IConfiguration configuration)
{
_client.BaseAddress = new Uri(configuration["IPAddress"]);
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public static T? GetRequest<T>(string requestUrl)
{
var response = _client.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<T>(result);
}
else
{
throw new Exception(result);
}
}
public static void PostRequest<T>(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _client.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(result);
}
}
}
}

View File

@ -1,6 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using SchoolAgainStudyContracts.BindingModel;
using SchoolAgainStudyContracts.BusinessLogicContracts;
using SchoolAgainStudyContracts.SearchModel;
using SchoolAgainStudyContracts.ViewModel;
using SchoolAgainStudyDataModels.Models;
using StudentWebClient.Models;
using System.Diagnostics;
@ -9,10 +13,19 @@ namespace StudentWebClient.Controllers
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
private readonly ITaskLogic _task;
private readonly IDiyLogic _diy;
private readonly IProductLogic _product;
private readonly IInterestLogic _interest;
private readonly IStudentLogic _student;
public HomeController(ILogger<HomeController> logger, IDiyLogic diy, IProductLogic product , ITaskLogic task , IInterestLogic interest, IStudentLogic student)
{
_logger = logger;
_diy = diy;
_product = product;
_task = task;
_interest = interest;
_student = student;
}
public IActionResult Index()
@ -51,7 +64,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Введите данные");
}
APIClient.PostRequest("api/student/updatedata", new StudentBindingModel
_student.Update( new StudentBindingModel
{
Id = APIClient.Student.Id,
Name = name,
@ -81,7 +94,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Введите логин и пароль");
}
APIClient.Student = APIClient.GetRequest<StudentViewModel>($"api/student/login?login={login}&password={password}");
APIClient.Student = _student.ReadElement(new StudentSearchModel { Login = login, Password = password });
if (APIClient.Student == null)
{
throw new Exception("Неверный логин/пароль");
@ -101,7 +114,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Введите логин, пароль и ФИО, класс, почту");
}
APIClient.PostRequest("api/student/register", new StudentBindingModel
_student.Create( new StudentBindingModel
{
Name = name,
Email = login,
@ -119,7 +132,7 @@ namespace StudentWebClient.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<InterestViewModel>>($"api/main/getinterests?studentId={APIClient.Student.Id}"));
return View(_interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id}));
}
[HttpGet]
public IActionResult CreateInterest()
@ -137,7 +150,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Введите название и описане");
}
APIClient.PostRequest("api/main/createinterest", new InterestBindingModel
_interest.Create( new InterestBindingModel
{
StudentId = APIClient.Student.Id,
Title = title,
@ -148,7 +161,7 @@ namespace StudentWebClient.Controllers
[HttpGet]
public IActionResult InterestSetting(int id)
{
return View(APIClient.GetRequest<InterestViewModel>($"api/main/getinterest?interestId={id}"));
return View(_interest.ReadElement(new InterestSearchModel { Id = id}));
}
[HttpPost]
public void UpdateInterest(int id,string name, string desc)
@ -164,7 +177,7 @@ namespace StudentWebClient.Controllers
throw new Exception("Нет описания");
}
APIClient.PostRequest("api/main/UpdateInterest", new InterestBindingModel
_interest.Update( new InterestBindingModel
{
Id = id,
Title = name,
@ -178,7 +191,7 @@ namespace StudentWebClient.Controllers
public void DeleteInterest(int id)
{
APIClient.PostRequest("api/main/DeleteInterest", new InterestBindingModel
_interest.Delete(new InterestBindingModel
{
Id = id,
});
@ -192,12 +205,15 @@ namespace StudentWebClient.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<DiyViewModel>>($"api/main/GetDiyes?studentId={APIClient.Student.Id}"));
return View(_diy.ReadList(new DiySearchModel { Id = APIClient.Student.Id}));
}
[HttpGet]
public IActionResult CreateDiy()
{
ViewBag.Tasks = APIClient.GetRequest<List<TaskViewModel>>("api/shop/GetTaskList");
ViewBag.Tasks = _task.ReadList(null);
var list = _interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id});
var simpInterest = list.Select(x => new { InterestId = x.Id, InterestName = x.Title });
ViewBag.Interests = new MultiSelectList(simpInterest, "InterestId", "InterestName");
return View();
}
[HttpPost]
@ -211,29 +227,45 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Введите название и описане");
}
APIClient.PostRequest("api/main/creatediy", new InterestBindingModel
Dictionary<int, IInterest> diyInterests = new Dictionary<int, IInterest>();
foreach(int id in interests)
{
diyInterests.Add(id,_interest.ReadElement(new InterestSearchModel { Id = id}));
}
_diy.Create(new DiyBindingModel
{
StudentId = APIClient.Student.Id,
StudentName = APIClient.Student.Name,
Title = title,
Description = description
});
Description = description,
DateCreate = DateTime.SpecifyKind(DateTime.Parse(dateCreate), DateTimeKind.Utc),
TaskId = task,
TaskName = _task.ReadElement(new TaskSearchModel { Id = task }).Title,
DiyInterests = diyInterests
}) ;
Response.Redirect("Interests");
}
[HttpGet]
public IActionResult DiySetting(int id)
{
return View(APIClient.GetRequest<DiyViewModel>($"api/main/getdiy?diyId={id}"));
var diy = _diy.ReadElement(new DiySearchModel { Id = id });
var interests = _interest.ReadList(null).Select(x => new {InterestId = x.Id, InterestName = x.Title}).ToList();
var selectedInterests = diy.DiyInterests.Select(x => x.Key).ToArray();
ViewBag.Interests = new MultiSelectList(interests, "InterestId", "InterestName", selectedInterests);
ViewBag.Tasks = _task.ReadList(null);
return View(diy);
}
[HttpPost]
public void UpdateDiy(int id, string name, string desc,string dateCreate, int task, int[] interests)
public void UpdateDiy(int idDiy,string title, string description, string dateCreate, int task, int[] interests)
{
if (string.IsNullOrEmpty(name))
if (string.IsNullOrEmpty(title))
{
throw new Exception("Нет названия");
}
if (string.IsNullOrEmpty(desc))
if (string.IsNullOrEmpty(description))
{
throw new Exception("Нет описания");
}
@ -250,12 +282,21 @@ namespace StudentWebClient.Controllers
throw new Exception("Нет интересов");
}
APIClient.PostRequest("api/main/UpdateDiy", new InterestBindingModel
Dictionary<int, IInterest> diyInterests = new Dictionary<int, IInterest>();
foreach (int id in interests)
{
diyInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id }));
}
_diy.Create(new DiyBindingModel
{
Id = id,
Title = name,
Description = desc,
StudentId = APIClient.Student.Id,
StudentName = APIClient.Student.Name,
Title = title,
Description = description,
DateCreate = DateTime.SpecifyKind(DateTime.Parse(dateCreate), DateTimeKind.Utc),
TaskId = task,
TaskName = _task.ReadElement(new TaskSearchModel { Id = task }).Title,
DiyInterests = diyInterests
});
Response.Redirect("/Home/Diyes");
@ -264,7 +305,7 @@ namespace StudentWebClient.Controllers
public void DeleteDiy(int id)
{
APIClient.PostRequest("api/main/DeletDiy", new DiyBindingModel
_diy.Delete( new DiyBindingModel
{
Id = id,
});

View File

@ -1,10 +1,43 @@
using SchoolAgainStudyBusinessLogic.BusinessLogic;
using SchoolAgainStudyBusinessLogic.OfficePackage.Implements;
using SchoolAgainStudyBusinessLogic.OfficePackage;
using SchoolAgainStudyBusinessLogic.Íîâàÿ_ïàïêà;
using SchoolAgainStudyContracts.BusinessLogicContracts;
using SchoolAgainStudyContracts.StorageContracts;
using SchoolAgainStudyDataBaseImplements.Implements;
using StudentWebClient;
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();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -7,6 +7,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

View File

@ -24,7 +24,12 @@
<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-4">Интересы:</div>
<div class="col-8">
@Html.ListBox("interests", (MultiSelectList)ViewBag.Interests)
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>

View File

@ -9,7 +9,7 @@
<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="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("DeleteInterest","Home", new {id=Model.Id })'" />
</div>
</div>

View File

@ -35,6 +35,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Interests">Интересы</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Diyes">Поделки</a>
</li>
</ul>
</div>

View File

@ -5,7 +5,7 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"IPAddress": "http://localhost:5018/"
"AllowedHosts": "*"
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="c:/temp/StudentWebClient.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="RollingFile" />
</root>
</log4net>