diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/ClientLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/ClientLogic.cs index 65e29a6..366d9aa 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogic/ClientLogic.cs @@ -55,7 +55,7 @@ namespace ServiceStationBusinessLogic.BusinessLogic { if (model == null) { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation($"ReadElement.Id:{model.Id}.login:{model.Login}"); + _logger.LogInformation($"ReadElement.Id:{model.Id}.login:{model.fio}"); var element = _storage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement.Element not fount"); @@ -83,22 +83,11 @@ namespace ServiceStationBusinessLogic.BusinessLogic { if (!withParams) { return; } - if (string.IsNullOrEmpty(model.FIO)) { throw new ArgumentNullException("Нет ФИО клиента", nameof(model.FIO)); } - if (string.IsNullOrEmpty(model.Password)) { - throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); - } - if (string.IsNullOrEmpty(model.Login)) { - throw new ArgumentNullException("Нет номера телефона пользователя", nameof(model.Login)); - } - _logger.LogInformation($"Client.Id:{model.Id}.FIO:{model.FIO}.Password:{model.Password}.Login:{model.Login}"); - - var element = _storage.GetElement(new ClientSearchModel { Login = model.Login}); - if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Такой логин пользователя уже есть"); - } + + _logger.LogInformation($"Client.Id:{model.Id}.FIO:{model.FIO}.TotalPoints:{model.TotalPoints}"); } } } diff --git a/ServiceStation/ServiceStationContracts/BindingModels/ClientBindingModel.cs b/ServiceStation/ServiceStationContracts/BindingModels/ClientBindingModel.cs index 5c0290e..d10fdd8 100644 --- a/ServiceStation/ServiceStationContracts/BindingModels/ClientBindingModel.cs +++ b/ServiceStation/ServiceStationContracts/BindingModels/ClientBindingModel.cs @@ -6,7 +6,6 @@ namespace ServiceStationContracts.BindingModels public int Id { get; set; } public string FIO { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public string Login { get; set; } = string.Empty; + public int TotalPoints { get; set; } } } diff --git a/ServiceStation/ServiceStationContracts/BindingModels/TaskBindingModel.cs b/ServiceStation/ServiceStationContracts/BindingModels/TaskBindingModel.cs index 305160d..4c4f949 100644 --- a/ServiceStation/ServiceStationContracts/BindingModels/TaskBindingModel.cs +++ b/ServiceStation/ServiceStationContracts/BindingModels/TaskBindingModel.cs @@ -10,5 +10,6 @@ namespace ServiceStationContracts.BindingModels { public int Id { get; set; } public string Name { get; set; } = string.Empty; - } + public double Price { get; set; } + } } diff --git a/ServiceStation/ServiceStationContracts/BindingModels/WorkFromWebBindingModel.cs b/ServiceStation/ServiceStationContracts/BindingModels/WorkFromWebBindingModel.cs index 62a6194..95607a0 100644 --- a/ServiceStation/ServiceStationContracts/BindingModels/WorkFromWebBindingModel.cs +++ b/ServiceStation/ServiceStationContracts/BindingModels/WorkFromWebBindingModel.cs @@ -18,6 +18,6 @@ namespace ServiceStationContracts.BindingModels { public int TaskId { get; set; } - public string client_ids { get; set; } = string.Empty; + public int[] client_ids { get; set; } = new int[0]; } } diff --git a/ServiceStation/ServiceStationContracts/SearchModels/ClientSearchModel.cs b/ServiceStation/ServiceStationContracts/SearchModels/ClientSearchModel.cs index 9aaa924..6c2307a 100644 --- a/ServiceStation/ServiceStationContracts/SearchModels/ClientSearchModel.cs +++ b/ServiceStation/ServiceStationContracts/SearchModels/ClientSearchModel.cs @@ -3,6 +3,6 @@ public class ClientSearchModel { public int? Id { get; set; } - public string? Login { get; set; } + public string? fio { get; set; } } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/ClientViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/ClientViewModel.cs index 78a4c5d..c5937b0 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/ClientViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/ClientViewModel.cs @@ -10,10 +10,7 @@ namespace ServiceStationContracts.ViewModels [DisplayName("ФИО")] public string FIO { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - - [DisplayName("Логин пользователя")] - public string Login { get; set; } = string.Empty; + [DisplayName("Всего баллов")] + public int TotalPoints { get; set; } } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/TaskViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/TaskViewModel.cs index 1b65688..8da581d 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/TaskViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/TaskViewModel.cs @@ -9,5 +9,8 @@ namespace ServiceStationContracts.ViewModels [DisplayName("Наименование задачи")] public string Name { get; set; } = string.Empty; - } + + [DisplayName("Стоимость задачи")] + public double Price { get; set; } + } } \ No newline at end of file diff --git a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs index 431c041..26d7106 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs @@ -18,6 +18,9 @@ namespace ServiceStationContracts.ViewModels public int TaskId { get; set; } + [DisplayName("Задача")] + public string TaskName { get; set; } = string.Empty; + public Dictionary ClientList { get; set; } = new(); } } diff --git a/ServiceStation/ServiceStationDataModels/Models/IClientModel.cs b/ServiceStation/ServiceStationDataModels/Models/IClientModel.cs index e658dfd..c933265 100644 --- a/ServiceStation/ServiceStationDataModels/Models/IClientModel.cs +++ b/ServiceStation/ServiceStationDataModels/Models/IClientModel.cs @@ -5,7 +5,6 @@ namespace ServiceStationDataModels.Models public interface IClientModel : IId { string FIO { get; } - string Password { get; } - string Login { get; } + int TotalPoints { get; } } } diff --git a/ServiceStation/ServiceStationDataModels/Models/ITaskModel.cs b/ServiceStation/ServiceStationDataModels/Models/ITaskModel.cs index e786237..0ba0555 100644 --- a/ServiceStation/ServiceStationDataModels/Models/ITaskModel.cs +++ b/ServiceStation/ServiceStationDataModels/Models/ITaskModel.cs @@ -10,5 +10,6 @@ namespace ServiceStationDataModels.Models public interface ITaskModel : IId { string Name { get; } + double Price { get; } } } diff --git a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs index dc6d20d..7837748 100644 --- a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs +++ b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs @@ -19,7 +19,9 @@ namespace ServiceSourceClientApp.Controllers { if (APIClient.executor == null) { return Redirect("~/Home/Enter"); } - return View(); + + var view = APIClient.GetRequest>($"api/Main/GetWorks?_executorId={APIClient.executor.Id}"); + return View(view); } [HttpGet] @@ -92,5 +94,31 @@ namespace ServiceSourceClientApp.Controllers { public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + + [HttpGet] + public IActionResult CreateWork() { + ViewBag.Tasks = APIClient.GetRequest>($"api/Main/GetTasks?"); + return View(APIClient.GetRequest>($"api/Main/GetClients?")); + } + + [HttpPost] + public void CreateWork(int[] ids, int task) { + if (APIClient.executor == null) { + Response.Redirect("~/Home/Enter"); + return; + } + APIClient.PostRequest("api/Main/CreateWork", new WorkFromWebBindingModel { + Price = Calc(task, ids.Length), + ExecutorId = APIClient.executor.Id, + TaskId = task, + client_ids = ids + }); + } + + [HttpPost] + public double Calc(int task, int count) { + var task_info = APIClient.GetRequest($"api/Main/GetTask?_taskId={task}") ?? throw new Exception(" "); + return task_info.Price + 700 * count; + } } } diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml index 61cd814..77d8c7c 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/CreateWork.cshtml @@ -1,26 +1,145 @@ -@{ - ViewData["Title"] = "Create"; +@using ServiceStationContracts.ViewModels +@{ + ViewData["Title"] = "CreateWork"; } + +@model List + + +
-

Создание работы

+

Создать работу

+
-
Товар:
+
Задача:
- +
-
Сумма:
-
+
Стоимость:
+
+ +
-
-
Сумма:
-
-
-
-
-
-
-
\ No newline at end of file + + +
+

Выбрать клиентов в работу

+
+ +
+ @{ + if (Model == null) { +

Авторизируйтесь

+ return; + } +
+ +
+ + + + + + + + + + @foreach (var item in Model) { + + + + + + } + +
+ Номер клиента + + ФИО клиента + + Выбрать все +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.FIO) + + +
+ } +
+ \ No newline at end of file diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/Index.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/Index.cshtml index c0e8a03..43266bf 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/Index.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/Index.cshtml @@ -1,40 +1,65 @@ -@{ +@using ServiceStationContracts.ViewModels +@{ ViewData["Title"] = "Home Page"; } +@model List +

Список работ

-
@{ if (Model == null) { -

Авторизируйтесь

+

Авторизируйтесь

return; } -

- Список работ -

- - - - - - - - - - - -
- Номер - - Дата начала - - Цена - - Статус -
+ +

+ Создать работу +

+ + + + + + + + + + + + @foreach (var item in Model) { + + + + + + + + } + +
+ Номер + + Дата работы + + Стоимость работы + + Номер задания + + Задания +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Date) + + @Html.DisplayFor(modelItem => item.Price) + + @Html.DisplayFor(modelItem => item.TaskId) + + @Html.DisplayFor(modelItem => item.TaskName) +
} -
+ \ No newline at end of file diff --git a/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs b/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs index 4f03015..a07cea8 100644 --- a/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs +++ b/ServiceStation/ServiceStationRestAPI/Controllers/MainController.cs @@ -82,12 +82,10 @@ namespace ServiceStationRestAPI.Controllers { ClientList = new() }; - foreach (char id in model.client_ids) { - if (int.TryParse(id.ToString(), out int _id)) { - var client = _clientLogic.ReadElement(new ClientSearchModel { Id = _id }) ?? throw new Exception("Ошибка получения данных"); - record.ClientList.Add(client.Id, (client)); - } - } + foreach (int id in model.client_ids) { + var client = _clientLogic.ReadElement(new ClientSearchModel { Id = id }) ?? throw new Exception("Ошибка получения данных"); + record.ClientList.Add(client.Id, (client)); + } return record; } @@ -149,6 +147,17 @@ namespace ServiceStationRestAPI.Controllers { } } + [HttpPost] + public void CreateTask(TaskBindingModel model) { + try { + _taskLogic.Create(model); + } + catch (Exception ex) { + _logger.LogError(ex, $"Ошибка создания задачи"); + throw; + } + } + [HttpGet] public List? GetTasks() { try { @@ -160,6 +169,29 @@ namespace ServiceStationRestAPI.Controllers { } } + [HttpGet] + public TaskViewModel? GetTask (int _taskId) { + try { + return _taskLogic.ReadElement(new TaskSearchModel { Id = _taskId }); + } + catch(Exception ex) { + _logger.LogError(ex, "Ошибка получения задачи"); + throw; + } + } + + [HttpPost] + public void CreateClient(ClientBindingModel model) { + try { + _clientLogic.Create(model); + } + catch (Exception ex) { + _logger.LogError(ex, $"Ошибка добавление клиента"); + throw; + } + } + + [HttpGet] public List? GetClients() { try { diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Implements/ClientStorage.cs b/ServiceStation/ServiceStationsDataBaseImplement/Implements/ClientStorage.cs index 7633fd1..f1e58f9 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Implements/ClientStorage.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Implements/ClientStorage.cs @@ -56,7 +56,7 @@ namespace ServiceStationsDataBaseImplement.Implements else { return context.Clients .Include(x => x.WorkClients) - .FirstOrDefault(x => x.Login == model.Login) + .FirstOrDefault(x => x.FIO == model.fio) ?.GetViewModel; } } diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs b/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs index b86c91c..2044e7c 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Implements/WorkStorage.cs @@ -67,6 +67,7 @@ namespace ServiceStationsDataBaseImplement.Implements using var context = new Database(); if (model.Id.HasValue) { return context.Works + .Include(x => x._task) .Include(x => x.WorkClients) .ThenInclude(x => x._work) .FirstOrDefault(x => x.Id == model.Id) @@ -74,13 +75,15 @@ namespace ServiceStationsDataBaseImplement.Implements } else if (model.ExecutorId.HasValue) { return context.Works - .Include(x => x.WorkClients) + .Include(x => x._task) + .Include(x => x.WorkClients) .ThenInclude(x => x._work) .FirstOrDefault(x => x.ExecutorId == model.ExecutorId) ?.GetViewModel; } return context.Works - .Include(x => x.WorkClients) + .Include(x => x._task) + .Include(x => x.WorkClients) .ThenInclude(x => x._work) .FirstOrDefault(x => x.TaskId == model.TaskId) ?.GetViewModel; @@ -91,23 +94,27 @@ namespace ServiceStationsDataBaseImplement.Implements using var context = new Database(); if (model.DateFrom.HasValue && model.DateTo.HasValue) { return context.Works - .Include(x => x.WorkClients) - .ThenInclude(x => x._work) + .Include(x => x._task) + .Include(x => x.WorkClients) + .ThenInclude(x => x._client) .Where(x => x.Date >= model.DateFrom && x.Date <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); } else if (model.ExecutorId.HasValue) { return context.Works - .Include(x => x.WorkClients) - .ThenInclude(x => x._work) - .Where(x => x.ExecutorId == model.ExecutorId) + .Include(x => x._task) + .Include(x => x.WorkClients) + .ThenInclude(x => x._client) + .Where(x => x.ExecutorId == model.ExecutorId) + .ToList() .Select(x => x.GetViewModel) .ToList(); } return context.Works - .Include(x => x.WorkClients) - .ThenInclude(x => x._work) + .Include(x => x._task) + .Include(x => x.WorkClients) + .ThenInclude(x => x._client) .Where(x => x.TaskId == model.TaskId) .Select(x => x.GetViewModel) .ToList(); @@ -117,8 +124,9 @@ namespace ServiceStationsDataBaseImplement.Implements { using var context = new Database(); return context.Works - .Include(x => x.WorkClients) - .ThenInclude(x => x._work) + .Include(x => x._task) + .Include(x => x.WorkClients) + .ThenInclude(x => x._client) .Select(x => x.GetViewModel) .ToList(); } diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822072626_Migration02.Designer.cs b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822072626_Migration02.Designer.cs new file mode 100644 index 0000000..b81cf55 --- /dev/null +++ b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822072626_Migration02.Designer.cs @@ -0,0 +1,204 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ServiceStationsDataBaseImplement; + +#nullable disable + +namespace ServiceStationsDataBaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20240822072626_Migration02")] + partial class Migration02 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Executors"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.TaskByWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Tasks"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("TaskId") + .HasColumnType("int"); + + b.Property("_taskId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.HasIndex("_taskId"); + + b.ToTable("Works"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("PointCount") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("WorkId"); + + b.ToTable("WorksClients"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => + { + b.HasOne("ServiceStationsDataBaseImplement.Models.Executor", null) + .WithMany("Works") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationsDataBaseImplement.Models.TaskByWork", "_task") + .WithMany() + .HasForeignKey("_taskId"); + + b.Navigation("_task"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b => + { + b.HasOne("ServiceStationsDataBaseImplement.Models.Client", "_client") + .WithMany("WorkClients") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationsDataBaseImplement.Models.Work", "_work") + .WithMany("WorkClients") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("_client"); + + b.Navigation("_work"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b => + { + b.Navigation("WorkClients"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b => + { + b.Navigation("Works"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => + { + b.Navigation("WorkClients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822072626_Migration02.cs b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822072626_Migration02.cs new file mode 100644 index 0000000..d4cbb66 --- /dev/null +++ b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822072626_Migration02.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ServiceStationsDataBaseImplement.Migrations +{ + /// + public partial class Migration02 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "_taskId", + table: "Works", + type: "int", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Works__taskId", + table: "Works", + column: "_taskId"); + + migrationBuilder.AddForeignKey( + name: "FK_Works_Tasks__taskId", + table: "Works", + column: "_taskId", + principalTable: "Tasks", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Works_Tasks__taskId", + table: "Works"); + + migrationBuilder.DropIndex( + name: "IX_Works__taskId", + table: "Works"); + + migrationBuilder.DropColumn( + name: "_taskId", + table: "Works"); + } + } +} diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822081747_Migration03.Designer.cs b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822081747_Migration03.Designer.cs new file mode 100644 index 0000000..f80b52b --- /dev/null +++ b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822081747_Migration03.Designer.cs @@ -0,0 +1,202 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ServiceStationsDataBaseImplement; + +#nullable disable + +namespace ServiceStationsDataBaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20240822081747_Migration03")] + partial class Migration03 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TotalPoints") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Executors"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.TaskByWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Tasks"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("TaskId") + .HasColumnType("int"); + + b.Property("_taskId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.HasIndex("_taskId"); + + b.ToTable("Works"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("PointCount") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("WorkId"); + + b.ToTable("WorksClients"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => + { + b.HasOne("ServiceStationsDataBaseImplement.Models.Executor", null) + .WithMany("Works") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationsDataBaseImplement.Models.TaskByWork", "_task") + .WithMany() + .HasForeignKey("_taskId"); + + b.Navigation("_task"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b => + { + b.HasOne("ServiceStationsDataBaseImplement.Models.Client", "_client") + .WithMany("WorkClients") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationsDataBaseImplement.Models.Work", "_work") + .WithMany("WorkClients") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("_client"); + + b.Navigation("_work"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b => + { + b.Navigation("WorkClients"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b => + { + b.Navigation("Works"); + }); + + modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => + { + b.Navigation("WorkClients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822081747_Migration03.cs b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822081747_Migration03.cs new file mode 100644 index 0000000..1a09bae --- /dev/null +++ b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/20240822081747_Migration03.cs @@ -0,0 +1,62 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ServiceStationsDataBaseImplement.Migrations +{ + /// + public partial class Migration03 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Login", + table: "Clients"); + + migrationBuilder.DropColumn( + name: "Password", + table: "Clients"); + + migrationBuilder.AddColumn( + name: "Price", + table: "Tasks", + type: "float", + nullable: false, + defaultValue: 0.0); + + migrationBuilder.AddColumn( + name: "TotalPoints", + table: "Clients", + type: "int", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Price", + table: "Tasks"); + + migrationBuilder.DropColumn( + name: "TotalPoints", + table: "Clients"); + + migrationBuilder.AddColumn( + name: "Login", + table: "Clients", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Password", + table: "Clients", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Migrations/DatabaseModelSnapshot.cs b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/DatabaseModelSnapshot.cs index 7f914d0..35c86fd 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -34,17 +34,12 @@ namespace ServiceStationsDataBaseImplement.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("Login") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); + b.Property("TotalPoints") + .HasColumnType("int"); b.HasKey("Id"); - b.ToTable("Clients"); + b.ToTable("Clients", (string)null); }); modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b => @@ -69,7 +64,7 @@ namespace ServiceStationsDataBaseImplement.Migrations b.HasKey("Id"); - b.ToTable("Executors"); + b.ToTable("Executors", (string)null); }); modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.TaskByWork", b => @@ -84,9 +79,12 @@ namespace ServiceStationsDataBaseImplement.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("Price") + .HasColumnType("float"); + b.HasKey("Id"); - b.ToTable("Tasks"); + b.ToTable("Tasks", (string)null); }); modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => @@ -109,11 +107,16 @@ namespace ServiceStationsDataBaseImplement.Migrations b.Property("TaskId") .HasColumnType("int"); + b.Property("_taskId") + .HasColumnType("int"); + b.HasKey("Id"); b.HasIndex("ExecutorId"); - b.ToTable("Works"); + b.HasIndex("_taskId"); + + b.ToTable("Works", (string)null); }); modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b => @@ -139,7 +142,7 @@ namespace ServiceStationsDataBaseImplement.Migrations b.HasIndex("WorkId"); - b.ToTable("WorksClients"); + b.ToTable("WorksClients", (string)null); }); modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b => @@ -149,6 +152,12 @@ namespace ServiceStationsDataBaseImplement.Migrations .HasForeignKey("ExecutorId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.HasOne("ServiceStationsDataBaseImplement.Models.TaskByWork", "_task") + .WithMany() + .HasForeignKey("_taskId"); + + b.Navigation("_task"); }); modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b => diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Models/Client.cs b/ServiceStation/ServiceStationsDataBaseImplement/Models/Client.cs index 1ef1e09..5bd5047 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Models/Client.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Models/Client.cs @@ -18,11 +18,7 @@ namespace ServiceStationsDataBaseImplement.Models [Required] public string FIO { get; set; } = string.Empty; - [Required] - public string Password { get; set; } = string.Empty; - - [Required] - public string Login { get; set; } = string.Empty; + public int TotalPoints { get; set; } [ForeignKey("ClientId")] public virtual List WorkClients { get; set; } = new(); @@ -34,8 +30,7 @@ namespace ServiceStationsDataBaseImplement.Models return new Client() { Id = model.Id, FIO = model.FIO, - Password = model.Password, - Login = model.Login + TotalPoints = model.TotalPoints, }; } @@ -44,15 +39,13 @@ namespace ServiceStationsDataBaseImplement.Models return; } FIO = model.FIO; - Login = model.Login; - Password = model.Password; + TotalPoints = model.TotalPoints; } public ClientViewModel GetViewModel => new() { Id = Id, FIO = FIO, - Password = Password, - Login = Login + TotalPoints = TotalPoints }; } } diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Models/TaskByWork.cs b/ServiceStation/ServiceStationsDataBaseImplement/Models/TaskByWork.cs index 4bc1ebc..47d7da6 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Models/TaskByWork.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Models/TaskByWork.cs @@ -15,13 +15,17 @@ namespace ServiceStationsDataBaseImplement.Models { [Required] public string Name { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + public static TaskByWork? Create(TaskBindingModel? model) { if (model == null) { return null; } return new TaskByWork() { Id = model.Id, - Name = model.Name + Name = model.Name, + Price = model.Price, }; } @@ -34,7 +38,9 @@ namespace ServiceStationsDataBaseImplement.Models { public TaskViewModel GetViewModel => new() { Id = Id, - Name = Name + Name = Name, + Price = Price, }; + } } diff --git a/ServiceStation/ServiceStationsDataBaseImplement/Models/Work.cs b/ServiceStation/ServiceStationsDataBaseImplement/Models/Work.cs index d5140df..c353555 100644 --- a/ServiceStation/ServiceStationsDataBaseImplement/Models/Work.cs +++ b/ServiceStation/ServiceStationsDataBaseImplement/Models/Work.cs @@ -8,7 +8,6 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace ServiceStationsDataBaseImplement.Models { @@ -28,6 +27,7 @@ namespace ServiceStationsDataBaseImplement.Models [ForeignKey("TaskId")] public int TaskId { get; set; } + public virtual TaskByWork? _task { get; set; } [ForeignKey("WorkId")] public virtual List WorkClients { get; set; } = new(); @@ -39,7 +39,7 @@ namespace ServiceStationsDataBaseImplement.Models public Dictionary ClientList { get { if (_clientList == null) { - _clientList = WorkClients.ToDictionary(recWC => recWC.WorkId, recWC => recWC._client as IClientModel); + _clientList = WorkClients.ToDictionary(recWC => recWC.ClientId, recWC => recWC._client as IClientModel); } return _clientList; } @@ -56,7 +56,8 @@ namespace ServiceStationsDataBaseImplement.Models ExecutorId = model.ExecutorId, TaskId = model.TaskId, WorkClients = model.ClientList.Select(x => new WorkClient { - _work = context.Works.First(y => y.Id == x.Key) + _client = context.Clients.First(y => y.Id == x.Key), + PointCount = 0 }).ToList() }; } @@ -74,7 +75,8 @@ namespace ServiceStationsDataBaseImplement.Models Price = Price, ExecutorId = ExecutorId, TaskId = TaskId, - ClientList = ClientList + ClientList = ClientList, + TaskName = _task?.Name ?? string.Empty }; public void UpdateClients(Database context, WorkBindingModel model) {