CourseWork/University/UniversityClientAppWorker/Controllers/HomeController.cs

217 lines
7.2 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Mvc;
using PlumbingRepairClientApp;
using System.Diagnostics;
using UniversityClientAppWorker.Models;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Enums;
namespace UniversityClientAppWorker.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult Index()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<PlanOfStudyViewModel>>($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"));
}
[HttpPost]
public void CreatePlanOfStudy(string profile, string formOfStudy)
{
if (APIClient.User == null)
{
throw new Exception("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
if (string.IsNullOrEmpty(formOfStudy) || string.IsNullOrEmpty(profile))
{
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
APIClient.PostRequest("api/planofstudys/createplanofstudy", new PlanOfStudyBindingModel
{
Profile = profile,
FormOfStudy = formOfStudy,
UserId = APIClient.User.Id
});
Response.Redirect("Index");
}
[HttpPost]
public void DeletePlanOfStudy(int id)
{
if (id == 0)
{
throw new Exception("id <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> 0");
}
APIClient.PostRequest("api/planofstudys/deleteplanofstudy", new PlanOfStudyBindingModel
{
Id = id
});
Response.Redirect("Index");
}
[HttpPost]
public void UpdatePlanOfStudy(int id)
{
if (id == 0)
{
throw new Exception("id <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> 0");
}
APIClient.PostRequest("api/planofstudys/updateplanofstudy", new PlanOfStudyBindingModel
{
Id = id
});
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("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
{
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>");
}
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");
}
2024-05-28 00:44:23 +04:00
ViewBag.Students = APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}");
ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast<AttestationScore>();
return View(APIClient.GetRequest<List<AttestationViewModel>>($"api/attestation/getattestations?userId={APIClient.User.Id}"));
}
2024-05-28 00:44:23 +04:00
[HttpPost]
public void CreateAttestation(string formOfEvaluation, int student, AttestationScore score)
{
if (APIClient.User == null)
{
throw new Exception("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
if (string.IsNullOrEmpty(formOfEvaluation) || student == 0)
{
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
APIClient.PostRequest("api/attestation/createattestation", new AttestationBindingModel
{
UserId = APIClient.User.Id,
FormOfEvaluation = formOfEvaluation,
StudentId = student,
Score = score
});
Response.Redirect("Attestations");
}
[HttpGet]
public IActionResult Students()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
2024-05-27 22:35:38 +04:00
ViewBag.PlanOfStudys = APIClient.GetRequest<List<PlanOfStudyViewModel>>
($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}");
return View(APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}"));
}
2024-05-27 22:35:38 +04:00
[HttpPost]
public void CreateStudent(string name, int planOfStudy, string phoneNumber)
{
if (APIClient.User == null)
{
throw new Exception("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
if (string.IsNullOrEmpty(name) || planOfStudy == 0 || string.IsNullOrEmpty(phoneNumber))
{
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
APIClient.PostRequest("api/student/createstudent", new StudentBindingModel
{
UserId = APIClient.User.Id,
Name = name,
PlanOfStudyId = planOfStudy,
PhoneNumber = phoneNumber,
});
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
APIClient.User = APIClient.GetRequest<UserViewModel>($"api/user/loginworker?login={login}&password={password}");
if (APIClient.User == null)
{
throw new Exception("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD>");
}
APIClient.PostRequest("api/user/registerworker", new UserBindingModel
{
Email = email,
Login = login,
Password = password
});
Response.Redirect("Enter");
return;
}
}
}