Готовые аттестации

This commit is contained in:
DyCTaTOR 2024-05-28 00:44:23 +04:00
parent 0d7809310a
commit 96a5f2c708
9 changed files with 88 additions and 105 deletions

View File

@ -58,8 +58,6 @@ namespace UniversityBusinessLogic.BusinessLogics
{ {
CheckModel(model); CheckModel(model);
model.Score = AttestationScore.Неявка;
if (_attestationStorage.Insert(model) == null) if (_attestationStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
@ -89,51 +87,6 @@ namespace UniversityBusinessLogic.BusinessLogics
} }
return true; return true;
} }
public bool ScoreUpdate(AttestationBindingModel model, AttestationScore newScore)
{
CheckModel(model);
if (!Enum.IsDefined(typeof(AttestationScore), newScore))
{
_logger.LogWarning("Score update to " + newScore.ToString() + " operation failed. Attestation status incorrect.");
return false;
}
if (_attestationStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
model.Score = newScore;
return true;
}
public bool SetPass(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Зачёт);
}
public bool SetNotPass(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Незачёт);
}
public bool SetTwo(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Неудовлетворительно);
}
public bool SetThree(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Удовлетворительно);
}
public bool SetFour(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Хорошо);
}
public bool SetFive(AttestationBindingModel model)
{
return ScoreUpdate(model, AttestationScore.Отлично);
}
private void CheckModel(AttestationBindingModel model, bool withParams = true) private void CheckModel(AttestationBindingModel model, bool withParams = true)
{ {

View File

@ -110,8 +110,29 @@ namespace UniversityClientAppWorker.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.Students = APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}");
ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast<AttestationScore>(); ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast<AttestationScore>();
return View(); return View(APIClient.GetRequest<List<AttestationViewModel>>($"api/attestation/getattestations?userId={APIClient.User.Id}"));
}
[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("Ââåäèòå ôîðìó îöåíèâàíèÿ è âûáåðèòå ñòóäåíòà");
}
APIClient.PostRequest("api/attestation/createattestation", new AttestationBindingModel
{
UserId = APIClient.User.Id,
FormOfEvaluation = formOfEvaluation,
StudentId = student,
Score = score
});
Response.Redirect("Attestations");
} }
[HttpGet] [HttpGet]
public IActionResult Students() public IActionResult Students()

View File

@ -1,34 +1,40 @@
@{ @using UniversityContracts.ViewModels
ViewData["Title"] = "Manage Attestations"; @model List<AttestationViewModel>
@{
ViewData["Title"] = "Управление аттестациями";
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">@ViewData["Title"]</h2> <h2 class="display-4">@ViewData["Title"]</h2>
</div> </div>
<form method="post"> <form asp-action="CreateAttestation" method="post">
<div class="row"> <div class="row">
<div class="col-4">Form Of Evaluation:</div> <div class="col-4">Форма оценивания:</div>
<div class="col-8"> <div class="col-8">
<input type="text" name="formOfEvaluation" id="formOfEvaluation" class="form-control" /> <select name="formOfEvaluation" id="formOfEvaluation" class="form-control">
<option value="Зачёт">Зачёт</option>
<option value="Экзамен">Экзамен</option>
<option value="Дифферинцируемый зачёт">Дифферинцируемый зачёт</option>
</select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Student:</div> <div class="col-4">Студент:</div>
<div class="col-8"> <div class="col-8">
<select name="student" id="student" class="form-control" multiple asp-items="ViewBag.Students"></select> <select name="student" id="student" class="form-control" asp-items="@(new SelectList(ViewBag.Students, "Id", "Name"))"></select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Score:</div> <div class="col-4">Оценка:</div>
<div class="col-8"> <div class="col-8">
<select id="score" name="score" class="form-control" asp-items="@(new SelectList(ViewBag.AttestationScore, "Score"))"></select> <select id="score" name="score" class="form-control" asp-items="@(new SelectList(ViewBag.AttestationScore, "Score"))"></select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"> <div class="col-4 mt-2">
<input type="submit" value="Create Attestation" class="btn btn-primary" /> <input type="submit" value="Добавить аттестацию" class="btn btn-primary" />
</div> </div>
</div> </div>
</form> </form>
@ -36,31 +42,40 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Form Of Evaluation</th> <th>Id</th>
<th>Student</th> <th>Форма оценивания</th>
<th>Score</th> <th>Студент</th>
<th>Actions</th> <th>Оценка</th>
<th>Действия</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@* @foreach (var discipline in Model) @foreach (var attestation in Model)
{ {
<tr> <tr>
<td>@discipline.Name</td>
<td>@discipline.Description</td>
<td> <td>
@foreach (var student in discipline.Students) @Html.DisplayFor(modelItem => attestation.Id)
{
<span>@student.Name</span>
}
</td> </td>
<td> <td>
<a asp-action="Edit" asp-route-id="@discipline.Id" class="btn btn-warning">Edit</a> @Html.DisplayFor(modelItem => attestation.FormOfEvaluation)
<a asp-action="Details" asp-route-id="@discipline.Id" class="btn btn-info">Details</a> </td>
<a asp-action="Delete" asp-route-id="@discipline.Id" class="btn btn-danger">Delete</a> <td>
@Html.DisplayFor(modelItem => attestation.StudentName)
</td>
<td>
@Html.DisplayFor(modelItem => attestation.Score)
</td>
<td>
<div class="btn-group">
<a asp-controller="Home" asp-action="" asp-route-id="@attestation.Id" class="btn btn-warning">Изменить</a>
<form asp-controller="Home" asp-action="DeleteAttestation" method="post">
<input type="hidden" name="id" value="@attestation.Id" />
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</div>
</td> </td>
</tr> </tr>
} *@ }
</tbody> </tbody>
</table> </table>

View File

@ -15,5 +15,6 @@ namespace UniversityContracts.BindingModels
public string FormOfEvaluation { get; set; } = string.Empty; public string FormOfEvaluation { get; set; } = string.Empty;
public AttestationScore Score { get; set; } = AttestationScore.Неявка; public AttestationScore Score { get; set; } = AttestationScore.Неявка;
public int StudentId { get; set; } public int StudentId { get; set; }
public string StudentName { get; set; } = string.Empty;
} }
} }

