add points
This commit is contained in:
parent
7745307e48
commit
85551918e3
@ -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<WorkClientModel>? 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("Нельзя ставить отрицательное количество баллов");
|
||||
}
|
||||
|
@ -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<WorkClientModel>? ReadList(WorkClientSearchModel model);
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<WorkClientModel> GetFilteredList(WorkClientSearchModel model);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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<int, IClientModel> ClientList { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -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<List<ClientViewModel>>($"api/Main/GetClients?") ?? throw new Exception("Îøèáêà ïîëó÷åíèÿ äàííûõ");
|
||||
return new JsonResult(clients);
|
||||
}
|
||||
|
||||
public JsonResult Work(int id) {
|
||||
var work_clients_list = APIClient.GetRequest<List<WorkClientModel>>($"api/Main/GetWorkClients?_clientId={id}")
|
||||
?? throw new Exception("Îøèáêà ïîëóåíèÿ äàííûõ");
|
||||
List<WorkViewModel> works = new();
|
||||
foreach (var record in work_clients_list) {
|
||||
int work_id = record.Work_Id;
|
||||
var work = APIClient.GetRequest<WorkViewModel>($"api/Main/GetWorkView?_workId={work_id}")
|
||||
?? throw new Exception("Îøèáêà ïîëó÷åíèÿ äàííûõ");
|
||||
works.Add(work);
|
||||
}
|
||||
return new JsonResult(works);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -82,7 +82,6 @@
|
||||
check();
|
||||
|
||||
function check() {
|
||||
debugger
|
||||
var task = $('#task').val();
|
||||
let checkboxes = document.getElementsByTagName('input');
|
||||
var count = 0;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -0,0 +1,68 @@
|
||||
@{
|
||||
ViewData["Title"] = "Scoring";
|
||||
}
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
|
||||
<div class="text-center">
|
||||
<h class="display-4">Выставление баллов клиентам за работу</h>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Клиент:</div>
|
||||
<div class="col-8">
|
||||
<select id="client" name="client" class="form-control">
|
||||
<option>--Select Client--</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Работа:</div>
|
||||
<div class="col-8">
|
||||
<select id="work" name="work" class="form-control">
|
||||
<option>--Select Work--</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Баллы:</div>
|
||||
<div class="col-8">
|
||||
<input id="points" type="text" name="points" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
GetClient();
|
||||
$('#client').change(function () {
|
||||
var id = $(this).val();
|
||||
$('#work').empty();
|
||||
$('#work').append('<Option>--Select Client--</Option>');
|
||||
$.ajax({
|
||||
url: '/Home/Work?id=' + id,
|
||||
success: function (result) {
|
||||
$.each(result, function (i, data) {
|
||||
$('#work').append('<Option value=' + data.id + '>' + 'work_id:' + data.id + '||' + data.taskName + '</Option>');
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function GetClient() {
|
||||
$.ajax({
|
||||
url: '/Home/Client',
|
||||
success: function (result) {
|
||||
$.each(result, function (i, data) {
|
||||
$('#client').append('<Option value=' + data.id + '>' + data.fio + '</Option>');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
@ -20,16 +20,22 @@
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Заказы</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Работы</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Scoring">Выставление баллов</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Report">Отчеты</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -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<WorkClientModel>? 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);
|
||||
}
|
||||
|
@ -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<WorkClientModel> GetFilteredList(WorkClientSearchModel model) {
|
||||
using var context = new Database();
|
||||
return context.WorksClients
|
||||
.Where(x => x.ClientId == model.client_id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user