2023-05-17 15:31:34 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-05-17 21:24:33 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
2023-05-17 15:31:34 +04:00
|
|
|
|
using SchoolAgainStudyContracts.BindingModel;
|
2023-05-17 21:24:33 +04:00
|
|
|
|
using SchoolAgainStudyContracts.BusinessLogicContracts;
|
|
|
|
|
using SchoolAgainStudyContracts.SearchModel;
|
2023-05-17 19:16:54 +04:00
|
|
|
|
using SchoolAgainStudyContracts.ViewModel;
|
2023-05-17 21:24:33 +04:00
|
|
|
|
using SchoolAgainStudyDataModels.Models;
|
2023-05-17 15:31:34 +04:00
|
|
|
|
using StudentWebClient.Models;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace StudentWebClient.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
2023-05-17 21:24:33 +04:00
|
|
|
|
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)
|
2023-05-17 15:31:34 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2023-05-17 21:24:33 +04:00
|
|
|
|
_diy = diy;
|
|
|
|
|
_product = product;
|
|
|
|
|
_task = task;
|
|
|
|
|
_interest = interest;
|
|
|
|
|
_student = student;
|
2023-05-17 15:31:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(APIClient.Student);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
{
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
|
|
|
|
public void Privacy(string name, string email,string login, string password, int scClass)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || scClass<=0 || scClass > 11)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите данные");
|
|
|
|
|
}
|
2023-05-17 21:24:33 +04:00
|
|
|
|
_student.Update( new StudentBindingModel
|
2023-05-17 15:31:34 +04:00
|
|
|
|
{
|
|
|
|
|
Id = APIClient.Student.Id,
|
|
|
|
|
Name = name,
|
|
|
|
|
Email = login,
|
|
|
|
|
Password = password,
|
|
|
|
|
Login = login,
|
|
|
|
|
Class = scClass
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
APIClient.Student.Name = name;
|
|
|
|
|
APIClient.Student.Email = email;
|
|
|
|
|
APIClient.Student.Password = password;
|
|
|
|
|
APIClient.Student.Login = login;
|
|
|
|
|
APIClient.Student.Class = scClass;
|
|
|
|
|
Response.Redirect("Index");
|
|
|
|
|
}
|
2023-05-17 19:16:54 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Enter()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Enter(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите логин и пароль");
|
|
|
|
|
}
|
2023-05-17 21:24:33 +04:00
|
|
|
|
APIClient.Student = _student.ReadElement(new StudentSearchModel { Login = login, Password = password });
|
2023-05-17 19:16:54 +04:00
|
|
|
|
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("Введите логин, пароль и ФИО, класс, почту");
|
|
|
|
|
}
|
2023-05-17 21:24:33 +04:00
|
|
|
|
_student.Create( new StudentBindingModel
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
}
|
2023-05-17 21:24:33 +04:00
|
|
|
|
return View(_interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id}));
|
2023-05-17 19:16:54 +04:00
|
|
|
|
}
|
|
|
|
|
[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("Введите название и описане");
|
|
|
|
|
}
|
2023-05-17 21:24:33 +04:00
|
|
|
|
_interest.Create( new InterestBindingModel
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
StudentId = APIClient.Student.Id,
|
|
|
|
|
Title = title,
|
|
|
|
|
Description = description
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Interests");
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult InterestSetting(int id)
|
|
|
|
|
{
|
2023-05-17 21:24:33 +04:00
|
|
|
|
return View(_interest.ReadElement(new InterestSearchModel { Id = id}));
|
2023-05-17 19:16:54 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateInterest(int id,string name, string desc)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет названия");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(desc))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет описания");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 21:24:33 +04:00
|
|
|
|
_interest.Update( new InterestBindingModel
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
Title = name,
|
|
|
|
|
Description = desc,
|
|
|
|
|
StudentId = APIClient.Student.Id,
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("/Home/Interests");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteInterest(int id)
|
|
|
|
|
{
|
|
|
|
|
|
2023-05-17 21:24:33 +04:00
|
|
|
|
_interest.Delete(new InterestBindingModel
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("/Home/Interests");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Diyes()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
2023-05-17 22:15:18 +04:00
|
|
|
|
return View(_diy.ReadList(new DiySearchModel { StudentId = APIClient.Student.Id}));
|
2023-05-17 19:16:54 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateDiy()
|
|
|
|
|
{
|
2023-05-17 21:24:33 +04:00
|
|
|
|
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");
|
2023-05-17 19:16:54 +04:00
|
|
|
|
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("Введите название и описане");
|
|
|
|
|
}
|
2023-05-17 21:24:33 +04:00
|
|
|
|
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
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
StudentId = APIClient.Student.Id,
|
2023-05-17 21:24:33 +04:00
|
|
|
|
StudentName = APIClient.Student.Name,
|
2023-05-17 19:16:54 +04:00
|
|
|
|
Title = title,
|
2023-05-17 21:24:33 +04:00
|
|
|
|
Description = description,
|
|
|
|
|
DateCreate = DateTime.SpecifyKind(DateTime.Parse(dateCreate), DateTimeKind.Utc),
|
|
|
|
|
TaskId = task,
|
|
|
|
|
TaskName = _task.ReadElement(new TaskSearchModel { Id = task }).Title,
|
|
|
|
|
DiyInterests = diyInterests
|
|
|
|
|
|
|
|
|
|
}) ;
|
2023-05-17 19:16:54 +04:00
|
|
|
|
Response.Redirect("Interests");
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult DiySetting(int id)
|
|
|
|
|
{
|
2023-05-17 21:24:33 +04:00
|
|
|
|
var diy = _diy.ReadElement(new DiySearchModel { Id = id });
|
2023-05-17 22:15:18 +04:00
|
|
|
|
var interests = _interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id}).Select(x => new {InterestId = x.Id, InterestName = x.Title}).ToList();
|
2023-05-17 21:24:33 +04:00
|
|
|
|
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);
|
2023-05-17 19:16:54 +04:00
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
2023-05-17 21:24:33 +04:00
|
|
|
|
public void UpdateDiy(int idDiy,string title, string description, string dateCreate, int task, int[] interests)
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2023-05-17 21:24:33 +04:00
|
|
|
|
if (string.IsNullOrEmpty(title))
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет названия");
|
|
|
|
|
}
|
2023-05-17 21:24:33 +04:00
|
|
|
|
if (string.IsNullOrEmpty(description))
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет описания");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(dateCreate))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет даты");
|
|
|
|
|
}
|
|
|
|
|
if (task <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет задания");
|
|
|
|
|
}
|
|
|
|
|
if (interests.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет интересов");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 21:24:33 +04:00
|
|
|
|
Dictionary<int, IInterest> diyInterests = new Dictionary<int, IInterest>();
|
|
|
|
|
foreach (int id in interests)
|
|
|
|
|
{
|
|
|
|
|
diyInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id }));
|
|
|
|
|
}
|
2023-05-17 22:15:18 +04:00
|
|
|
|
_diy.Update(new DiyBindingModel
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
2023-05-17 22:15:18 +04:00
|
|
|
|
Id = idDiy,
|
2023-05-17 19:16:54 +04:00
|
|
|
|
StudentId = APIClient.Student.Id,
|
2023-05-17 21:24:33 +04:00
|
|
|
|
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
|
2023-05-17 19:16:54 +04:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("/Home/Diyes");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteDiy(int id)
|
|
|
|
|
{
|
|
|
|
|
|
2023-05-17 21:24:33 +04:00
|
|
|
|
_diy.Delete( new DiyBindingModel
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("/Home/Diyes");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 15:31:34 +04:00
|
|
|
|
}
|
|
|
|
|
}
|