View File

@ -15,12 +15,6 @@ namespace UniversityContracts.BusinessLogicsContracts
bool CreateAttestation(AttestationBindingModel model); bool CreateAttestation(AttestationBindingModel model);
bool DeleteAttestation(AttestationBindingModel model); bool DeleteAttestation(AttestationBindingModel model);
bool UpdateAttestation(AttestationBindingModel model); bool UpdateAttestation(AttestationBindingModel model);
bool SetPass(AttestationBindingModel model);
bool SetNotPass(AttestationBindingModel model);
bool SetTwo(AttestationBindingModel model);
bool SetThree(AttestationBindingModel model);
bool SetFour(AttestationBindingModel model);
bool SetFive(AttestationBindingModel model);
} }
} }

View File

@ -14,6 +14,8 @@ namespace UniversityContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public int StudentId { get; set; } public int StudentId { get; set; }
[DisplayName("ФИО студента")]
public string StudentName { get; set; } = string.Empty;
[DisplayName("Форма оценивания")] [DisplayName("Форма оценивания")]
public string FormOfEvaluation { get; set; } = string.Empty; public string FormOfEvaluation { get; set; } = string.Empty;
[DisplayName("Оценка")] [DisplayName("Оценка")]

View File

@ -23,25 +23,18 @@ namespace UniversityDatabaseImplement.Implements
public List<AttestationViewModel> GetFilteredList(AttestationSearchModel model) public List<AttestationViewModel> GetFilteredList(AttestationSearchModel model)
{ {
using var context = new UniversityDatabase(); if (model == null)
if (model.Id.HasValue)
{ {
return context.Attestations return new();
.Include(x => x.Student)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.StudentId.HasValue)
{
return context.Attestations
.Include(x => x.Student)
.Where(x => x.StudentId == model.StudentId)
.Select(x => x.GetViewModel)
.ToList();
} }
return new(); using var context = new UniversityDatabase();
return context.Attestations
.Include(x => x.Student)
.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
} }
public AttestationViewModel? GetElement(AttestationSearchModel model) public AttestationViewModel? GetElement(AttestationSearchModel model)

View File

@ -18,6 +18,7 @@ namespace UniversityDatabaseImplement.Models
public int UserId { get; private set; } public int UserId { get; private set; }
[Required] [Required]
public int StudentId { get; private set; } public int StudentId { get; private set; }
public string StudentName { get; private set; } = string.Empty;
[Required] [Required]
public string FormOfEvaluation { get; private set; } = string.Empty; public string FormOfEvaluation { get; private set; } = string.Empty;
[Required] [Required]
@ -37,6 +38,7 @@ namespace UniversityDatabaseImplement.Models
User = context.Users.First(x => x.Id == model.UserId), User = context.Users.First(x => x.Id == model.UserId),
StudentId = model.StudentId, StudentId = model.StudentId,
Student = context.Students.First(x => x.Id == model.StudentId), Student = context.Students.First(x => x.Id == model.StudentId),
StudentName = model.StudentName,
FormOfEvaluation = model.FormOfEvaluation, FormOfEvaluation = model.FormOfEvaluation,
Score = model.Score Score = model.Score
}; };
@ -48,6 +50,7 @@ namespace UniversityDatabaseImplement.Models
return; return;
} }
StudentId = model.StudentId; StudentId = model.StudentId;
StudentName = model.StudentName;
FormOfEvaluation = model.FormOfEvaluation; FormOfEvaluation = model.FormOfEvaluation;
Score = model.Score; Score = model.Score;
} }
@ -55,6 +58,7 @@ namespace UniversityDatabaseImplement.Models
{ {
Id = Id, Id = Id,
StudentId = StudentId, StudentId = StudentId,
StudentName = StudentName,
FormOfEvaluation = FormOfEvaluation, FormOfEvaluation = FormOfEvaluation,
Score = Score Score = Score
}; };

View File

@ -20,15 +20,15 @@ namespace UniversityRestApi.Controllers
} }
[HttpGet] [HttpGet]
public List<AttestationViewModel>? GetAttestations(int studentId) public List<AttestationViewModel>? GetAttestations(int userId)
{ {
try try
{ {
return _logic.ReadList(new AttestationSearchModel { StudentId = studentId }); return _logic.ReadList(new AttestationSearchModel { UserId = userId });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка получения аттестаций студента id={Id}", studentId); _logger.LogError(ex, "Ошибка получения аттестаций пользователя id={Id}", userId);
throw; throw;
} }
} }