контроллер учителя
This commit is contained in:
parent
c96decd748
commit
6caf3790a0
@ -1,6 +1,10 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using SchoolAgainStudyContracts.BindingModel;
|
||||
using SchoolAgainStudyContracts.BusinessLogicContracts;
|
||||
using SchoolAgainStudyContracts.SearchModel;
|
||||
using SchoolAgainStudyDataBaseImplements.Models;
|
||||
using SchoolAgainStudyDataModels.Models;
|
||||
using System.Diagnostics;
|
||||
using TeacherWebClient.Models;
|
||||
|
||||
@ -48,5 +52,362 @@ namespace TeacherWebClient.Controllers
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
[HttpPost]
|
||||
|
||||
public void Privacy(string name, string post, string email, string login, string password)
|
||||
{
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(post))
|
||||
{
|
||||
throw new Exception("Введите данные");
|
||||
}
|
||||
_teacher.Update(new TeacherBindingModel
|
||||
{
|
||||
Id = APIClient.Teacher.Id,
|
||||
Name = name,
|
||||
Email = login,
|
||||
Password = password,
|
||||
Login = login,
|
||||
Post = post
|
||||
});
|
||||
|
||||
APIClient.Teacher.Name = name;
|
||||
APIClient.Teacher.Email = email;
|
||||
APIClient.Teacher.Password = password;
|
||||
APIClient.Teacher.Login = login;
|
||||
APIClient.Teacher.Post = post;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string login, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите логин и пароль");
|
||||
}
|
||||
APIClient.Teacher = _teacher.ReadElement(new TeacherSearchModel { Login = login, Password = password });
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(string name, string post, string email, string login, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(post))
|
||||
{
|
||||
throw new Exception("Введите ФИО, должность, почту, логин, пароль");
|
||||
}
|
||||
_teacher.Create(new TeacherBindingModel
|
||||
{
|
||||
Name = name,
|
||||
Email = login,
|
||||
Password = password,
|
||||
Login = login,
|
||||
Post = post
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Materials()
|
||||
{
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(_material.ReadList(new MaterialSearchModel { TeacherId = APIClient.Teacher.Id }));
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateMaterial()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateMaterial(string title, string sphereUse)
|
||||
{
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(sphereUse))
|
||||
{
|
||||
throw new Exception("Введите название и сферу использования");
|
||||
}
|
||||
_material.Create(new MaterialBindingModel
|
||||
{
|
||||
TeacherId = APIClient.Teacher.Id,
|
||||
Title = title,
|
||||
SphereUse = sphereUse
|
||||
});
|
||||
Response.Redirect("Materials");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult MaterialSetting(int id)
|
||||
{
|
||||
return View(_material.ReadElement(new MaterialSearchModel { Id = id }));
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateMaterial(int id, string name, string sph)
|
||||
{
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Нет названия");
|
||||
}
|
||||
if (string.IsNullOrEmpty(sph))
|
||||
{
|
||||
throw new Exception("Нет сферы применения");
|
||||
}
|
||||
|
||||
_material.Update(new MaterialBindingModel
|
||||
{
|
||||
Id = id,
|
||||
Title = name,
|
||||
SphereUse = sph,
|
||||
TeacherId = APIClient.Teacher.Id,
|
||||
|
||||
});
|
||||
Response.Redirect("/Home/Materials");
|
||||
}
|
||||
|
||||
public void DeleteMaterial(int id)
|
||||
{
|
||||
|
||||
_material.Delete(new MaterialBindingModel
|
||||
{
|
||||
Id = id,
|
||||
});
|
||||
Response.Redirect("/Home/Materials");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Lessons()
|
||||
{
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(_lesson.ReadList(new LessonSearchModel { TeacherId = APIClient.Teacher.Id }));
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateLesson()
|
||||
{
|
||||
ViewBag.Products = _product.ReadList(null);
|
||||
var list = _material.ReadList(new MaterialSearchModel { TeacherId = APIClient.Teacher.Id });
|
||||
var simpMaterial = list.Select(x => new { MaterialId = x.Id, MaterialName = x.Title });
|
||||
ViewBag.Interests = new MultiSelectList(simpMaterial, "MaterialId", "MaterialName");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateLesson(string title, string dateEvent, int product, int[] materials)
|
||||
{
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(dateEvent) && product <= 0 || materials.Length == 0)
|
||||
{
|
||||
throw new Exception("Введите название и дату");
|
||||
}
|
||||
Dictionary<int, IMaterial> lessonMaterials = new Dictionary<int, IMaterial>();
|
||||
foreach (int id in materials)
|
||||
{
|
||||
lessonMaterials.Add(id, _material.ReadElement(new MaterialSearchModel { Id = id }));
|
||||
}
|
||||
_lesson.Create(new LessonBindingModel
|
||||
{
|
||||
TeacherId = APIClient.Teacher.Id,
|
||||
TeacherName = APIClient.Teacher.Name,
|
||||
Title = title,
|
||||
DateEvent = DateTime.SpecifyKind(DateTime.Parse(dateEvent), DateTimeKind.Utc),
|
||||
ProductId = product,
|
||||
ProductName = _product.ReadElement(new ProductSearchModel { Id = product }).Title,
|
||||
LessonMaterials = lessonMaterials
|
||||
|
||||
});
|
||||
Response.Redirect("Lessons");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult LessonSetting(int id)
|
||||
{
|
||||
var lesson = _lesson.ReadElement(new LessonSearchModel { Id = id });
|
||||
var materials = _material.ReadList(new MaterialSearchModel { TeacherId = APIClient.Teacher.Id }).Select(x => new { MaterialId = x.Id, MaterialName = x.Title }).ToList();
|
||||
var selectedMaterials = lesson.LessonMaterials.Select(x => x.Key).ToArray();
|
||||
ViewBag.Materials = new MultiSelectList(materials, "MaterialId", "MaterialName", selectedMaterials);
|
||||
ViewBag.Products = _product.ReadList(null);
|
||||
return View(lesson);
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateDiy(int idLesson, string title, string dateEvent, int product, int[] materials)
|
||||
{
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
throw new Exception("Нет названия");
|
||||
}
|
||||
if (string.IsNullOrEmpty(dateEvent))
|
||||
{
|
||||
throw new Exception("Нет даты");
|
||||
}
|
||||
if (product <= 0)
|
||||
{
|
||||
throw new Exception("Нет изделия");
|
||||
}
|
||||
if (materials.Length == 0)
|
||||
{
|
||||
throw new Exception("Нет материалов");
|
||||
}
|
||||
|
||||
Dictionary<int, IMaterial> lessonMaterials = new Dictionary<int, IMaterial>();
|
||||
foreach (int id in materials)
|
||||
{
|
||||
lessonMaterials.Add(id, _material.ReadElement(new MaterialSearchModel { Id = id }));
|
||||
}
|
||||
_lesson.Update(new LessonBindingModel
|
||||
{
|
||||
Id = idLesson,
|
||||
TeacherId = APIClient.Teacher.Id,
|
||||
TeacherName = APIClient.Teacher.Name,
|
||||
Title = title,
|
||||
DateEvent = DateTime.SpecifyKind(DateTime.Parse(dateEvent), DateTimeKind.Utc),
|
||||
ProductId = product,
|
||||
ProductName = _task.ReadElement(new TaskSearchModel { Id = product }).Title,
|
||||
LessonMaterials = lessonMaterials
|
||||
|
||||
});
|
||||
Response.Redirect("/Home/Lessons");
|
||||
}
|
||||
|
||||
public void DeleteLesson(int id)
|
||||
{
|
||||
|
||||
_lesson.Delete(new LessonBindingModel
|
||||
{
|
||||
Id = id,
|
||||
});
|
||||
Response.Redirect("/Home/Lessons");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult Tasks()
|
||||
{
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(_task.ReadList(new TaskSearchModel { TeacherId = APIClient.Teacher.Id }));
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateTask()
|
||||
{
|
||||
var list = _material.ReadList(new MaterialSearchModel { TeacherId = APIClient.Teacher.Id });
|
||||
var simpMaterial = list.Select(x => new { MaterialId = x.Id, MaterialName = x.Title });
|
||||
ViewBag.Interests = new MultiSelectList(simpMaterial, "MaterialId", "MaterialName");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateTask(string title, string dateIssue, string dateDelivery, int[] materials)
|
||||
{
|
||||
if (APIClient.Teacher == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(dateIssue) || string.IsNullOrEmpty(dateDelivery) || materials.Length == 0)
|
||||
{
|
||||
throw new Exception("Введите название и даты");
|
||||
}
|
||||
Dictionary<int, IMaterial> taskMaterials = new Dictionary<int, IMaterial>();
|
||||
foreach (int id in materials)
|
||||
{
|
||||
taskMaterials.Add(id, _material.ReadElement(new MaterialSearchModel { Id = id }));
|
||||
}
|
||||
_task.Create(new TaskBindingModel
|
||||
{
|
||||
TeacherId = APIClient.Teacher.Id,
|
||||
TeacherName = APIClient.Teacher.Name,
|
||||
Title = title,
|
||||
DateIssue = DateTime.SpecifyKind(DateTime.Parse(dateIssue), DateTimeKind.Utc),
|
||||
DateDelivery = DateTime.SpecifyKind(DateTime.Parse(dateDelivery), DateTimeKind.Utc),
|
||||
TaskMaterials = taskMaterials
|
||||
|
||||
});
|
||||
Response.Redirect("Tasks");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult TaskSetting(int id)
|
||||
{
|
||||
var task = _task.ReadElement(new TaskSearchModel { Id = id });
|
||||
var materials = _material.ReadList(new MaterialSearchModel { TeacherId = APIClient.Teacher.Id }).Select(x => new { MaterialId = x.Id, MaterialName = x.Title }).ToList();
|
||||
var selectedMaterials = task.TaskMaterials.Select(x => x.Key).ToArray();
|
||||
ViewBag.Materials = new MultiSelectList(materials, "MaterialId", "MaterialName", selectedMaterials);
|
||||
return View(task);
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateTask(int idTask, string title, string dateIssue, string dateDelivery, int[] materials)
|
||||
{
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
throw new Exception("Нет названия");
|
||||
}
|
||||
if (string.IsNullOrEmpty(dateIssue))
|
||||
{
|
||||
throw new Exception("Нет даты выдачи");
|
||||
}
|
||||
if (string.IsNullOrEmpty(dateDelivery))
|
||||
{
|
||||
throw new Exception("Нет срока сдачи");
|
||||
}
|
||||
if (materials.Length == 0)
|
||||
{
|
||||
throw new Exception("Нет материалов");
|
||||
}
|
||||
|
||||
Dictionary<int, IMaterial> taskMaterials = new Dictionary<int, IMaterial>();
|
||||
foreach (int id in materials)
|
||||
{
|
||||
taskMaterials.Add(id, _material.ReadElement(new MaterialSearchModel { Id = id }));
|
||||
}
|
||||
_task.Update(new TaskBindingModel
|
||||
{
|
||||
Id = idTask,
|
||||
TeacherId = APIClient.Teacher.Id,
|
||||
TeacherName = APIClient.Teacher.Name,
|
||||
Title = title,
|
||||
DateIssue = DateTime.SpecifyKind(DateTime.Parse(dateIssue), DateTimeKind.Utc),
|
||||
DateDelivery = DateTime.SpecifyKind(DateTime.Parse(dateDelivery), DateTimeKind.Utc),
|
||||
TaskMaterials = taskMaterials
|
||||
|
||||
});
|
||||
Response.Redirect("/Home/Tasks");
|
||||
}
|
||||
|
||||
public void DeleteTask(int id)
|
||||
{
|
||||
|
||||
_task.Delete(new TaskBindingModel
|
||||
{
|
||||
Id = id,
|
||||
});
|
||||
Response.Redirect("/Home/Tasks");
|
||||
}
|
||||
}
|
||||
}
|
16
SchoolAgainStudy/TeacherWebClient/log4net.config
Normal file
16
SchoolAgainStudy/TeacherWebClient/log4net.config
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<log4net>
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="c:/temp/StudentWebClient.log" />
|
||||
<appendToFile value="true" />
|
||||
<maximumFileSize value="100KB" />
|
||||
<maxSizeRollBackups value="2" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="TRACE" />
|
||||
<appender-ref ref="RollingFile" />
|
||||
</root>
|
||||
</log4net>
|
Loading…
Reference in New Issue
Block a user