2023-05-19 17:14:57 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Drawing;
|
|
|
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
2023-05-18 23:25:22 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-05-17 21:24:33 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
2023-05-19 17:14:57 +04:00
|
|
|
|
using Newtonsoft.Json;
|
2023-05-18 23:25:22 +04:00
|
|
|
|
using SchoolAgainStudyBusinessLogic.MailWorker;
|
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;
|
|
|
|
|
using SchoolAgainStudyDataModels.Models;
|
2023-05-17 15:31:34 +04:00
|
|
|
|
using StudentWebClient.Models;
|
2023-05-19 17:14:57 +04:00
|
|
|
|
using System.Collections;
|
2023-05-17 15:31:34 +04:00
|
|
|
|
using System.Diagnostics;
|
2023-05-19 17:14:57 +04:00
|
|
|
|
using System.Linq.Expressions;
|
2023-05-17 15:31:34 +04:00
|
|
|
|
|
|
|
|
|
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;
|
2023-05-18 20:23:52 +04:00
|
|
|
|
private readonly IReportLogic _report;
|
2023-05-19 17:14:57 +04:00
|
|
|
|
private readonly IChartLogic _chart;
|
2023-05-18 23:25:22 +04:00
|
|
|
|
private readonly AbstractMailWorker mailSender;
|
2023-05-18 20:23:52 +04:00
|
|
|
|
public HomeController(ILogger<HomeController> logger, IDiyLogic diy,
|
2023-05-19 17:14:57 +04:00
|
|
|
|
IProductLogic product , ITaskLogic task , IInterestLogic interest,
|
|
|
|
|
IStudentLogic student, IReportLogic report, AbstractMailWorker abstractMailWorker, IChartLogic chartLogic)
|
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-18 20:23:52 +04:00
|
|
|
|
_report = report;
|
2023-05-19 17:14:57 +04:00
|
|
|
|
_chart = chartLogic;
|
2023-05-18 23:25:22 +04:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mailSender = abstractMailWorker;
|
|
|
|
|
mailSender?.MailConfig(new MailConfigBindingModel
|
|
|
|
|
{
|
|
|
|
|
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
|
|
|
|
|
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
|
|
|
|
|
SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty,
|
|
|
|
|
SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
|
|
|
|
|
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
|
|
|
|
|
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError(ex, "Ошибка работы с почтой");
|
|
|
|
|
}
|
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,
|
2023-05-18 20:23:52 +04:00
|
|
|
|
Email = email,
|
2023-05-17 15:31:34 +04:00
|
|
|
|
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,
|
2023-05-18 20:23:52 +04:00
|
|
|
|
Email = email,
|
2023-05-17 19:16:54 +04:00
|
|
|
|
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()
|
|
|
|
|
{
|
2023-05-18 23:25:22 +04:00
|
|
|
|
|
2023-05-17 19:16:54 +04:00
|
|
|
|
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("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-05-19 17:14:57 +04:00
|
|
|
|
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) || task <=0 )
|
2023-05-17 19:16:54 +04:00
|
|
|
|
{
|
|
|
|
|
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-18 00:03:47 +04:00
|
|
|
|
Response.Redirect("Diyes");
|
2023-05-17 19:16:54 +04:00
|
|
|
|
}
|
|
|
|
|
[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("Нет задания");
|
|
|
|
|
}
|
2023-05-19 17:14:57 +04:00
|
|
|
|
|
2023-05-17 19:16:54 +04:00
|
|
|
|
|
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-18 00:03:47 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Products()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(_product.ReadList(new ProductSearchModel { StudentId = APIClient.Student.Id }));
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateProduct()
|
|
|
|
|
{
|
|
|
|
|
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]
|
|
|
|
|
public void CreateProduct(string title, string description, string dateCreate, int[] interests)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
|
|
|
|
}
|
2023-05-19 17:14:57 +04:00
|
|
|
|
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate))
|
2023-05-18 00:03:47 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введите название и описане");
|
|
|
|
|
}
|
|
|
|
|
Dictionary<int, IInterest> productInterests = new Dictionary<int, IInterest>();
|
|
|
|
|
foreach (int id in interests)
|
|
|
|
|
{
|
|
|
|
|
productInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id }));
|
|
|
|
|
}
|
|
|
|
|
_product.Create(new ProductBindingModel
|
|
|
|
|
{
|
|
|
|
|
StudentId = APIClient.Student.Id,
|
|
|
|
|
StudentName = APIClient.Student.Name,
|
|
|
|
|
Title = title,
|
|
|
|
|
Description = description,
|
|
|
|
|
DateCreate = DateTime.SpecifyKind(DateTime.Parse(dateCreate), DateTimeKind.Utc),
|
|
|
|
|
ProductInterests = productInterests
|
2023-05-17 19:16:54 +04:00
|
|
|
|
|
2023-05-18 00:03:47 +04:00
|
|
|
|
});
|
|
|
|
|
Response.Redirect("Products");
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult ProductSetting(int id)
|
|
|
|
|
{
|
|
|
|
|
var product = _product.ReadElement(new ProductSearchModel { Id = id });
|
|
|
|
|
var interests = _interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id }).Select(x => new { InterestId = x.Id, InterestName = x.Title }).ToList();
|
|
|
|
|
var selectedInterests = product.ProductInterests.Select(x => x.Key).ToArray();
|
|
|
|
|
ViewBag.Interests = new MultiSelectList(interests, "InterestId", "InterestName", selectedInterests);
|
|
|
|
|
return View(product);
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateProduct(int idDiy, string title, string description, string dateCreate, int[] interests)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(title))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет названия");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(description))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет описания");
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(dateCreate))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Нет даты");
|
|
|
|
|
}
|
2023-05-19 17:14:57 +04:00
|
|
|
|
|
2023-05-18 00:03:47 +04:00
|
|
|
|
|
|
|
|
|
Dictionary<int, IInterest> productInterests = new Dictionary<int, IInterest>();
|
|
|
|
|
foreach (int id in interests)
|
|
|
|
|
{
|
|
|
|
|
productInterests.Add(id, _interest.ReadElement(new InterestSearchModel { Id = id }));
|
|
|
|
|
}
|
|
|
|
|
_product.Update(new ProductBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = idDiy,
|
|
|
|
|
StudentId = APIClient.Student.Id,
|
|
|
|
|
StudentName = APIClient.Student.Name,
|
|
|
|
|
Title = title,
|
|
|
|
|
Description = description,
|
|
|
|
|
DateCreate = DateTime.SpecifyKind(DateTime.Parse(dateCreate), DateTimeKind.Utc),
|
|
|
|
|
ProductInterests = productInterests
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("/Home/Products");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteProduct(int id)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_product.Delete(new ProductBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
});
|
|
|
|
|
Response.Redirect("/Home/Products");
|
|
|
|
|
}
|
2023-05-18 12:56:00 +04:00
|
|
|
|
public IActionResult Reports()
|
|
|
|
|
{
|
2023-05-18 20:23:52 +04:00
|
|
|
|
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-18 12:56:00 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2023-05-18 20:23:52 +04:00
|
|
|
|
|
|
|
|
|
public IActionResult GetPartial(int[] interests, string mode)
|
|
|
|
|
{
|
|
|
|
|
var list = interests.Select(x => _interest.ReadElement(new InterestSearchModel { Id = x })).ToList();
|
|
|
|
|
if (mode.Equals("Excel"))
|
|
|
|
|
{
|
|
|
|
|
_report.SaveInterestLessonToExcelFile
|
|
|
|
|
(new ReportBindingModel { FileName = $"C:\\Users\\Вова\\Documents\\Учеба\\Reports\\{APIClient.Student.Name}-{DateTime.Now.ToString("dd/MM/yyyy")}.xlsx", Interests = list, StudentId = APIClient.Student.Id });
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_report.SaveInterestLessonToWordFile
|
|
|
|
|
(new ReportBindingModel { FileName = $"C:\\Users\\Вова\\Documents\\Учеба\\Reports\\{APIClient.Student.Name}-{DateTime.Now.ToString("dd/MM/yyyy")}.docx", Interests = list, StudentId = APIClient.Student.Id });
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
var items = _report.GetInterestLesson(new ReportBindingModel { Interests = list, StudentId = APIClient.Student.Id});
|
|
|
|
|
return PartialView("_LessonListPartial", items);
|
|
|
|
|
}
|
2023-05-18 22:22:03 +04:00
|
|
|
|
public IActionResult SendingEmail()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult GetPartialForPDF(string dateFrom, string dateTo)
|
|
|
|
|
{
|
|
|
|
|
var _dateFrom = DateTime.SpecifyKind(DateTime.Parse(dateFrom), DateTimeKind.Utc);
|
|
|
|
|
var _dateTo = DateTime.SpecifyKind(DateTime.Parse(dateTo), DateTimeKind.Utc);
|
|
|
|
|
if(_dateFrom > _dateTo)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Не верные даты");
|
|
|
|
|
}
|
2023-05-18 23:25:22 +04:00
|
|
|
|
string path = $"C:\\Users\\Вова\\Documents\\Учеба\\Reports\\{APIClient.Student.Name} от {_dateFrom.ToString("dd/MM/yyyy")}.pdf";
|
2023-05-18 22:22:03 +04:00
|
|
|
|
_report.SaveInterestsToPdfFile
|
2023-05-18 23:25:22 +04:00
|
|
|
|
(new ReportBindingModel { FileName = path,
|
2023-05-18 22:22:03 +04:00
|
|
|
|
DateFrom = _dateFrom, DateTo = _dateTo, StudentId = APIClient.Student.Id});
|
2023-05-18 20:23:52 +04:00
|
|
|
|
|
2023-05-18 22:22:03 +04:00
|
|
|
|
var items = _report.GetInterests(new ReportBindingModel { DateFrom = _dateFrom, DateTo = _dateTo, StudentId = APIClient.Student.Id });
|
2023-05-18 23:25:22 +04:00
|
|
|
|
mailSender.MailSendAsync(new MailSendInfoBindingModel
|
|
|
|
|
{
|
|
|
|
|
MailAddress = APIClient.Student.Email,
|
2023-05-19 17:14:57 +04:00
|
|
|
|
Subject = $"Отчет от {dateFrom} по {dateTo}",
|
2023-05-18 23:25:22 +04:00
|
|
|
|
Path = path
|
|
|
|
|
});
|
2023-05-19 17:14:57 +04:00
|
|
|
|
return PartialView("_InterestListPartial", items);
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult WorksCharts()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
return View(_chart.GetDifferenceInCount(APIClient.Student.Id));
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult ActivityCharts()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Student == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetActivitys(APIClient.Student.Id),
|
|
|
|
|
new JsonSerializerSettings() {
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore});
|
|
|
|
|
return View();
|
2023-05-18 22:22:03 +04:00
|
|
|
|
}
|
2023-05-19 17:14:57 +04:00
|
|
|
|
|
|
|
|
|
|
2023-05-17 15:31:34 +04:00
|
|
|
|
}
|
|
|
|
|
}
|