diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfStorekeeper.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfStorekeeper.cs index b0f252c..a1681d2 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfStorekeeper.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfStorekeeper.cs @@ -10,7 +10,7 @@ namespace UniversityBusinessLogic.OfficePackage CreatePdf(info); CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "4 cm" }); + CreateTable(new List { "6cm", "6cm", "6cm", "3cm", "4 cm" }); CreateRow(new PdfRowParameters { diff --git a/University/UniversityClientApp/Controllers/HomeController.cs b/University/UniversityClientApp/Controllers/HomeController.cs index 5c6372e..535eb19 100644 --- a/University/UniversityClientApp/Controllers/HomeController.cs +++ b/University/UniversityClientApp/Controllers/HomeController.cs @@ -197,8 +197,8 @@ namespace UniversityClientApp.Controllers { APIStorekeeper.PostRequest("api/teacher/loadreporttoword", new ReportBindingModel { - FileName = "C:\\ВременныеОтчёты\\TeachersAndStudents.docx" - }); + FileName = $"C:\\ВременныеОтчёты\\TeachersAndStudents.docx" + }); return GetWordFile(); } @@ -206,7 +206,7 @@ namespace UniversityClientApp.Controllers { APIStorekeeper.PostRequest("api/teacher/loadreporttoexcel", new ReportBindingModel { - FileName = "C:\\ВременныеОтчёты\\TeachersAndStudents.xlsx" + FileName = $"C:\\ВременныеОтчёты\\TeachersAndStudents.xlsx" }); return GetExcelFile(); } diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index 590d3f0..f40e719 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -1,461 +1,461 @@ -using DocumentFormat.OpenXml.Office2010.Excel; -using DocumentFormat.OpenXml.Wordprocessing; -using Microsoft.AspNetCore.Mvc; -using PlumbingRepairClientApp; -using System.Diagnostics; -using UniversityClientAppWorker.Models; -using UniversityContracts.BindingModels; -using UniversityContracts.ViewModels; -using UniversityDatabaseImplement.Models; -using UniversityDataModels.Enums; -using UniversityDataModels.Models; -using static System.Runtime.InteropServices.JavaScript.JSType; - -namespace UniversityClientAppWorker.Controllers -{ - public class HomeController : Controller - { - private readonly ILogger _logger; - - public HomeController(ILogger logger) - { - _logger = logger; - } - [HttpGet] - public async Task Index() - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - ViewBag.Teachers = APIClient.GetRequest>($"api/teacher/getallteachers"); - var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync>($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); - - return View(planOfStudys); - } - [HttpGet] - public async Task InfoPlanOfStudy(int id) - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - var obj1 = APIClient.GetRequest>($"api/teacher/getallteachers"); - ViewBag.Teachers = obj1; - - var obj = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={id}&userId={APIClient.User.Id}"); - return View(obj); - } - [HttpPost] - public void CreatePlanOfStudy(string profile, string formOfStudy, List teacherIds) - { - if (APIClient.User == null) - { - throw new Exception("Вход только авторизованным пользователям"); - } - if (string.IsNullOrEmpty(formOfStudy) || string.IsNullOrEmpty(profile)) - { - throw new Exception("Введите данные профиля и формы обучения"); - } - APIClient.PostRequest("api/planofstudys/createplanofstudy", new PlanOfStudyBindingModel - { - Profile = profile, - FormOfStudy = formOfStudy, - UserId = APIClient.User.Id, - PlanOfStudyTeachers = teacherIds.ToDictionary(id => id, id => (ITeacherModel)null) - }); - Response.Redirect("Index"); - } - [HttpPost] - public void DeletePlanOfStudy(int id) - { - if (id == 0) - { - throw new Exception("id не может быть равен 0"); - } - APIClient.PostRequest("api/planofstudys/deleteplanofstudy", new PlanOfStudyBindingModel - { - Id = id - }); - Response.Redirect("Index"); - } - [HttpPost] - public void UpdatePlanOfStudy(int id, string profile, string formOfStudy, List teacherIds) - { - if (id == 0) - { - throw new Exception("id не может быть равен 0"); - } - var planOfStudyTeachers = teacherIds.ToDictionary(id => id, id => (ITeacherModel)null); - APIClient.PostRequest("api/planofstudys/updateplanofstudy", new PlanOfStudyBindingModel - { - Id = id, - Profile = profile, - FormOfStudy = formOfStudy, - PlanOfStudyTeachers = planOfStudyTeachers - }); - Response.Redirect("Index"); - } - [HttpGet] - public IActionResult Privacy() - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.User); - } - [HttpPost] - public void Privacy(string login, string password, string email) - { - if (APIClient.User == null) - { - throw new Exception("Вход только авторизованным пользователям"); - } - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) - { - throw new Exception("Введите логин, пароль и почту"); - } - APIClient.PostRequest("api/user/updatedata", new UserViewModel - { - Id = APIClient.User.Id, - Email = email, - Login = login, - Password = password - }); - - APIClient.User.Login = login; - APIClient.User.Email = email; - APIClient.User.Password = password; - Response.Redirect("Index"); - } - [HttpGet] - public IActionResult Attestations() - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); - ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); - var obj = APIClient.GetRequest>($"api/attestation/getattestations?userId={APIClient.User.Id}"); - return View(obj); - } - [HttpPost] - public void CreateAttestation(string formOfEvaluation, int student, AttestationScore score) - { - if (APIClient.User == null) - { - throw new Exception("Вход только авторизованным"); - } - if (string.IsNullOrEmpty(formOfEvaluation) || student == 0) - { - throw new Exception("Введите форму оценивания и выберите студента"); - } - var Student = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}"); - - if(Student == null) - { - throw new Exception("Студент не найден"); - } - APIClient.PostRequest("api/attestation/createattestation", new AttestationBindingModel - { - UserId = APIClient.User.Id, - FormOfEvaluation = formOfEvaluation, - StudentId = student, - StudentName = Student.Name, - Score = score - }); - Response.Redirect("Attestations"); - } - [HttpGet] - public IActionResult InfoAttestation(int id) - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); - ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); - var obj = APIClient.GetRequest($"api/attestation/getattestation?userId={APIClient.User.Id}&id={id}"); - return View(obj); - } - [HttpPost] - public void UpdateAttestation(int id, string formOfEvaluation, int student, AttestationScore score) - { - if (APIClient.User == null) - { - throw new Exception("Вход только авторизованным"); - } - if (string.IsNullOrEmpty(formOfEvaluation) || student == 0) - { - throw new Exception("Введите форму оценивания и выберите студента"); - } - var Student = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}"); - - if (Student == null) - { - throw new Exception("Студент не найден"); - } - APIClient.PostRequest("api/attestation/updateattestation", new AttestationBindingModel - { - Id = id, - FormOfEvaluation = formOfEvaluation, - StudentId = student, - StudentName = Student.Name, - Score = score - }); - Response.Redirect("Attestations"); - } - [HttpPost] +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Wordprocessing; +using Microsoft.AspNetCore.Mvc; +using PlumbingRepairClientApp; +using System.Diagnostics; +using UniversityClientAppWorker.Models; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; +using UniversityDatabaseImplement.Models; +using UniversityDataModels.Enums; +using UniversityDataModels.Models; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace UniversityClientAppWorker.Controllers +{ + public class HomeController : Controller + { + private readonly ILogger _logger; + + public HomeController(ILogger logger) + { + _logger = logger; + } + [HttpGet] + public async Task Index() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Teachers = APIClient.GetRequest>($"api/teacher/getallteachers"); + var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync>($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); + + return View(planOfStudys); + } + [HttpGet] + public async Task InfoPlanOfStudy(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + var obj1 = APIClient.GetRequest>($"api/teacher/getallteachers"); + ViewBag.Teachers = obj1; + + var obj = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={id}&userId={APIClient.User.Id}"); + return View(obj); + } + [HttpPost] + public void CreatePlanOfStudy(string profile, string formOfStudy, List teacherIds) + { + if (APIClient.User == null) + { + throw new Exception("Вход только авторизованным пользователям"); + } + if (string.IsNullOrEmpty(formOfStudy) || string.IsNullOrEmpty(profile)) + { + throw new Exception("Введите данные профиля и формы обучения"); + } + APIClient.PostRequest("api/planofstudys/createplanofstudy", new PlanOfStudyBindingModel + { + Profile = profile, + FormOfStudy = formOfStudy, + UserId = APIClient.User.Id, + PlanOfStudyTeachers = teacherIds.ToDictionary(id => id, id => (ITeacherModel)null) + }); + Response.Redirect("Index"); + } + [HttpPost] + public void DeletePlanOfStudy(int id) + { + if (id == 0) + { + throw new Exception("id не может быть равен 0"); + } + APIClient.PostRequest("api/planofstudys/deleteplanofstudy", new PlanOfStudyBindingModel + { + Id = id + }); + Response.Redirect("Index"); + } + [HttpPost] + public void UpdatePlanOfStudy(int id, string profile, string formOfStudy, List teacherIds) + { + if (id == 0) + { + throw new Exception("id не может быть равен 0"); + } + var planOfStudyTeachers = teacherIds.ToDictionary(id => id, id => (ITeacherModel)null); + APIClient.PostRequest("api/planofstudys/updateplanofstudy", new PlanOfStudyBindingModel + { + Id = id, + Profile = profile, + FormOfStudy = formOfStudy, + PlanOfStudyTeachers = planOfStudyTeachers + }); + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Privacy() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.User); + } + [HttpPost] + public void Privacy(string login, string password, string email) + { + if (APIClient.User == null) + { + throw new Exception("Вход только авторизованным пользователям"); + } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception("Введите логин, пароль и почту"); + } + APIClient.PostRequest("api/user/updatedata", new UserViewModel + { + Id = APIClient.User.Id, + Email = email, + Login = login, + Password = password + }); + + APIClient.User.Login = login; + APIClient.User.Email = email; + APIClient.User.Password = password; + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Attestations() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); + ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); + var obj = APIClient.GetRequest>($"api/attestation/getattestations?userId={APIClient.User.Id}"); + return View(obj); + } + [HttpPost] + public void CreateAttestation(string formOfEvaluation, int student, AttestationScore score) + { + if (APIClient.User == null) + { + throw new Exception("Вход только авторизованным"); + } + if (string.IsNullOrEmpty(formOfEvaluation) || student == 0) + { + throw new Exception("Введите форму оценивания и выберите студента"); + } + var Student = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}"); + + if(Student == null) + { + throw new Exception("Студент не найден"); + } + APIClient.PostRequest("api/attestation/createattestation", new AttestationBindingModel + { + UserId = APIClient.User.Id, + FormOfEvaluation = formOfEvaluation, + StudentId = student, + StudentName = Student.Name, + Score = score + }); + Response.Redirect("Attestations"); + } + [HttpGet] + public IActionResult InfoAttestation(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); + ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); + var obj = APIClient.GetRequest($"api/attestation/getattestation?userId={APIClient.User.Id}&id={id}"); + return View(obj); + } + [HttpPost] + public void UpdateAttestation(int id, string formOfEvaluation, int student, AttestationScore score) + { + if (APIClient.User == null) + { + throw new Exception("Вход только авторизованным"); + } + if (string.IsNullOrEmpty(formOfEvaluation) || student == 0) + { + throw new Exception("Введите форму оценивания и выберите студента"); + } + var Student = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}"); + + if (Student == null) + { + throw new Exception("Студент не найден"); + } + APIClient.PostRequest("api/attestation/updateattestation", new AttestationBindingModel + { + Id = id, + FormOfEvaluation = formOfEvaluation, + StudentId = student, + StudentName = Student.Name, + Score = score + }); + Response.Redirect("Attestations"); + } + [HttpPost] public void DeleteAttestation(int id) { - if (id == 0) - { - throw new Exception("id не может быть равен 0"); - } - APIClient.PostRequest("api/attestation/deleteattestation", new PlanOfStudyBindingModel - { - Id = id - }); + if (id == 0) + { + throw new Exception("id не может быть равен 0"); + } + APIClient.PostRequest("api/attestation/deleteattestation", new PlanOfStudyBindingModel + { + Id = id + }); Response.Redirect("Attestations"); - } - [HttpGet] - public async Task Students() - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync> - ($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); - ViewBag.PlanOfStudys = planOfStudys; - return View(APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}")); - } - [HttpPost] - public async Task CreateStudent(string name, int planOfStudy, string phoneNumber) - { - if (APIClient.User == null) - { - throw new Exception("Вход только авторизованным"); - } - if (string.IsNullOrEmpty(name) || planOfStudy == 0 || string.IsNullOrEmpty(phoneNumber)) - { - throw new Exception("Введите ФИО, план обучения и телефон"); - } - var PlanOfStudy = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={planOfStudy}"); + } + [HttpGet] + public async Task Students() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync> + ($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); + ViewBag.PlanOfStudys = planOfStudys; + return View(APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}")); + } + [HttpPost] + public async Task CreateStudent(string name, int planOfStudy, string phoneNumber) + { + if (APIClient.User == null) + { + throw new Exception("Вход только авторизованным"); + } + if (string.IsNullOrEmpty(name) || planOfStudy == 0 || string.IsNullOrEmpty(phoneNumber)) + { + throw new Exception("Введите ФИО, план обучения и телефон"); + } + var PlanOfStudy = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={planOfStudy}"); if(PlanOfStudy == null) { throw new Exception("План обучения не найден"); - } - APIClient.PostRequest("api/student/createstudent", new StudentBindingModel - { - UserId = APIClient.User.Id, - Name = name, - PlanOfStudyId = planOfStudy, - PlanOfStudyProfile = PlanOfStudy.Profile, - PhoneNumber = phoneNumber, - - }); - return Redirect("/Home/Students"); - } + } + APIClient.PostRequest("api/student/createstudent", new StudentBindingModel + { + UserId = APIClient.User.Id, + Name = name, + PlanOfStudyId = planOfStudy, + PlanOfStudyProfile = PlanOfStudy.Profile, + PhoneNumber = phoneNumber, + + }); + return Redirect("/Home/Students"); + } [HttpGet] - public async Task InfoStudent(int id) + public async Task InfoStudent(int id) { if (APIClient.User == null) { return Redirect("~/Home/Enter"); - } + } if(id == 0) { throw new Exception("id не может быть 0"); - } - var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync> - ($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); - ViewBag.PlanOfStudys = planOfStudys; - var obj = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={id}"); - return View(obj); - } - [HttpPost] + } + var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync> + ($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); + ViewBag.PlanOfStudys = planOfStudys; + var obj = APIClient.GetRequest($"api/student/getstudent?userId={APIClient.User.Id}&studentId={id}"); + return View(obj); + } + [HttpPost] public async Task UpdateStudent(int id, string name, int planOfStudy, string phoneNumber) { - if (APIClient.User == null) - { - throw new Exception("Вход только авторизованным"); - } + if (APIClient.User == null) + { + throw new Exception("Вход только авторизованным"); + } if(id == 0) { throw new Exception("id не может быть 0"); + } + if (string.IsNullOrEmpty(name) || planOfStudy == 0 || string.IsNullOrEmpty(phoneNumber)) + { + throw new Exception("Введите ФИО, план обучения и телефон"); } - if (string.IsNullOrEmpty(name) || planOfStudy == 0 || string.IsNullOrEmpty(phoneNumber)) - { - throw new Exception("Введите ФИО, план обучения и телефон"); - } - var PlanOfStudy = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={planOfStudy}"); + var PlanOfStudy = await APIClient.GetRequestPlanOfStudyAsync($"api/planofstudys/getplanofstudy?id={planOfStudy}"); if (PlanOfStudy == null) { throw new Exception("План обучения не найден"); } - APIClient.PostRequest("api/student/updatestudent", new StudentBindingModel - { - Id = id, - Name = name, - PlanOfStudyId = planOfStudy, - PlanOfStudyProfile = PlanOfStudy.Profile, + APIClient.PostRequest("api/student/updatestudent", new StudentBindingModel + { + Id = id, + Name = name, + PlanOfStudyId = planOfStudy, + PlanOfStudyProfile = PlanOfStudy.Profile, PhoneNumber = phoneNumber, }); return Redirect("/Home/Students"); - } - [HttpPost] + } + [HttpPost] public void DeleteStudent(int id) { - if (APIClient.User == null) - { - throw new Exception("Вход только авторизованным"); - } + if (APIClient.User == null) + { + throw new Exception("Вход только авторизованным"); + } if (id == 0) { throw new Exception("id не может быть 0"); } - APIClient.PostRequest("api/student/deletestudent", new StudentBindingModel - { + APIClient.PostRequest("api/student/deletestudent", new StudentBindingModel + { Id = id }); Response.Redirect("Students"); - } - [HttpGet] - public IActionResult Enter() - { - return View(); - } - [HttpGet] - public IActionResult Register() - { - return View(); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - [HttpPost] - public void Enter(string login, string password) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) - { - throw new Exception("Введите логин и пароль"); - } - APIClient.User = APIClient.GetRequest($"api/user/loginworker?login={login}&password={password}"); - if (APIClient.User == null) - { - throw new Exception("Неверный логин/пароль"); - } - Response.Redirect("Index"); - } - [HttpPost] - public void Register(string login, string password, string email) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) - { - throw new Exception("Введите логин, пароль и почту"); - } - APIClient.PostRequest("api/user/registerworker", new UserBindingModel - { - Email = email, - Login = login, - Password = password - }); - Response.Redirect("Enter"); - return; - } - [HttpGet] - public IActionResult GetWordFile() - { - return PhysicalFile($"C:\\Users\\{Environment.UserName}\\Downloads\\Планы обучений по дисциплинам.docx", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "Планы обучений по дисциплинам.docx"); - } - public IActionResult GetExcelFile() - { - return PhysicalFile($"C:\\Users\\{Environment.UserName}\\Downloads\\Планы обучений по дисциплинам.xlsx", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "Планы обучений по дисциплинам.xlsx"); - } - [HttpGet] - public IActionResult ReportPlanOfStudys() - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - return View("ReportPlanOfStudys", APIClient.GetRequest>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}")); - } - [HttpPost] - public IActionResult ReportPlanOfStudys(string type) - { - if (APIClient.User == null) - { - Redirect("~/Home/Enter"); - throw new Exception("Вход только авторизованным"); - } - - if (string.IsNullOrEmpty(type)) - { - throw new Exception("Неверный тип отчета"); - } - - if (type == "docx") - { - APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel - { - FileName = "C:\\ВременныеОтчёты\\Планы обучений по дисциплинам.docx" - }); - return GetWordFile(); - } - - if (type == "xlsx") - { - APIClient.PostRequest("api/planofstudys/loadreporttoexcel", new ReportBindingModel - { - FileName = "C:\\ВременныеОтчёты\\Планы обучений по дисциплинам.xlsx" - }); - return GetExcelFile(); - } - return Redirect("Index"); - } - [HttpGet] - public IActionResult ReportPlanOfStudyAndStudents() - { - if (APIClient.User == null) - { - return Redirect("~/Home/Enter"); - } - return View("ReportPlanOfStudyAndStudents", APIClient.GetRequest>($"api/planofstudys/getplanofstudyandstudents")); - } - [HttpPost] - public void ReportPlanOfStudyAndStudents(string type) - { - if (APIClient.User == null) - { - Redirect("~/Home/Enter"); - throw new Exception("Вход только авторизованным"); - } - if (type == "pdf") - { - APIClient.PostRequest("api/planofstudys/createreporttopdffile", new ReportBindingModel - { - FileName = "C:\\ВременныеОтчёты\\Сведения по планам обучения.pdf" - }); - APIClient.PostRequest("api/planofstudys/sendpdftomail", new MailSendInfoBindingModel - { - MailAddress = APIClient.User.Email, - Subject = "Отчет", - Text = "Сведения по планам обучения" - }); - } - Response.Redirect("Index"); - return; - } - } -} + } + [HttpGet] + public IActionResult Enter() + { + return View(); + } + [HttpGet] + public IActionResult Register() + { + return View(); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.User = APIClient.GetRequest($"api/user/loginworker?login={login}&password={password}"); + if (APIClient.User == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } + [HttpPost] + public void Register(string login, string password, string email) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email)) + { + throw new Exception("Введите логин, пароль и почту"); + } + APIClient.PostRequest("api/user/registerworker", new UserBindingModel + { + Email = email, + Login = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + [HttpGet] + public IActionResult GetWordFile() + { + return PhysicalFile($"C:\\ВременныеОтчёты\\Планы обучений по дисциплинам.docx", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "Планы обучений по дисциплинам.docx"); + } + public IActionResult GetExcelFile() + { + return PhysicalFile($"C:\\ВременныеОтчёты\\Планы обучений по дисциплинам.xlsx", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "Планы обучений по дисциплинам.xlsx"); + } + [HttpGet] + public IActionResult ReportPlanOfStudys() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View("ReportPlanOfStudys", APIClient.GetRequest>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}")); + } + [HttpPost] + public IActionResult ReportPlanOfStudys(string type) + { + if (APIClient.User == null) + { + Redirect("~/Home/Enter"); + throw new Exception("Вход только авторизованным"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + if (type == "docx") + { + APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel + { + FileName = "C:\\ВременныеОтчёты\\Планы обучений по дисциплинам.docx" + }); + return GetWordFile(); + } + + if (type == "xlsx") + { + APIClient.PostRequest("api/planofstudys/loadreporttoexcel", new ReportBindingModel + { + FileName = "C:\\ВременныеОтчёты\\Планы обучений по дисциплинам.xlsx" + }); + return GetExcelFile(); + } + return Redirect("Index"); + } + [HttpGet] + public IActionResult ReportPlanOfStudyAndStudents() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View("ReportPlanOfStudyAndStudents", APIClient.GetRequest>($"api/planofstudys/getplanofstudyandstudents")); + } + [HttpPost] + public void ReportPlanOfStudyAndStudents(string type) + { + if (APIClient.User == null) + { + Redirect("~/Home/Enter"); + throw new Exception("Вход только авторизованным"); + } + if (type == "pdf") + { + APIClient.PostRequest("api/planofstudys/createreporttopdffile", new ReportBindingModel + { + FileName = "C:\\ВременныеОтчёты\\Сведения по планам обучения.pdf" + }); + APIClient.PostRequest("api/planofstudys/sendpdftomail", new MailSendInfoBindingModel + { + MailAddress = APIClient.User.Email, + Subject = "Отчет", + Text = "Сведения по планам обучения" + }); + } + Response.Redirect("Index"); + return; + } + } +} diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 07213d0..3eebb86 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (localdb) название РїРє, РІРѕС‚ РїРє Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); }