diff --git a/SchoolAgainStudy/SchoolAgainStudy.sln b/SchoolAgainStudy/SchoolAgainStudy.sln index 9e66ed4..c72504c 100644 --- a/SchoolAgainStudy/SchoolAgainStudy.sln +++ b/SchoolAgainStudy/SchoolAgainStudy.sln @@ -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 diff --git a/SchoolAgainStudy/StudentRestAPI/Program.cs b/SchoolAgainStudy/StudentRestAPI/Program.cs index 6ecacfd..e1de723 100644 --- a/SchoolAgainStudy/StudentRestAPI/Program.cs +++ b/SchoolAgainStudy/StudentRestAPI/Program.cs @@ -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(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); - -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/SchoolAgainStudy/StudentWebClient/APIClient.cs b/SchoolAgainStudy/StudentWebClient/APIClient.cs index 521e962..e726b17 100644 --- a/SchoolAgainStudy/StudentWebClient/APIClient.cs +++ b/SchoolAgainStudy/StudentWebClient/APIClient.cs @@ -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(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } - } - - public static void PostRequest(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); - } - } } } \ No newline at end of file diff --git a/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs b/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs index 26fc385..554e8d1 100644 --- a/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs +++ b/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs @@ -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 _logger; - - public HomeController(ILogger logger) + private readonly ITaskLogic _task; + private readonly IDiyLogic _diy; + private readonly IProductLogic _product; + private readonly IInterestLogic _interest; + private readonly IStudentLogic _student; + public HomeController(ILogger 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($"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>($"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($"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>($"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>("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 diyInterests = new Dictionary(); + 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($"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 diyInterests = new Dictionary(); + 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, }); diff --git a/SchoolAgainStudy/StudentWebClient/Program.cs b/SchoolAgainStudy/StudentWebClient/Program.cs index 7ebc55a..e9305d6 100644 --- a/SchoolAgainStudy/StudentWebClient/Program.cs +++ b/SchoolAgainStudy/StudentWebClient/Program.cs @@ -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(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); // 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()) { diff --git a/SchoolAgainStudy/StudentWebClient/StudentWebClient.csproj b/SchoolAgainStudy/StudentWebClient/StudentWebClient.csproj index 80e9c8e..8be91af 100644 --- a/SchoolAgainStudy/StudentWebClient/StudentWebClient.csproj +++ b/SchoolAgainStudy/StudentWebClient/StudentWebClient.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,6 +7,11 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/CreateDiy.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/CreateDiy.cshtml index e50fcaf..3a6652a 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Home/CreateDiy.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/CreateDiy.cshtml @@ -24,7 +24,12 @@ - +
+
Интересы:
+
+ @Html.ListBox("interests", (MultiSelectList)ViewBag.Interests) +
+
diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/InterestSetting.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/InterestSetting.cshtml index aad9f3d..21a422e 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Home/InterestSetting.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/InterestSetting.cshtml @@ -9,7 +9,7 @@
- +
diff --git a/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml index c1a9e92..f136e27 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml @@ -35,6 +35,9 @@ +
diff --git a/SchoolAgainStudy/StudentWebClient/appsettings.json b/SchoolAgainStudy/StudentWebClient/appsettings.json index fd073d8..ada3ee6 100644 --- a/SchoolAgainStudy/StudentWebClient/appsettings.json +++ b/SchoolAgainStudy/StudentWebClient/appsettings.json @@ -5,7 +5,7 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*", - "IPAddress": "http://localhost:5018/" + "AllowedHosts": "*" + } diff --git a/SchoolAgainStudy/StudentWebClient/log4net.config b/SchoolAgainStudy/StudentWebClient/log4net.config new file mode 100644 index 0000000..e38a25c --- /dev/null +++ b/SchoolAgainStudy/StudentWebClient/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file