diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/WorkClientLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/WorkClientLogic.cs index 5b39bca..778aa71 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/WorkClientLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/WorkClientLogic.cs @@ -1,5 +1,7 @@ using Microsoft.Extensions.Logging; using ServiceStationContracts.BusinessLogic; +using ServiceStationContracts.HelperModels; +using ServiceStationContracts.SearchModels; using ServiceStationContracts.StorageContracts; using System; using System.Collections.Generic; @@ -7,7 +9,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ServiceStationBusinessLogic.BusinessLogic { +namespace ServiceStationBusinessLogic.BusinessLogic +{ public class WorkClientLogic : IWorkClientLogic { private readonly ILogger _logger; @@ -22,7 +25,7 @@ namespace ServiceStationBusinessLogic.BusinessLogic { _clientStorage = clientStorage; } - public bool Add_Points(WorkClientBindingModel model) { + public bool Add_Points(WorkClientModel model) { CheckModel(model); if (!_storage.Add_Points(model)) { _logger.LogWarning("Add_Points operatin failed"); @@ -31,7 +34,18 @@ namespace ServiceStationBusinessLogic.BusinessLogic { return true; } - private void CheckModel(WorkClientBindingModel model) { + public List? ReadList(WorkClientSearchModel model) { + _logger.LogInformation($"ReadList.client_id:{model.client_id}"); + var list = _storage.GetFilteredList(model); + if (list == null) { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation($"ReadList.Count:{list.Count}"); + return list; + } + + private void CheckModel(WorkClientModel model) { if (model.Point_count < 0) { throw new ArgumentNullException("Нельзя ставить отрицательное количество баллов"); } diff --git a/ServiceStation/ServiceStationContracts/BusinessLogic/IWorkClientLogic.cs b/ServiceStation/ServiceStationContracts/BusinessLogic/IWorkClientLogic.cs index 2e7a18e..e6e9da8 100644 --- a/ServiceStation/ServiceStationContracts/BusinessLogic/IWorkClientLogic.cs +++ b/ServiceStation/ServiceStationContracts/BusinessLogic/IWorkClientLogic.cs @@ -1,12 +1,15 @@ -using ServiceStationContracts.StorageContracts; +using ServiceStationContracts.HelperModels; +using ServiceStationContracts.SearchModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ServiceStationContracts.BusinessLogic { +namespace ServiceStationContracts.BusinessLogic +{ public interface IWorkClientLogic { - bool Add_Points(WorkClientBindingModel model); + bool Add_Points(WorkClientModel model); + List? ReadList(WorkClientSearchModel model); } } diff --git a/ServiceStation/ServiceStationContracts/StorageContracts/WorkClientBindingModel.cs b/ServiceStation/ServiceStationContracts/HelperModels/WorkClientModel.cs similarity index 73% rename from ServiceStation/ServiceStationContracts/StorageContracts/WorkClientBindingModel.cs rename to ServiceStation/ServiceStationContracts/HelperModels/WorkClientModel.cs index 24276d2..364d633 100644 --- a/ServiceStation/ServiceStationContracts/StorageContracts/WorkClientBindingModel.cs +++ b/ServiceStation/ServiceStationContracts/HelperModels/WorkClientModel.cs @@ -4,8 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ServiceStationContracts.StorageContracts { - public class WorkClientBindingModel { +namespace ServiceStationContracts.HelperModels +{ + public class WorkClientModel + { public int Work_Id { get; set; } public int Client_Id { get; set; } public int Point_count { get; set; } diff --git a/ServiceStation/ServiceStationContracts/SearchModels/WorkClientSearchModel.cs b/ServiceStation/ServiceStationContracts/SearchModels/WorkClientSearchModel.cs new file mode 100644 index 0000000..dda6a11 --- /dev/null +++ b/ServiceStation/ServiceStationContracts/SearchModels/WorkClientSearchModel.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServiceStationContracts.SearchModels { + public class WorkClientSearchModel { + public int client_id { get; set; } + } +} diff --git a/ServiceStation/ServiceStationContracts/StorageContracts/IWorkClientStorage.cs b/ServiceStation/ServiceStationContracts/StorageContracts/IWorkClientStorage.cs index 8a254f3..d57d0cb 100644 --- a/ServiceStation/ServiceStationContracts/StorageContracts/IWorkClientStorage.cs +++ b/ServiceStation/ServiceStationContracts/StorageContracts/IWorkClientStorage.cs @@ -1,11 +1,16 @@ -using System; +using ServiceStationContracts.HelperModels; +using ServiceStationContracts.SearchModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ServiceStationContracts.StorageContracts { +namespace ServiceStationContracts.StorageContracts +{ public interface IWorkClientStorage { - bool Add_Points(WorkClientBindingModel model); - } + bool Add_Points(WorkClientModel model); + List GetFilteredList(WorkClientSearchModel model); + + } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs index 8509fcc..10080e3 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs @@ -1,5 +1,6 @@ using ServiceStationDataModels.Models; using System.ComponentModel; +using System.Text.Json.Serialization; namespace ServiceStationContracts.ViewModels @@ -21,6 +22,7 @@ namespace ServiceStationContracts.ViewModels [DisplayName("Задача")] public string TaskName { get; set; } = string.Empty; + [JsonIgnore] public Dictionary ClientList { get; set; } = new(); } } diff --git a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs index bbe1316..f6744d8 100644 --- a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs +++ b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using ServiceSourceClientApp.Models; using ServiceSourceExecutorApp; using ServiceStationContracts.BindingModels; +using ServiceStationContracts.HelperModels; using ServiceStationContracts.ViewModels; using System.Diagnostics; @@ -58,7 +59,6 @@ namespace ServiceSourceClientApp.Controllers { FIO = fio }); Response.Redirect("Enter"); - return; } [HttpGet] @@ -193,5 +193,41 @@ namespace ServiceSourceClientApp.Controllers { }); return RedirectToAction("Index"); } + + [HttpGet] + public IActionResult Scoring () { + if (APIClient.executor == null) { + return Redirect("~/Home/Enter"); + } + return View(); + } + + [HttpPost] + public void Scoring(int client, int work, int points) { + APIClient.PostRequest("api/Main/AddClientPoints", new WorkClientModel { + Client_Id = client, + Work_Id = work, + Point_count = points + }); + Response.Redirect("Scoring"); + } + + public JsonResult Client() { + var clients = APIClient.GetRequest>($"api/Main/GetClients?") ?? throw new Exception(" "); + return new JsonResult(clients); + } + + public JsonResult Work(int id) { + var work_clients_list = APIClient.GetRequest>($"api/Main/GetWorkClients?_clientId={id}") + ?? throw new Exception(" "); + List works = new(); + foreach (var record in work_clients_list) { + int work_id = record.Work_Id; + var work = APIClient.GetRequest($"api/Main/GetWorkView?_workId={work_id}") + ?? throw new Exception(" "); + works.Add(work); + } + return new JsonResult(works); + } } -} +} \ No newline at end of file diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml index 45ba4c4..2519d74 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml @@ -82,7 +82,6 @@ check(); function check() { - debugger var task = $('#task').val(); let checkboxes = document.getElementsByTagName('input'); var count = 0; diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/EditWork.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/EditWork.cshtml index cf73877..6262126 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/EditWork.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/EditWork.cshtml @@ -129,7 +129,6 @@ check(); function check() { - debugger var task = $('#task').val(); let checkboxes = document.getElementsByTagName('input'); var count = 0; @@ -156,7 +155,6 @@ } function checked_all() { - debugger let checkboxes = document.querySelectorAll('.form-check-input.old'); let val = null; @@ -177,7 +175,6 @@ }); $('#Select_all_new').on('click', function () { - debugger let checkboxes = document.querySelectorAll('.form-check-input.new'); let val = null; diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/Scoring.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/Scoring.cshtml new file mode 100644 index 0000000..49abdaa --- /dev/null +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/Scoring.cshtml @@ -0,0 +1,68 @@ +@{ + ViewData["Title"] = "Scoring"; +} + + + +
+ Выставление баллов клиентам за работу +
+ +
+
+
Клиент:
+
+ +
+
+
+
Работа:
+
+ +
+
+
+
Баллы:
+
+ +
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Shared/_Layout.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Shared/_Layout.cshtml index 4290970..e5bf5ab 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Shared/_Layout.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Shared/_Layout.cshtml @@ -20,16 +20,22 @@ diff --git a/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs b/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs index 6fb7227..af508b0 100644 --- a/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs +++ b/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs @@ -4,11 +4,12 @@ using ServiceStationBusinessLogic.MailKitWorker; using ServiceStationContracts.BindingModels; using ServiceStationContracts.BusinessLogic; using ServiceStationContracts.SearchModels; -using ServiceStationContracts.StorageContracts; using ServiceStationContracts.ViewModels; using Newtonsoft.Json; +using ServiceStationContracts.HelperModels; -namespace ServiceStationRestAPI.Controllers { +namespace ServiceStationRestAPI.Controllers +{ [Route("api/[controller]/[action]")] [ApiController] @@ -163,6 +164,18 @@ namespace ServiceStationRestAPI.Controllers { } } + [HttpGet] + public WorkViewModel GetWorkView(int _workId) { + try { + var work = _workLogic.ReadElement(new WorkSearchModel { Id = _workId }) ?? throw new Exception("Ошибка получения данных"); + return work; + } + catch (Exception ex) { + _logger.LogError(ex, $"Ошибка получения работы || work_id = {_workId}"); + throw; + } + } + [HttpPost] public void CreateTask(TaskBindingModel model) { try { @@ -219,8 +232,21 @@ namespace ServiceStationRestAPI.Controllers { } } + [HttpGet] + public List? GetWorkClients(int _clientId) { + try { + return _workClientLogic.ReadList(new WorkClientSearchModel { + client_id = _clientId + }); + } + catch (Exception ex) { + _logger.LogError(ex, "Ошибка получения данных"); + throw; + } + } + [HttpPost] - public void AddClientPoints(WorkClientBindingModel model) { + public void AddClientPoints(WorkClientModel model) { try { _workClientLogic.Add_Points(model); } diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkClientStorage.cs b/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkClientStorage.cs index 80a55dc..f5f7286 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkClientStorage.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkClientStorage.cs @@ -1,13 +1,16 @@ -using ServiceStationContracts.StorageContracts; +using ServiceStationContracts.HelperModels; +using ServiceStationContracts.SearchModels; +using ServiceStationContracts.StorageContracts; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ServiceStationsDataBaseImplement.Implements { +namespace ServiceStationsDataBaseImplement.Implements +{ public class WorkClientStorage : IWorkClientStorage { - public bool Add_Points(WorkClientBindingModel model) { + public bool Add_Points(WorkClientModel model) { using var context = new Database(); var rec = context.WorksClients.FirstOrDefault(x => x.WorkId == model.Work_Id && x.ClientId == model.Client_Id); if (rec == null) { @@ -17,5 +20,13 @@ namespace ServiceStationsDataBaseImplement.Implements { context.SaveChanges(); return ans; } - } -} + + public List GetFilteredList(WorkClientSearchModel model) { + using var context = new Database(); + return context.WorksClients + .Where(x => x.ClientId == model.client_id) + .Select(x => x.GetViewModel) + .ToList(); + } + } +} \ No newline at end of file diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs b/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs index 159822c..c2cc909 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs @@ -69,7 +69,8 @@ namespace ServiceStationsDataBaseImplement.Implements return context.Works .Include(x => x.WorkClients) .ThenInclude(x => x._client) - .FirstOrDefault(x => x.Id == model.Id) + .Include(x => x._task) + .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } else if (model.ExecutorId.HasValue) { diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Models/WorkClient.cs b/ServiceStation/ServiceStationsDataBaseImplement/Models/WorkClient.cs index 04fa5a7..2686f0e 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Models/WorkClient.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Models/WorkClient.cs @@ -1,4 +1,4 @@ -using ServiceStationContracts.StorageContracts; +using ServiceStationContracts.HelperModels; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -6,8 +6,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ServiceStationsDataBaseImplement.Models { - public class WorkClient { +namespace ServiceStationsDataBaseImplement.Models +{ + public class WorkClient { public int Id { get; set; } [Required] @@ -21,12 +22,18 @@ namespace ServiceStationsDataBaseImplement.Models { public virtual Work _work { get; set; } = new(); public virtual Client _client { get; set; } = new(); - public bool Update(WorkClientBindingModel? model) { + public bool Update(WorkClientModel? model) { if (model == null) { return false; } PointCount += model.Point_count; return true; } + + public WorkClientModel GetViewModel => new() { + Client_Id = ClientId, + Work_Id = WorkId, + Point_count = PointCount, + }; } }