Data base model&imp
This commit is contained in:
parent
6ee89f6397
commit
46ae5de04f
@ -2,15 +2,11 @@
|
||||
|
||||
namespace ServiceStationContracts.BindingModels
|
||||
{
|
||||
public class ClientBindingModel : IClientModel
|
||||
{
|
||||
public class ClientBindingModel : IClientModel {
|
||||
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public int Points { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
using ServiceStationDataModels.Models;
|
||||
|
||||
namespace ServiceStationContracts.BindingModels
|
||||
{
|
||||
public class ClientWorkBindingModel : IClientWorkModel
|
||||
{
|
||||
public int ClientId { get; set; }
|
||||
|
||||
public int WorkId { get; set; }
|
||||
}
|
||||
}
|
@ -2,12 +2,11 @@
|
||||
|
||||
namespace ServiceStationContracts.BindingModels
|
||||
{
|
||||
public class ExecutorBindingModel : IExecutorModel
|
||||
{
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
public class ExecutorBindingModel : IExecutorModel {
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string ExecutorFIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationContracts.BindingModels {
|
||||
public class TaskBindingModel : ITaskModel {
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,15 @@
|
||||
using ServiceStationDataModels.Enums;
|
||||
using ServiceStationDataModels.Models;
|
||||
using ServiceStationDataModels.Models;
|
||||
|
||||
namespace ServiceStationContracts.BindingModels
|
||||
{
|
||||
public class WorkBindingModel : IWorkModel
|
||||
{
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public class WorkBindingModel : IWorkModel {
|
||||
|
||||
public double Price { get; set; }
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public double Price { get; set; }
|
||||
public int ExecutorId { get; set; }
|
||||
public int TaskId { get; set; }
|
||||
|
||||
public WorkStatus Status { get; set; } = WorkStatus.Ожидает_выполнения;
|
||||
|
||||
public int ExecutorId { get; set; }
|
||||
|
||||
public int TaskId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
public Dictionary<int, IClientModel> ClientList { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ namespace ServiceStationContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IClientLogic
|
||||
{
|
||||
List<ClientViewModel>? ReadList(ClientSearchModel? model = null);
|
||||
List<ClientViewModel>? ReadList(ClientSearchModel model);
|
||||
ClientViewModel? ReadElement(ClientSearchModel model);
|
||||
|
||||
bool Create(ClientBindingModel model);
|
||||
bool Update(ClientBindingModel model);
|
||||
bool Delete(ClientBindingModel model);
|
||||
|
@ -1,15 +0,0 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
|
||||
|
||||
namespace ServiceStationContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IClintWorkLogic
|
||||
{
|
||||
List<ClientWorkViewModel>? ReadList(ClientWorkSearchModel? model);
|
||||
bool Create(ClientWorkBindingModel model);
|
||||
bool Update(ClientWorkBindingModel model);
|
||||
bool Delete(ClientWorkBindingModel model);
|
||||
}
|
||||
}
|
@ -6,8 +6,9 @@ namespace ServiceStationContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IExecutorLogic
|
||||
{
|
||||
List<ExecutorViewModel>? ReadList(ExecutorSearchModel? model = null);
|
||||
List<ExecutorViewModel>? ReadList(ExecutorSearchModel models);
|
||||
ExecutorViewModel? ReadElement(ExecutorSearchModel model);
|
||||
|
||||
bool Create(ExecutorBindingModel model);
|
||||
bool Update(ExecutorBindingModel model);
|
||||
bool Delete(ExecutorBindingModel model);
|
||||
|
@ -9,8 +9,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationContracts.BusinessLogicContracts {
|
||||
public interface ITaskLogic {
|
||||
List<TaskViewModel>? ReadList(TaskSearchModel? model = null);
|
||||
List<TaskViewModel>? ReadList(TaskSearchModel model);
|
||||
TaskViewModel? ReadElement(TaskSearchModel model);
|
||||
|
||||
bool Create(TaskBindingModel model);
|
||||
bool Update(TaskBindingModel model);
|
||||
bool Delete(TaskBindingModel model);
|
||||
|
@ -6,11 +6,11 @@ namespace ServiceStationContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IWorkLogic
|
||||
{
|
||||
List<WorkViewModel>? ReadList(WorkSearchModel? model = null);
|
||||
List<WorkViewModel>? ReadList(WorkSearchModel model);
|
||||
WorkViewModel? ReadElement(WorkSearchModel model);
|
||||
|
||||
bool Create(WorkBindingModel model);
|
||||
|
||||
bool TakeWorkInWork(WorkBindingModel model);
|
||||
bool FinishWork(WorkBindingModel model);
|
||||
bool IssuedWork(WorkBindingModel model);
|
||||
bool Update(WorkBindingModel model);
|
||||
bool Delete(WorkBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,6 @@
|
||||
public class ClientSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? FIO { get; set; }
|
||||
|
||||
public string? Login { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
namespace ServiceStationContracts.SearchModels
|
||||
{
|
||||
public class ClientWorkSearchModel
|
||||
{
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public int? WorkId { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
public class ExecutorSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
public class TaskSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
using ServiceStationDataModels.Enums;
|
||||
|
||||
|
||||
namespace ServiceStationContracts.SearchModels
|
||||
{
|
||||
public class WorkSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public DateTime? Date { get; set; }
|
||||
public WorkStatus Status { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? ExecutorId { get; set; }
|
||||
public int? TaskId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ namespace ServiceStationsContracts.StorageContracts
|
||||
public interface IClientStorage
|
||||
{
|
||||
List<ClientViewModel> GetFullList();
|
||||
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
|
||||
ClientViewModel? GetElement(ClientSearchModel model);
|
||||
|
||||
ClientViewModel? Insert(ClientBindingModel model);
|
||||
ClientViewModel? Update(ClientBindingModel model);
|
||||
ClientViewModel? Delete(ClientBindingModel model);
|
||||
|
@ -1,21 +0,0 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsContracts.StorageContracts
|
||||
{
|
||||
public interface IClientWorkStorage
|
||||
{
|
||||
List<ClientWorkViewModel> GetFullList();
|
||||
List<ClientWorkViewModel> GetFilteredList(ClientWorkSearchModel model);
|
||||
ClientWorkViewModel? GetElement(ClientWorkSearchModel model);
|
||||
ClientWorkViewModel? Insert(ClientWorkBindingModel model);
|
||||
ClientWorkViewModel? Update(ClientWorkBindingModel model);
|
||||
ClientWorkViewModel? Delete(ClientWorkBindingModel model);
|
||||
}
|
||||
}
|
@ -12,8 +12,8 @@ namespace ServiceStationsContracts.StorageContracts
|
||||
public interface IExecutorStorage
|
||||
{
|
||||
List<ExecutorViewModel> GetFullList();
|
||||
List<ExecutorViewModel> GetFilteredList(ExecutorSearchModel model);
|
||||
ExecutorViewModel? GetElement(ExecutorSearchModel model);
|
||||
|
||||
ExecutorViewModel? Insert(ExecutorBindingModel model);
|
||||
ExecutorViewModel? Update(ExecutorBindingModel model);
|
||||
ExecutorViewModel? Delete(ExecutorBindingModel model);
|
||||
|
@ -12,8 +12,8 @@ namespace ServiceStationsContracts.StorageContracts
|
||||
public interface ITaskStorage
|
||||
{
|
||||
List<TaskViewModel> GetFullList();
|
||||
List<TaskViewModel> GetFilteredList(TaskSearchModel model);
|
||||
TaskViewModel? GetElement(TaskSearchModel model);
|
||||
|
||||
TaskViewModel? Insert(TaskBindingModel model);
|
||||
TaskViewModel? Update(TaskBindingModel model);
|
||||
TaskViewModel? Delete(TaskBindingModel model);
|
||||
|
@ -13,6 +13,7 @@ namespace ServiceStationsContracts.StorageContracts
|
||||
{
|
||||
List<WorkViewModel> GetFullList();
|
||||
List<WorkViewModel> GetFilteredList(WorkSearchModel model);
|
||||
|
||||
WorkViewModel? GetElement(WorkSearchModel model);
|
||||
WorkViewModel? Insert(WorkBindingModel model);
|
||||
WorkViewModel? Update(WorkBindingModel model);
|
||||
|
@ -5,15 +5,15 @@ namespace ServiceStationContracts.ViewModels
|
||||
{
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
[DisplayName("ФИО")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("ФИО")]
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Бонусы")]
|
||||
public int Points { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
[DisplayName("Логин пользователя")]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
using ServiceStationDataModels.Models;
|
||||
|
||||
|
||||
namespace ServiceStationContracts.ViewModels
|
||||
{
|
||||
public class ClientWorkViewModel : IClientWorkModel
|
||||
{
|
||||
public int ClientId { get; set; }
|
||||
|
||||
public int WorkId { get; set; }
|
||||
}
|
||||
}
|
@ -5,11 +5,15 @@ namespace ServiceStationContracts.ViewModels
|
||||
{
|
||||
public class ExecutorViewModel : IExecutorModel
|
||||
{
|
||||
[DisplayName("Email")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Email")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
public string ExecutorFIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ namespace ServiceStationContracts.ViewModels
|
||||
{
|
||||
public class TaskViewModel : ITaskModel
|
||||
{
|
||||
[DisplayName("Имя задачи")]
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Наименование задачи")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using ServiceStationDataModels.Enums;
|
||||
using ServiceStationDataModels.Models;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
@ -7,18 +6,18 @@ namespace ServiceStationContracts.ViewModels
|
||||
{
|
||||
public class WorkViewModel : IWorkModel
|
||||
{
|
||||
[DisplayName("Дата")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
public WorkStatus Status { get; set; } = WorkStatus.Ожидает_выполнения;
|
||||
|
||||
public int ExecutorId { get; set; }
|
||||
|
||||
public int TaskId { get; set; }
|
||||
public int TaskId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
}
|
||||
public Dictionary<int, IClientModel> ClientList { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationDataModels.Enums
|
||||
{
|
||||
public enum WorkStatus
|
||||
{
|
||||
Ожидает_выполнения = -1,
|
||||
Выполняется = 1
|
||||
}
|
||||
}
|
@ -6,6 +6,6 @@ namespace ServiceStationDataModels.Models
|
||||
{
|
||||
string FIO { get; }
|
||||
string Password { get; }
|
||||
int Points { get; }
|
||||
string Login { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationDataModels.Models
|
||||
{
|
||||
public interface IClientWorkModel
|
||||
{
|
||||
int ClientId { get; }
|
||||
int WorkId { get; }
|
||||
}
|
||||
}
|
@ -11,5 +11,6 @@ namespace ServiceStationDataModels.Models
|
||||
{
|
||||
string Email { get; }
|
||||
string Password { get; }
|
||||
string ExecutorFIO { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using ServiceStationDataModels.Enums;
|
||||
using ServiceStationDataModels.HelperInterfaces;
|
||||
using ServiceStationDataModels.HelperInterfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -12,8 +11,10 @@ namespace ServiceStationDataModels.Models
|
||||
{
|
||||
DateTime Date { get; }
|
||||
double Price { get; }
|
||||
WorkStatus Status { get; }
|
||||
int ExecutorId { get; }
|
||||
int TaskId { get; }
|
||||
|
||||
// ClientId, ClientModel
|
||||
Dictionary<int, IClientModel> ClientList { get; }
|
||||
}
|
||||
}
|
||||
|
@ -8,22 +8,20 @@ namespace ServiceStationsDataBaseImplement
|
||||
{
|
||||
public class Database : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder
|
||||
optionsBuilder)
|
||||
//DESKTOP-E2VPEN3
|
||||
//WIN-4HUIDGH3G02
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ServiceStationDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<CategoryWork> CategoryWorks { set; get; }
|
||||
public virtual DbSet<ClientWork> ClientsWorks { set; get; }
|
||||
public virtual DbSet<WorkClient> WorksClients { set; get; }
|
||||
public virtual DbSet<Executor> Executors { set; get; }
|
||||
public virtual DbSet<Report> Reports { set; get; }
|
||||
public virtual DbSet<TaskByWork> Tasks { set; get; }
|
||||
public virtual DbSet<Work> Works { set; get; }
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationsContracts.StorageContracts;
|
||||
using ServiceStationsDataBaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Implements
|
||||
{
|
||||
public class CategoryWorkStorage : ICategoryWorkStorage
|
||||
{
|
||||
public CategoryWorkViewModel? Delete(CategoryWorkBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var element = context.CategoryWorks.FirstOrDefault(rec => rec.Id == model.ID);
|
||||
if (element != null)
|
||||
{
|
||||
context.CategoryWorks.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CategoryWorkViewModel? GetElement(CategoryWorkSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.CategoryWorks.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name ||
|
||||
(model.Id.HasValue && x.Id == model.Id)))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CategoryWorkViewModel> GetFilteredList(CategoryWorkSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.CategoryWorks.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<CategoryWorkViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.CategoryWorks.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CategoryWorkViewModel? Insert(CategoryWorkBindingModel model)
|
||||
{
|
||||
var newComponent = CategoryWork.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.CategoryWorks.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public CategoryWorkViewModel? Update(CategoryWorkBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var component = context.CategoryWorks.FirstOrDefault(x => x.Id == model.ID);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationsContracts.StorageContracts;
|
||||
@ -6,73 +8,62 @@ using ServiceStationsDataBaseImplement.Models;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
public class ClientStorage : IClientStorage {
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model) {
|
||||
var newRec = Client.Create(model);
|
||||
if (newRec == null) {
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.ID);
|
||||
if (element != null)
|
||||
{
|
||||
context.Clients.Remove(element);
|
||||
context.Clients.Add(newRec);
|
||||
context.SaveChanges();
|
||||
return newRec.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model) {
|
||||
using var context = new Database();
|
||||
var recUp = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (recUp == null) {
|
||||
return null;
|
||||
}
|
||||
recUp.Update(model);
|
||||
context.SaveChanges();
|
||||
return recUp.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model) {
|
||||
using var context = new Database();
|
||||
var recDel = context.Clients
|
||||
.Include(x => x.WorkClients)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (recDel != null) {
|
||||
context.Clients.Remove(recDel);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
return recDel.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public ClientViewModel? GetElement(ClientSearchModel model) {
|
||||
using var context = new Database();
|
||||
return context.Clients.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email ||
|
||||
(model.Id.HasValue && x.Id == model.Id)))?.GetViewModel;
|
||||
if (model.Id.HasValue) {
|
||||
return context.Clients
|
||||
.Include(x => x.WorkClients)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
else {
|
||||
return context.Clients
|
||||
.Include(x => x.WorkClients)
|
||||
.FirstOrDefault(x => x.Login == model.Login)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Clients.Where(x => x.Login.Contains(model.Email)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
public List<ClientViewModel> GetFullList() {
|
||||
using var context = new Database();
|
||||
return context.Clients.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
var newComponent = Client.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.Clients.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var component = context.Clients.FirstOrDefault(x => x.Id == model.ID);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +0,0 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationsContracts.StorageContracts;
|
||||
using ServiceStationsDataBaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Implements
|
||||
{
|
||||
public class ClientWorkStorage : IClientWorkStorage
|
||||
{
|
||||
public ClientWorkViewModel? Delete(ClientWorkBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var element = context.ClientsWorks.FirstOrDefault(rec => rec.ClientId == model.ClientId);
|
||||
if (element != null)
|
||||
{
|
||||
context.ClientsWorks.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientWorkViewModel? GetElement(ClientWorkSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.ClientsWorks.FirstOrDefault(x =>
|
||||
(model.ClientId.HasValue && x.ClientId == model.ClientId))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ClientWorkViewModel> GetFilteredList(ClientWorkSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.ClientsWorks.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ClientWorkViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.ClientsWorks.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ClientWorkViewModel? Insert(ClientWorkBindingModel model)
|
||||
{
|
||||
var newComponent = ClientWork.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.ClientsWorks.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientWorkViewModel? Update(ClientWorkBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var component = context.ClientsWorks.FirstOrDefault(x => x.ClientId == model.ClientId);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationDataModels;
|
||||
@ -14,39 +15,58 @@ namespace ServiceStationsDataBaseImplement.Implements
|
||||
{
|
||||
public class ExecutorStorage : IExecutorStorage
|
||||
{
|
||||
public ExecutorViewModel? Insert(ExecutorBindingModel model) {
|
||||
var newRec = Executor.Create(model);
|
||||
if (newRec == null) {
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.Executors.Add(newRec);
|
||||
context.SaveChanges();
|
||||
return newRec.GetViewModel;
|
||||
}
|
||||
|
||||
public ExecutorViewModel? Update(ExecutorBindingModel model) {
|
||||
using var context = new Database();
|
||||
var recUp = context.Executors.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (recUp == null) {
|
||||
return null;
|
||||
}
|
||||
recUp.Update(model);
|
||||
context.SaveChanges();
|
||||
return recUp.GetViewModel;
|
||||
}
|
||||
|
||||
public ExecutorViewModel? Delete(ExecutorBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var element = context.Executors.FirstOrDefault(rec => rec.Id == model.ID);
|
||||
if (element != null)
|
||||
var recDel = context.Executors
|
||||
.Include(x => x.Works)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (recDel != null)
|
||||
{
|
||||
context.Executors.Remove(element);
|
||||
context.Executors.Remove(recDel);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
return recDel.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExecutorViewModel? GetElement(ExecutorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
using var context = new Database();
|
||||
if (model.Id.HasValue) {
|
||||
return context.Executors
|
||||
.Include(x => x.Works)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Executors.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email ||
|
||||
(model.Id.HasValue && x.Id == model.Id)))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ExecutorViewModel> GetFilteredList(ExecutorSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return new();
|
||||
else {
|
||||
return context.Executors
|
||||
.Include (x => x.Works)
|
||||
.FirstOrDefault(x => x.Email == model.Email)
|
||||
?.GetViewModel;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Executors.Where(x => x.Email.Contains(model.Email)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ExecutorViewModel> GetFullList()
|
||||
@ -54,31 +74,5 @@ namespace ServiceStationsDataBaseImplement.Implements
|
||||
using var context = new Database();
|
||||
return context.Executors.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ExecutorViewModel? Insert(ExecutorBindingModel model)
|
||||
{
|
||||
var newComponent = Executor.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.Executors.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ExecutorViewModel? Update(ExecutorBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var component = context.Executors.FirstOrDefault(x => x.Id == model.ID);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +0,0 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationsContracts.StorageContracts;
|
||||
using ServiceStationsDataBaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Implements
|
||||
{
|
||||
public class ReportStorage : ITaskStorage
|
||||
{
|
||||
public TaskViewModel? Delete(ReportBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var element = context.Reports.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Reports.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TaskViewModel? GetElement(TaskSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Reports.FirstOrDefault(x =>
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<TaskViewModel> GetFilteredList(TaskSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Reports.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<TaskViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.Reports.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public TaskViewModel? Insert(ReportBindingModel model)
|
||||
{
|
||||
var newComponent = Report.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.Reports.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public TaskViewModel? Update(ReportBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var component = context.Reports.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationsContracts.StorageContracts;
|
||||
using ServiceStationsDataBaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Implements {
|
||||
public class TaskStorage : ITaskStorage {
|
||||
public TaskViewModel? Insert(TaskBindingModel model) {
|
||||
var newRec = TaskByWork.Create(model);
|
||||
if (newRec == null) {
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.Tasks.Add(newRec);
|
||||
context.SaveChanges();
|
||||
return newRec.GetViewModel;
|
||||
}
|
||||
|
||||
public TaskViewModel? Update(TaskBindingModel model) {
|
||||
using var context = new Database();
|
||||
var recUp = context.Tasks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (recUp == null) {
|
||||
return null;
|
||||
}
|
||||
recUp.Update(model);
|
||||
context.SaveChanges();
|
||||
return recUp.GetViewModel;
|
||||
}
|
||||
|
||||
public TaskViewModel? Delete(TaskBindingModel model) {
|
||||
using var context = new Database();
|
||||
var recDel = context.Tasks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (recDel != null) {
|
||||
context.Tasks.Remove(recDel);
|
||||
context.SaveChanges();
|
||||
return recDel.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TaskViewModel? GetElement(TaskSearchModel model) {
|
||||
using var context = new Database();
|
||||
if (model.Id.HasValue) {
|
||||
return context.Tasks
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
else {
|
||||
return context.Tasks
|
||||
.FirstOrDefault(x => x.Name == model.Name)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<TaskViewModel> GetFullList() {
|
||||
using var context = new Database();
|
||||
return context.Tasks.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationsContracts.StorageContracts;
|
||||
@ -13,70 +14,113 @@ namespace ServiceStationsDataBaseImplement.Implements
|
||||
{
|
||||
public class WorkStorage : IWorkStorage
|
||||
{
|
||||
public WorkViewModel? Insert(WorkBindingModel model) {
|
||||
|
||||
using var context = new Database();
|
||||
var newRec = Work.Create(context,model);
|
||||
if (newRec == null) {
|
||||
return null;
|
||||
}
|
||||
context.Works.Add(newRec);
|
||||
context.SaveChanges();
|
||||
return newRec.GetViewModel;
|
||||
}
|
||||
|
||||
public WorkViewModel? Update(WorkBindingModel model) {
|
||||
using var context = new Database();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try {
|
||||
var recUp = context.Works.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (recUp == null) {
|
||||
return null;
|
||||
}
|
||||
recUp.Update(model);
|
||||
context.SaveChanges();
|
||||
recUp.UpdateClients(context, model);
|
||||
transaction.Commit();
|
||||
return recUp.GetViewModel;
|
||||
}
|
||||
catch {
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public WorkViewModel? Delete(WorkBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var element = context.Works.FirstOrDefault(rec => rec.Id == model.ID);
|
||||
if (element != null)
|
||||
var recDel = context.Works
|
||||
.Include(x => x.WorkClients)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (recDel != null)
|
||||
{
|
||||
context.Works.Remove(element);
|
||||
context.Works.Remove(recDel);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
return recDel.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WorkViewModel? GetElement(WorkSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Works.FirstOrDefault(x =>
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
if (model.Id.HasValue) {
|
||||
return context.Works
|
||||
.Include(x => x.WorkClients)
|
||||
.ThenInclude(x => x._work)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
else if (model.ExecutorId.HasValue) {
|
||||
return context.Works
|
||||
.Include(x => x.WorkClients)
|
||||
.ThenInclude(x => x._work)
|
||||
.FirstOrDefault(x => x.ExecutorId == model.ExecutorId)
|
||||
?.GetViewModel;
|
||||
}
|
||||
return context.Works
|
||||
.Include(x => x.WorkClients)
|
||||
.ThenInclude(x => x._work)
|
||||
.FirstOrDefault(x => x.TaskId == model.TaskId)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<WorkViewModel> GetFilteredList(WorkSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
using var context = new Database();
|
||||
if (model.DateFrom.HasValue && model.DateTo.HasValue) {
|
||||
return context.Works
|
||||
.Include(x => x.WorkClients)
|
||||
.ThenInclude(x => x._work)
|
||||
.Where(x => x.Date >= model.DateFrom && x.Date <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Works.Where(x => x.Id == model.Id).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)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return context.Works
|
||||
.Include(x => x.WorkClients)
|
||||
.ThenInclude(x => x._work)
|
||||
.Where(x => x.TaskId == model.TaskId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<WorkViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.Works.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public WorkViewModel? Insert(WorkBindingModel model)
|
||||
{
|
||||
var newComponent = Work.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
context.Works.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public WorkViewModel? Update(WorkBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var component = context.Works.FirstOrDefault(x => x.Id == model.ID);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
return context.Works
|
||||
.Include(x => x.WorkClients)
|
||||
.ThenInclude(x => x._work)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
using Microsoft.IdentityModel.Abstractions;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationDataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models
|
||||
{
|
||||
public class CategoryWork : ICategoryWorkModel
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int ExecutorId { get; set; }
|
||||
|
||||
public int ID { get; set; }
|
||||
public static CategoryWork? Create(CategoryWorkBindingModel? model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new CategoryWork()
|
||||
{
|
||||
Name = model.Name,
|
||||
ExecutorId = model.ExecutorId,
|
||||
ID = model.ID
|
||||
};
|
||||
}
|
||||
public static CategoryWork? Create(CategoryWorkViewModel model)
|
||||
{
|
||||
return new CategoryWork
|
||||
{
|
||||
Name = model.Name,
|
||||
ExecutorId = model.ExecutorId,
|
||||
ID = model.ID
|
||||
};
|
||||
}
|
||||
public void Update(CategoryWorkBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
ExecutorId = model.ExecutorId;
|
||||
}
|
||||
public CategoryWorkViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
Name = Name,
|
||||
ExecutorId = ExecutorId
|
||||
};
|
||||
}
|
||||
}
|
@ -4,90 +4,55 @@ using ServiceStationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[Required]
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int Point { get; set; }
|
||||
public int ID { get; set; }
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
FirstName = model.FirstName,
|
||||
LastName = model.LastName,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Login = model.Login,
|
||||
Point = model.Point,
|
||||
ID = model.ID
|
||||
|
||||
};
|
||||
}
|
||||
public static Client? Create(ClientViewModel model)
|
||||
{
|
||||
return new Client
|
||||
{
|
||||
FirstName = model.FirstName,
|
||||
LastName = model.LastName,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Login = model.Login,
|
||||
Point = model.Point,
|
||||
ID = model.ID
|
||||
};
|
||||
}
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FirstName = model.FirstName;
|
||||
LastName = model.LastName;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
Login = model.Login;
|
||||
Point = model.Point;
|
||||
|
||||
}
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
public class Client : IClientModel {
|
||||
|
||||
FirstName = FirstName,
|
||||
LastName = LastName,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
PhoneNumber = PhoneNumber,
|
||||
Login = Login,
|
||||
Point = Point,
|
||||
ID = ID
|
||||
};
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
}
|
||||
[Required]
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<WorkClient> WorkClients { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel? model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return new Client() {
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Password = model.Password,
|
||||
Login = model.Login
|
||||
};
|
||||
}
|
||||
|
||||
public void Update (ClientBindingModel? model) {
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
FIO = model.FIO;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new() {
|
||||
Id = Id,
|
||||
FIO = FIO,
|
||||
Password = Password,
|
||||
Login = Login
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models
|
||||
{
|
||||
public class ClientWork : IClientWorkModel
|
||||
{
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
[Required]
|
||||
public int WorkId { get; set; }
|
||||
public static ClientWork? Create(ClientWorkBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ClientWork()
|
||||
{
|
||||
ClientId = model.ClientId,
|
||||
WorkId = model.WorkId
|
||||
};
|
||||
}
|
||||
public static ClientWork? Create(ClientWorkViewModel model)
|
||||
{
|
||||
return new ClientWork
|
||||
{
|
||||
ClientId = model.ClientId,
|
||||
WorkId = model.WorkId
|
||||
};
|
||||
}
|
||||
public void Update(ClientWorkBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientId = model.ClientId;
|
||||
WorkId = model.WorkId;
|
||||
|
||||
}
|
||||
public ClientWorkViewModel GetViewModel => new()
|
||||
{
|
||||
ClientId = ClientId,
|
||||
WorkId = WorkId
|
||||
};
|
||||
}
|
||||
}
|
@ -1,85 +1,60 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using Microsoft.Identity.Client;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models
|
||||
{
|
||||
public class Executor : IExecutorModel
|
||||
{
|
||||
[Required]
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int Id { get; set; }
|
||||
public static Executor? Create(ExecutorBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Executor()
|
||||
{
|
||||
FirstName = model.FirstName,
|
||||
LastName = model.LastName,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Login = model.Login,
|
||||
Id = model.Id
|
||||
public class Executor : IExecutorModel {
|
||||
|
||||
};
|
||||
}
|
||||
public static Executor? Create(ExecutorViewModel model)
|
||||
{
|
||||
return new Executor
|
||||
{
|
||||
FirstName = model.FirstName,
|
||||
LastName = model.LastName,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Login = model.Login,
|
||||
Id = model.Id
|
||||
};
|
||||
}
|
||||
public void Update(ExecutorBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FirstName = model.FirstName;
|
||||
LastName = model.LastName;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
Login = model.Login;
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
public ExecutorViewModel GetViewModel => new()
|
||||
{
|
||||
FirstName = FirstName,
|
||||
LastName = LastName,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
PhoneNumber = PhoneNumber,
|
||||
Login = Login,
|
||||
Id = Id
|
||||
};
|
||||
}
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string ExecutorFIO { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ExecutorId")]
|
||||
public virtual List<Work> Works { get; set; } = new();
|
||||
|
||||
public static Executor? Create(ExecutorBindingModel? model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return new Executor() {
|
||||
Id = model.Id,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
ExecutorFIO = model.ExecutorFIO
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public void Update(ExecutorBindingModel? model) {
|
||||
if (model== null) {
|
||||
return;
|
||||
}
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
ExecutorFIO = model.ExecutorFIO;
|
||||
}
|
||||
|
||||
public ExecutorViewModel GetViewModel => new() {
|
||||
Id = Id,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
ExecutorFIO = ExecutorFIO
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models
|
||||
{
|
||||
public class Report : ITaskModel
|
||||
{
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public static Report? Create(ReportBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Report()
|
||||
{
|
||||
Id = model.Id,
|
||||
Count = model.Count
|
||||
};
|
||||
}
|
||||
public static Report? Create(TaskViewModel model)
|
||||
{
|
||||
return new Report
|
||||
{
|
||||
Id = model.Id,
|
||||
Count = model.Count,
|
||||
};
|
||||
}
|
||||
public void Update(ReportBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Count = model.Count;
|
||||
|
||||
}
|
||||
public TaskViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Count = Count
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models {
|
||||
public class TaskByWork : ITaskModel {
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public static TaskByWork? Create(TaskBindingModel? model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return new TaskByWork() {
|
||||
Id = model.Id,
|
||||
Name = model.Name
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TaskBindingModel? model) {
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
}
|
||||
|
||||
public TaskViewModel GetViewModel => new() {
|
||||
Id = Id,
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
}
|
@ -1,85 +1,100 @@
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationDataModels.Enums;
|
||||
using ServiceStationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models
|
||||
{
|
||||
public class Work : IWorkModel
|
||||
{
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public int Price { get; set; }
|
||||
public class Work : IWorkModel {
|
||||
|
||||
public WorkStatus Status { get; set; } = WorkStatus.Неизвестно;
|
||||
public int Id { get; set; }
|
||||
|
||||
public int ExecutorId { get; set; }
|
||||
[Required]
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
|
||||
public int ReportId { get; set; }
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
public int CategoryWorkId { get; set; }
|
||||
[ForeignKey("ExecutorId")]
|
||||
public int ExecutorId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public static Work? Create(WorkBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Work()
|
||||
{
|
||||
Date = model.Date,
|
||||
Price = model.Price,
|
||||
Status = model.Status,
|
||||
ExecutorId = model.ExecutorId,
|
||||
ReportId = model.ReportId,
|
||||
CategoryWorkId = model.CategoryWorkId,
|
||||
Id = model.Id
|
||||
[ForeignKey("TaskId")]
|
||||
public int TaskId { get; set; }
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
public static Work? Create(WorkViewModel model)
|
||||
{
|
||||
return new Work
|
||||
{
|
||||
Date = model.Date,
|
||||
Price = model.Price,
|
||||
Status = model.Status,
|
||||
ExecutorId = model.ExecutorId,
|
||||
ReportId = model.ReportId,
|
||||
CategoryWorkId = model.CategoryWorkId,
|
||||
Id = model.Id
|
||||
};
|
||||
}
|
||||
public void Update(WorkBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Date = model.Date;
|
||||
Price = model.Price;
|
||||
Status = model.Status;
|
||||
ExecutorId = model.ExecutorId;
|
||||
ReportId = model.ReportId;
|
||||
CategoryWorkId = model.CategoryWorkId;
|
||||
|
||||
[ForeignKey("WorkId")]
|
||||
public virtual List<WorkClient> WorkClients { get; set; } = new();
|
||||
|
||||
}
|
||||
public WorkViewModel GetViewModel => new()
|
||||
{
|
||||
Date = Date,
|
||||
Price = Price,
|
||||
Status = Status,
|
||||
ExecutorId = ExecutorId,
|
||||
ReportId = ReportId,
|
||||
CategoryWorkId = CategoryWorkId,
|
||||
Id = Id
|
||||
};
|
||||
}
|
||||
|
||||
public Dictionary<int, IClientModel>? _clientList = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IClientModel> ClientList {
|
||||
get {
|
||||
if (_clientList == null) {
|
||||
_clientList = WorkClients.ToDictionary(recWC => recWC.WorkId, recWC => recWC._client as IClientModel);
|
||||
}
|
||||
return _clientList;
|
||||
}
|
||||
}
|
||||
|
||||
public static Work? Create(Database context, WorkBindingModel? model) {
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
return new Work() {
|
||||
Id = model.Id,
|
||||
Date = model.Date,
|
||||
Price = model.Price,
|
||||
ExecutorId = model.ExecutorId,
|
||||
TaskId = model.TaskId,
|
||||
WorkClients = model.ClientList.Select(x => new WorkClient {
|
||||
_work = context.Works.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(WorkBindingModel? model) {
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public WorkViewModel GetViewModel => new() {
|
||||
Id = Id,
|
||||
Date = Date,
|
||||
Price = Price,
|
||||
ExecutorId = ExecutorId,
|
||||
TaskId = TaskId,
|
||||
ClientList = ClientList
|
||||
};
|
||||
|
||||
public void UpdateClients(Database context, WorkBindingModel model) {
|
||||
var worckClients = context.WorksClients.Where(rec => rec.WorkId == model.Id).ToList();
|
||||
if (worckClients != null && worckClients.Count > 0) {
|
||||
// Нужно удалить те записи, которых нет в модели
|
||||
context.WorksClients.RemoveRange(worckClients.Where(rec => !model.ClientList.ContainsKey(rec.ClientId)));
|
||||
context.SaveChanges();
|
||||
}
|
||||
// получаем работу, добавляем новые записи
|
||||
var work = context.Works.First(x => x.Id == Id);
|
||||
foreach (var wc in model.ClientList) {
|
||||
context.WorksClients.Add(new WorkClient {
|
||||
_work = work,
|
||||
_client = context.Clients.First(x => x.Id == wc.Key)
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_clientList = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ServiceStationsDataBaseImplement.Models {
|
||||
public class WorkClient {
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int WorkId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
|
||||
public virtual Work _work { get; set; } = new();
|
||||
public virtual Client _client { get; set; } = new();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user