часть
This commit is contained in:
parent
018447776b
commit
62aaba8e53
123
LawFirm/LawFirmBusinessLogic/BusinessLogics/ImplementerLogic.cs
Normal file
123
LawFirm/LawFirmBusinessLogic/BusinessLogics/ImplementerLogic.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.BusinessLogicsContracts;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StoragesContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModel.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ImplementerLogic : IImplementerLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IImplementerStorage _implementerStorage;
|
||||||
|
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_implementerStorage = implementerStorage;
|
||||||
|
}
|
||||||
|
public bool Create(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_implementerStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_implementerStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}",
|
||||||
|
model.ImplementerFIO, model.Id);
|
||||||
|
var element = _implementerStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id);
|
||||||
|
var list = (model == null) ? _implementerStorage.GetFullList() :
|
||||||
|
_implementerStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public bool Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_implementerStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (model.WorkExperience < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience));
|
||||||
|
}
|
||||||
|
if (model.Qualification < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет фио исполнителя", nameof(model.ImplementerFIO));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO);
|
||||||
|
var element = _implementerStorage.GetElement(new ImplementerSearchModel
|
||||||
|
{
|
||||||
|
ImplementerFIO = model.ImplementerFIO,
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Исполнитель с таким фио уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,8 @@ using LawFirmContracts.StoragesContracts;
|
|||||||
using LawFirmContracts.ViewModels;
|
using LawFirmContracts.ViewModels;
|
||||||
using LawFirmDataModels.Enums;
|
using LawFirmDataModels.Enums;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using DocumentFormat.OpenXml.EMMA;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
|
||||||
namespace LawFirmBusinessLogic.BusinessLogics
|
namespace LawFirmBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
@ -47,12 +49,18 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
|
model.DateCreate = viewModel.DateCreate;
|
||||||
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
model.DateImplement = viewModel.DateImplement;
|
model.DateImplement = viewModel.DateImplement;
|
||||||
}
|
}
|
||||||
CheckModel(model, false);
|
if (viewModel.ImplementerId.HasValue)
|
||||||
|
model.ImplementerId = viewModel.ImplementerId;
|
||||||
|
model.DocumentId = viewModel.DocumentId;
|
||||||
|
model.Sum = viewModel.Sum;
|
||||||
|
model.Count = viewModel.Count;
|
||||||
|
CheckModel(model);
|
||||||
if (_orderStorage.Update(model) == null)
|
if (_orderStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
model.Status--;
|
model.Status--;
|
||||||
@ -86,6 +94,22 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||||
|
var element = _orderStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
146
LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs
Normal file
146
LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.BusinessLogicsContracts;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModels.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class WorkModeling : IWorkProcess
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly Random _rnd;
|
||||||
|
private IOrderLogic? _orderLogic;
|
||||||
|
public WorkModeling(ILogger<WorkModeling> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_rnd = new Random(1000);
|
||||||
|
}
|
||||||
|
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic
|
||||||
|
orderLogic)
|
||||||
|
{
|
||||||
|
_orderLogic = orderLogic;
|
||||||
|
var implementers = implementerLogic.ReadList(null);
|
||||||
|
if (implementers == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("DoWork. Implementers is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Принят });
|
||||||
|
if (orders == null || orders.Count == 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||||
|
foreach (var implementer in implementers)
|
||||||
|
{
|
||||||
|
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Иммитация работы исполнителя
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="implementer"></param>
|
||||||
|
/// <param name="orders"></param>
|
||||||
|
private async Task WorkerWorkAsync(ImplementerViewModel implementer,
|
||||||
|
List<OrderViewModel> orders)
|
||||||
|
{
|
||||||
|
if (_orderLogic == null || implementer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await RunOrderInWork(implementer);
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
foreach (var order in orders)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
|
||||||
|
// пытаемся назначить заказ на исполнителя
|
||||||
|
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = order.Id,
|
||||||
|
ImplementerId = implementer.Id
|
||||||
|
});
|
||||||
|
// делаем работу
|
||||||
|
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100,
|
||||||
|
1000) * order.Count);
|
||||||
|
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||||
|
_orderLogic.FinishOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = order.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error try get work");
|
||||||
|
}
|
||||||
|
// заканчиваем выполнение имитации в случае иной ошибки
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error while do work");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
// отдыхаем
|
||||||
|
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="implementer"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task RunOrderInWork(ImplementerViewModel implementer)
|
||||||
|
{
|
||||||
|
if (_orderLogic == null || implementer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||||
|
{
|
||||||
|
ImplementerId = implementer.Id,
|
||||||
|
OrderStatus = OrderStatus.Выполняется
|
||||||
|
}));
|
||||||
|
if (runOrder == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
|
||||||
|
// доделываем работу
|
||||||
|
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) *
|
||||||
|
runOrder.Count);
|
||||||
|
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}",
|
||||||
|
implementer.Id, runOrder.Id);
|
||||||
|
_orderLogic.FinishOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = runOrder.Id
|
||||||
|
});
|
||||||
|
// отдыхаем
|
||||||
|
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||||
|
}
|
||||||
|
// заказа может не быть, просто игнорируем ошибку
|
||||||
|
catch (InvalidOperationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error try get work");
|
||||||
|
}
|
||||||
|
// а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error while do work");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using LawFirmDataModel.Models;
|
||||||
|
using LawFirmDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ImplementerBindingModel : IImplementerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ImplementerFIO { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
public int WorkExperience { get; set; }
|
||||||
|
public int Qualification { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,8 @@ namespace LawFirmContracts.BindingModels
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int DocumentId { get; set; }
|
public int DocumentId { get; set; }
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
public int Count { get; set; }
|
public int? ImplementerId { get; set; }
|
||||||
|
public int Count { get; set; }
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IImplementerLogic
|
||||||
|
{
|
||||||
|
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
|
||||||
|
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
|
||||||
|
bool Create(ImplementerBindingModel model);
|
||||||
|
bool Update(ImplementerBindingModel model);
|
||||||
|
bool Delete(ImplementerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ namespace LawFirmContracts.BusinessLogicsContracts
|
|||||||
public interface IOrderLogic
|
public interface IOrderLogic
|
||||||
{
|
{
|
||||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||||
|
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||||
bool CreateOrder(OrderBindingModel model);
|
bool CreateOrder(OrderBindingModel model);
|
||||||
bool TakeOrderInWork(OrderBindingModel model);
|
bool TakeOrderInWork(OrderBindingModel model);
|
||||||
bool FinishOrder(OrderBindingModel model);
|
bool FinishOrder(OrderBindingModel model);
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IWorkProcess
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Запуск работ
|
||||||
|
/// </summary>
|
||||||
|
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ImplementerSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ImplementerFIO { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
namespace LawFirmContracts.SearchModels
|
using LawFirmDataModels.Enums;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.SearchModels
|
||||||
{
|
{
|
||||||
public class OrderSearchModel
|
public class OrderSearchModel
|
||||||
{
|
{
|
||||||
@ -6,5 +8,7 @@
|
|||||||
public DateTime? DateFrom { get; set; }
|
public DateTime? DateFrom { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime? DateTo { get; set; }
|
||||||
public int? ClientId { get; set; }
|
public int? ClientId { get; set; }
|
||||||
}
|
public int? ImplementerId { get; set; }
|
||||||
|
public OrderStatus? OrderStatus { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IImplementerStorage
|
||||||
|
{
|
||||||
|
List<ImplementerViewModel> GetFullList();
|
||||||
|
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
|
||||||
|
ImplementerViewModel? GetElement(ImplementerSearchModel model);
|
||||||
|
ImplementerViewModel? Insert(ImplementerBindingModel model);
|
||||||
|
ImplementerViewModel? Update(ImplementerBindingModel model);
|
||||||
|
ImplementerViewModel? Delete(ImplementerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
27
LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs
Normal file
27
LawFirm/LawFirmContracts/ViewModels/ImplementerViewModel.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using LawFirmDataModel.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ImplementerViewModel : IImplementerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("ФИО исполнителя")]
|
||||||
|
public string ImplementerFIO { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Пароль")]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Стаж работы")]
|
||||||
|
public int WorkExperience { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Квалификация")]
|
||||||
|
public int Qualification { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -9,11 +9,14 @@ namespace LawFirmContracts.ViewModels
|
|||||||
[DisplayName("Номер")]
|
[DisplayName("Номер")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int DocumentId { get; set; }
|
public int DocumentId { get; set; }
|
||||||
|
public int? ImplementerId { get; set; }
|
||||||
[DisplayName("Документ")]
|
[DisplayName("Документ")]
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
[DisplayName("Данные клиента")]
|
[DisplayName("Данные клиента")]
|
||||||
public string ClientFIO { get; set; } = string.Empty;
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
[DisplayName("Документ")]
|
[DisplayName("Фамилия исполнителя")]
|
||||||
|
public string ImplementerFIO { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Документ")]
|
||||||
public string DocumentName { get; set; } = string.Empty;
|
public string DocumentName { get; set; } = string.Empty;
|
||||||
[DisplayName("Количество")]
|
[DisplayName("Количество")]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
16
LawFirm/LawFirmDataModels/Models/IImplementerModel.cs
Normal file
16
LawFirm/LawFirmDataModels/Models/IImplementerModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmDataModel.Models
|
||||||
|
{
|
||||||
|
public interface IImplementerModel
|
||||||
|
{
|
||||||
|
string ImplementerFIO { get; }
|
||||||
|
string Password { get; }
|
||||||
|
int WorkExperience { get; }
|
||||||
|
int Qualification { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -11,5 +11,6 @@ namespace LawFirmDataModels.Models
|
|||||||
OrderStatus Status { get; }
|
OrderStatus Status { get; }
|
||||||
DateTime DateCreate { get; }
|
DateTime DateCreate { get; }
|
||||||
DateTime? DateImplement { get; }
|
DateTime? DateImplement { get; }
|
||||||
|
int? ImplementerId { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StoragesContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ImplementerStorage : IImplementerStorage
|
||||||
|
{
|
||||||
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
context.Implementers.Remove(res);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
if (model.ImplementerFIO != null && model.Password != null)
|
||||||
|
return context.Implementers
|
||||||
|
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
|
||||||
|
&& x.Password.Equals(model.Password))
|
||||||
|
?.GetViewModel;
|
||||||
|
if (model.ImplementerFIO != null)
|
||||||
|
return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
var res = GetElement(model);
|
||||||
|
return res != null ? new() { res } : new();
|
||||||
|
}
|
||||||
|
if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Implementers
|
||||||
|
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
public List<ImplementerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
return context.Implementers.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var res = Implementer.Create(model);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
context.Implementers.Add(res);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDatabase();
|
||||||
|
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
res.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,12 +11,26 @@ namespace LawFirmDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new LawFirmDatabase();
|
using var context = new LawFirmDatabase();
|
||||||
return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Document)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
if (model.ImplementerId.HasValue && model.OrderStatus.HasValue)
|
||||||
|
{
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Document)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
@ -48,7 +62,17 @@ namespace LawFirmDatabaseImplement.Implements
|
|||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
else
|
else if (model.OrderStatus.HasValue)
|
||||||
|
{
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Document)
|
||||||
|
.Include(x => x.Client)
|
||||||
|
.Include(x => x.Implementer)
|
||||||
|
.Where(x => x.Status == model.OrderStatus)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
@ -56,7 +80,7 @@ namespace LawFirmDatabaseImplement.Implements
|
|||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDatabase();
|
using var context = new LawFirmDatabase();
|
||||||
return context.Orders.Include(x => x.Document).Include(x => x.Client).Select(x => x.GetViewModel).ToList();
|
return context.Orders.Include(x => x.Document).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -73,19 +97,19 @@ namespace LawFirmDatabaseImplement.Implements
|
|||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDatabase();
|
using var context = new LawFirmDatabase();
|
||||||
var order = context.Orders.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
|
var order = context.Orders.Include(x => x.Client).Include(x => x.Implementer).Include(x => x.Document).FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Orders.Include(x => x.Document).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
return order.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDatabase();
|
using var context = new LawFirmDatabase();
|
||||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
var element = context.Orders.Include(x => x.Client).Include(x => x.Implementer).Include(x => x.Document).FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
var deletedElement = context.Orders
|
var deletedElement = context.Orders
|
||||||
@ -94,8 +118,8 @@ namespace LawFirmDatabaseImplement.Implements
|
|||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return deletedElement;
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace LawFirmDatabaseImplement
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
if (optionsBuilder.IsConfigured == false)
|
||||||
{
|
{
|
||||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS; Initial Catalog=LawFirmDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS; Initial Catalog=LawFirm6;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
}
|
}
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
@ -18,5 +18,6 @@ namespace LawFirmDatabaseImplement
|
|||||||
public virtual DbSet<DocumentBlank> DocumentBlanks { set; get; }
|
public virtual DbSet<DocumentBlank> DocumentBlanks { set; get; }
|
||||||
public virtual DbSet<Order> Orders { set; get; }
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
public virtual DbSet<Client> Clients { set; get; }
|
public virtual DbSet<Client> Clients { set; get; }
|
||||||
}
|
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace LawFirmDatabaseImplement.Migrations
|
namespace LawFirmDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(LawFirmDatabase))]
|
[DbContext(typeof(LawFirmDatabase))]
|
||||||
[Migration("20240517194322_InitialCreate")]
|
[Migration("20240524144938_r")]
|
||||||
partial class InitialCreate
|
partial class r
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -116,6 +116,33 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
b.ToTable("DocumentBlanks");
|
b.ToTable("DocumentBlanks");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ImplementerFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("Qualification")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("WorkExperience")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Implementers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -139,6 +166,9 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
b.Property<int>("DocumentId")
|
b.Property<int>("DocumentId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int?>("ImplementerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
@ -151,6 +181,8 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("DocumentId");
|
b.HasIndex("DocumentId");
|
||||||
|
|
||||||
|
b.HasIndex("ImplementerId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -187,9 +219,15 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Implementer", "Implementer")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ImplementerId");
|
||||||
|
|
||||||
b.Navigation("Client");
|
b.Navigation("Client");
|
||||||
|
|
||||||
b.Navigation("Document");
|
b.Navigation("Document");
|
||||||
|
|
||||||
|
b.Navigation("Implementer");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
|
||||||
@ -208,6 +246,11 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
namespace LawFirmDatabaseImplement.Migrations
|
namespace LawFirmDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class InitialCreate : Migration
|
public partial class r : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
@ -54,6 +54,22 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
table.PrimaryKey("PK_Documents", x => x.Id);
|
table.PrimaryKey("PK_Documents", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Implementers",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Qualification = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Implementers", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "DocumentBlanks",
|
name: "DocumentBlanks",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -93,6 +109,7 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
Sum = table.Column<double>(type: "float", nullable: false),
|
Sum = table.Column<double>(type: "float", nullable: false),
|
||||||
Status = table.Column<int>(type: "int", nullable: false),
|
Status = table.Column<int>(type: "int", nullable: false),
|
||||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
ImplementerId = table.Column<int>(type: "int", nullable: true),
|
||||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
@ -110,6 +127,11 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
principalTable: "Documents",
|
principalTable: "Documents",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Orders_Implementers_ImplementerId",
|
||||||
|
column: x => x.ImplementerId,
|
||||||
|
principalTable: "Implementers",
|
||||||
|
principalColumn: "Id");
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
@ -131,6 +153,11 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
name: "IX_Orders_DocumentId",
|
name: "IX_Orders_DocumentId",
|
||||||
table: "Orders",
|
table: "Orders",
|
||||||
column: "DocumentId");
|
column: "DocumentId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_ImplementerId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "ImplementerId");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -150,6 +177,9 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Documents");
|
name: "Documents");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Implementers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -113,6 +113,33 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
b.ToTable("DocumentBlanks");
|
b.ToTable("DocumentBlanks");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ImplementerFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("Qualification")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("WorkExperience")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Implementers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -136,6 +163,9 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
b.Property<int>("DocumentId")
|
b.Property<int>("DocumentId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int?>("ImplementerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
@ -148,6 +178,8 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("DocumentId");
|
b.HasIndex("DocumentId");
|
||||||
|
|
||||||
|
b.HasIndex("ImplementerId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -184,9 +216,15 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("LawFirmDatabaseImplement.Models.Implementer", "Implementer")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ImplementerId");
|
||||||
|
|
||||||
b.Navigation("Client");
|
b.Navigation("Client");
|
||||||
|
|
||||||
b.Navigation("Document");
|
b.Navigation("Document");
|
||||||
|
|
||||||
|
b.Navigation("Implementer");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Blank", b =>
|
||||||
@ -205,6 +243,11 @@ namespace LawFirmDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
57
LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs
Normal file
57
LawFirm/LawFirmDatabaseImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModel.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Implementer : IImplementerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
public int WorkExperience { get; private set; }
|
||||||
|
public int Qualification { get; private set; }
|
||||||
|
[ForeignKey("ImplementerId")]
|
||||||
|
public virtual List<Order> Orders { get; private set; } = new();
|
||||||
|
public static Implementer? Create(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Password = model.Password,
|
||||||
|
Qualification = model.Qualification,
|
||||||
|
ImplementerFIO = model.ImplementerFIO,
|
||||||
|
WorkExperience = model.WorkExperience,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Password = model.Password;
|
||||||
|
Qualification = model.Qualification;
|
||||||
|
ImplementerFIO = model.ImplementerFIO;
|
||||||
|
WorkExperience = model.WorkExperience;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Password = Password,
|
||||||
|
Qualification = Qualification,
|
||||||
|
ImplementerFIO = ImplementerFIO,
|
||||||
|
WorkExperience = WorkExperience,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -21,10 +21,12 @@ namespace LawFirmDatabaseImplement.Models
|
|||||||
public OrderStatus Status { get; set; }
|
public OrderStatus Status { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime DateCreate { get; set; }
|
public DateTime DateCreate { get; set; }
|
||||||
|
public int? ImplementerId { get; private set; }
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
public virtual Document Document { get; set; }
|
public virtual Document Document { get; set; }
|
||||||
public virtual Client Client { get; set; }
|
public virtual Client Client { get; set; }
|
||||||
public int Id { get; set; }
|
public virtual Implementer? Implementer { get; private set; }
|
||||||
|
public int Id { get; set; }
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public static Order? Create(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -40,7 +42,8 @@ namespace LawFirmDatabaseImplement.Models
|
|||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement
|
DateImplement = model.DateImplement,
|
||||||
|
ImplementerId = model.ImplementerId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(OrderBindingModel? model)
|
public void Update(OrderBindingModel? model)
|
||||||
@ -49,8 +52,14 @@ namespace LawFirmDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DocumentId = model.DocumentId;
|
||||||
|
Count = model.Count;
|
||||||
|
Sum = model.Sum;
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
|
DateCreate = model.DateCreate;
|
||||||
DateImplement = model.DateImplement;
|
DateImplement = model.DateImplement;
|
||||||
|
ImplementerId = model.ImplementerId;
|
||||||
|
Id = model.Id;
|
||||||
}
|
}
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
@ -58,12 +67,14 @@ namespace LawFirmDatabaseImplement.Models
|
|||||||
DocumentId = DocumentId,
|
DocumentId = DocumentId,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
ClientFIO = Client.ClientFIO,
|
ClientFIO = Client.ClientFIO,
|
||||||
Count = Count,
|
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
|
||||||
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
DocumentName = Document.DocumentName
|
DocumentName = Document.DocumentName,
|
||||||
|
ImplementerId = ImplementerId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,11 +10,13 @@ namespace LawFirmFileImplement
|
|||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string DocumentFileName = "Document.xml";
|
private readonly string DocumentFileName = "Document.xml";
|
||||||
private readonly string ClientFileName = "Client.xml";
|
private readonly string ClientFileName = "Client.xml";
|
||||||
public List<Blank> Blanks { get; private set; }
|
private readonly string ImplementerFileName = "Implementer.xml";
|
||||||
|
public List<Blank> Blanks { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Document> Documents { get; private set; }
|
public List<Document> Documents { get; private set; }
|
||||||
public List<Client> Clients { get; private set; }
|
public List<Client> Clients { get; private set; }
|
||||||
public static DataFileSingleton GetInstance()
|
public List<Implementer> Implementers { get; private set; }
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
{
|
{
|
||||||
@ -26,13 +28,15 @@ namespace LawFirmFileImplement
|
|||||||
public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement);
|
public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||||
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!;
|
Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!;
|
||||||
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
|
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = new List<Order>();
|
||||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
}
|
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||||
|
}
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||||
Func<XElement, T> selectFunction)
|
Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StoragesContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ImplementerStorage : IImplementerStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton _source;
|
||||||
|
public ImplementerStorage()
|
||||||
|
{
|
||||||
|
_source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
_source.Implementers.Remove(res);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
if (model.ImplementerFIO != null && model.Password != null)
|
||||||
|
return _source.Implementers
|
||||||
|
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
|
||||||
|
&& x.Password.Equals(model.Password))
|
||||||
|
?.GetViewModel;
|
||||||
|
if (model.ImplementerFIO != null)
|
||||||
|
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
var res = GetElement(model);
|
||||||
|
return res != null ? new() { res } : new();
|
||||||
|
}
|
||||||
|
if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально)
|
||||||
|
{
|
||||||
|
return _source.Implementers
|
||||||
|
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
public List<ImplementerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||||
|
var res = Implementer.Create(model);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
_source.Implementers.Add(res);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
res.Update(model);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -33,8 +33,15 @@ namespace LawFirmFileImplement.Implements
|
|||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
var result = GetElement(model);
|
if (!model.Id.HasValue && model.OrderStatus.HasValue)
|
||||||
return result != null ? new() { result } : new();
|
{
|
||||||
|
return source.Orders
|
||||||
|
.Where(x => model.OrderStatus == x.Status)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
var result = GetElement(model);
|
||||||
|
return result != null ? new() { result } : new();
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
@ -42,6 +49,19 @@ namespace LawFirmFileImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (model.ImplementerId.HasValue && model.OrderStatus.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders
|
||||||
|
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&
|
||||||
|
model.OrderStatus == x.Status)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
if (model.ImplementerId.HasValue)
|
||||||
|
{
|
||||||
|
return source.Orders
|
||||||
|
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
return source.Orders.FirstOrDefault(x =>
|
return source.Orders.FirstOrDefault(x =>
|
||||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
76
LawFirm/LawFirmFileImplement/Models/Implementer.cs
Normal file
76
LawFirm/LawFirmFileImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModel.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace LawFirmFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Implementer : IImplementerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
public int WorkExperience { get; private set; }
|
||||||
|
public int Qualification { get; private set; }
|
||||||
|
public static Implementer? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
ImplementerFIO = element.Element("FIO")!.Value,
|
||||||
|
Password = element.Element("Password")!.Value,
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
|
||||||
|
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Implementer? Create(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Password = model.Password,
|
||||||
|
Qualification = model.Qualification,
|
||||||
|
ImplementerFIO = model.ImplementerFIO,
|
||||||
|
WorkExperience = model.WorkExperience,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Password = model.Password;
|
||||||
|
Qualification = model.Qualification;
|
||||||
|
ImplementerFIO = model.ImplementerFIO;
|
||||||
|
WorkExperience = model.WorkExperience;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Password = Password,
|
||||||
|
Qualification = Qualification,
|
||||||
|
ImplementerFIO = ImplementerFIO,
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Client",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("Password", Password),
|
||||||
|
new XElement("FIO", ImplementerFIO),
|
||||||
|
new XElement("Qualification", Qualification),
|
||||||
|
new XElement("WorkExperience", WorkExperience)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,8 @@ namespace LawFirmFileImplement.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int DocumentId { get; private set; }
|
public int DocumentId { get; private set; }
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
public int Count { get; private set; }
|
public int? ImplementerId { get; set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
@ -32,6 +33,7 @@ namespace LawFirmFileImplement.Models
|
|||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
|
ImplementerId = model.ImplementerId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static Order? Create(XElement element)
|
public static Order? Create(XElement element)
|
||||||
@ -40,12 +42,18 @@ namespace LawFirmFileImplement.Models
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
var dateImplement = element.Element("DateImplement")!.Value;
|
||||||
var order = new Order()
|
var order = new Order()
|
||||||
{
|
{
|
||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value),
|
DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value),
|
||||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
|
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
|
||||||
|
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||||
|
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||||
|
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement),
|
||||||
|
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
|
||||||
};
|
};
|
||||||
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
|
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
|
||||||
order.DateImplement = dateImpl;
|
order.DateImplement = dateImpl;
|
||||||
@ -63,8 +71,14 @@ namespace LawFirmFileImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DocumentId = model.DocumentId;
|
||||||
|
Count = model.Count;
|
||||||
|
Sum = model.Sum;
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
|
DateCreate = model.DateCreate;
|
||||||
|
ImplementerId = model.ImplementerId;
|
||||||
DateImplement = model.DateImplement;
|
DateImplement = model.DateImplement;
|
||||||
|
Id = model.Id;
|
||||||
}
|
}
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
@ -76,6 +90,7 @@ namespace LawFirmFileImplement.Models
|
|||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
ImplementerId = ImplementerId
|
||||||
};
|
};
|
||||||
public XElement GetXElement => new("Order",
|
public XElement GetXElement => new("Order",
|
||||||
new XAttribute("Id", Id),
|
new XAttribute("Id", Id),
|
||||||
@ -84,6 +99,7 @@ namespace LawFirmFileImplement.Models
|
|||||||
new XElement("Sum", Sum.ToString()),
|
new XElement("Sum", Sum.ToString()),
|
||||||
new XElement("Status", Status.ToString()),
|
new XElement("Status", Status.ToString()),
|
||||||
new XElement("DateCreate", DateCreate.ToString()),
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
new XElement("DateImplement", DateImplement.ToString()));
|
new XElement("DateImplement", DateImplement.ToString()),
|
||||||
|
new XElement("ImplementerId", ImplementerId));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,13 +9,15 @@ namespace LawFirmListImplement
|
|||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Document> Documents { get; set; }
|
public List<Document> Documents { get; set; }
|
||||||
public List<Client> Clients { get; set; }
|
public List<Client> Clients { get; set; }
|
||||||
private DataListSingleton()
|
public List<Implementer> Implementers { get; set; }
|
||||||
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Blanks = new List<Blank>();
|
Blanks = new List<Blank>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Documents = new List<Document>();
|
Documents = new List<Document>();
|
||||||
Clients = new List<Client>();
|
Clients = new List<Client>();
|
||||||
}
|
Implementers = new List<Implementer>();
|
||||||
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (_instance == null)
|
if (_instance == null)
|
||||||
|
113
LawFirm/LawFirmListImplement/Implements/ImplementerStorage.cs
Normal file
113
LawFirm/LawFirmListImplement/Implements/ImplementerStorage.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StoragesContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ImplementerStorage : IImplementerStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public ImplementerStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Implementers.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Implementers[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Implementers[i];
|
||||||
|
_source.Implementers.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
foreach (var x in _source.Implementers)
|
||||||
|
{
|
||||||
|
if (model.Id.HasValue && x.Id == model.Id)
|
||||||
|
return x.GetViewModel;
|
||||||
|
if (model.ImplementerFIO != null && model.Password != null &&
|
||||||
|
x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))
|
||||||
|
return x.GetViewModel;
|
||||||
|
if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||||
|
return x.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
var res = GetElement(model);
|
||||||
|
return res != null ? new() { res } : new();
|
||||||
|
}
|
||||||
|
// На случай если при расширении проекта фио не будет уникальным
|
||||||
|
// (по заданию оно уникально)
|
||||||
|
List<ImplementerViewModel> result = new();
|
||||||
|
if (model.ImplementerFIO != null)
|
||||||
|
{
|
||||||
|
foreach (var implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||||
|
{
|
||||||
|
result.Add(implementer.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ImplementerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ImplementerViewModel>();
|
||||||
|
foreach (var implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
result.Add(implementer.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
if (model.Id <= implementer.Id)
|
||||||
|
{
|
||||||
|
model.Id = implementer.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var res = Implementer.Create(model);
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
_source.Implementers.Add(res);
|
||||||
|
}
|
||||||
|
return res?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
if (implementer.Id == model.Id)
|
||||||
|
{
|
||||||
|
implementer.Update(model);
|
||||||
|
return implementer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,10 +32,10 @@ namespace LawFirmListImplement.Implements
|
|||||||
foreach (var order in _source.Orders)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
if (order.Id == model.Id ||
|
if (order.Id == model.Id ||
|
||||||
model.DateFrom <= order.DateCreate &&
|
model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo ||
|
||||||
order.DateCreate <= model.DateTo ||
|
model.ClientId.HasValue && order.ClientId == model.ClientId ||
|
||||||
model.ClientId.HasValue &&
|
model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId ||
|
||||||
order.ClientId == model.ClientId)
|
model.OrderStatus.HasValue && model.OrderStatus == order.Status)
|
||||||
{
|
{
|
||||||
result.Add(GetViewModel(order));
|
result.Add(GetViewModel(order));
|
||||||
}
|
}
|
||||||
@ -50,7 +50,16 @@ namespace LawFirmListImplement.Implements
|
|||||||
}
|
}
|
||||||
foreach (var order in _source.Orders)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
if (model.Id.HasValue && order.Id == model.Id)
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
return GetViewModel(order);
|
||||||
|
}
|
||||||
|
else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue &&
|
||||||
|
order.ImplementerId == model.ImplementerId && model.OrderStatus == order.Status)
|
||||||
|
{
|
||||||
|
return GetViewModel(order);
|
||||||
|
}
|
||||||
|
else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
|
||||||
{
|
{
|
||||||
return GetViewModel(order);
|
return GetViewModel(order);
|
||||||
}
|
}
|
||||||
|
53
LawFirm/LawFirmListImplement/Models/Implementer.cs
Normal file
53
LawFirm/LawFirmListImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDataModel.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmListImplement.Models
|
||||||
|
{
|
||||||
|
public class Implementer : IImplementerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
public int WorkExperience { get; private set; }
|
||||||
|
public int Qualification { get; private set; }
|
||||||
|
public static Implementer? Create(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Password = model.Password,
|
||||||
|
Qualification = model.Qualification,
|
||||||
|
ImplementerFIO = model.ImplementerFIO,
|
||||||
|
WorkExperience = model.WorkExperience,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Password = model.Password;
|
||||||
|
Qualification = model.Qualification;
|
||||||
|
ImplementerFIO = model.ImplementerFIO;
|
||||||
|
WorkExperience = model.WorkExperience;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Password = Password,
|
||||||
|
Qualification = Qualification,
|
||||||
|
ImplementerFIO = ImplementerFIO,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,8 @@ namespace LawFirmListImplement.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int DocumentId { get; private set; }
|
public int DocumentId { get; private set; }
|
||||||
public int ClientId { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
public int Count { get; private set; }
|
public int? ImplementerId { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
@ -30,7 +31,8 @@ namespace LawFirmListImplement.Models
|
|||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement
|
DateImplement = model.DateImplement,
|
||||||
|
ImplementerId = model.ImplementerId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(OrderBindingModel? model)
|
public void Update(OrderBindingModel? model)
|
||||||
@ -39,8 +41,14 @@ namespace LawFirmListImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DocumentId = model.DocumentId;
|
||||||
|
Count = model.Count;
|
||||||
|
Sum = model.Sum;
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
|
DateCreate = model.DateCreate;
|
||||||
DateImplement = model.DateImplement;
|
DateImplement = model.DateImplement;
|
||||||
|
ImplementerId = model.ImplementerId;
|
||||||
|
Id = model.Id;
|
||||||
}
|
}
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
@ -51,7 +59,8 @@ namespace LawFirmListImplement.Models
|
|||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement
|
DateImplement = DateImplement,
|
||||||
|
ImplementerId = ImplementerId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user