6. Загружена база данных, изменены Models, дополнена BusinessLogic, добавлены Storage
This commit is contained in:
parent
d4903934ea
commit
c48df11a64
@ -52,7 +52,6 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(CaseBindingModel model)
|
public bool Create(CaseBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.BusinessLogicsContracts;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
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 CaseServiceLogic : ICaseServiceLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICaseServiceStorage _caseServiceStorage;
|
||||||
|
public CaseServiceLogic(ILogger<CaseServiceLogic> logger, ICaseServiceStorage caseServiceStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_caseServiceStorage = caseServiceStorage;
|
||||||
|
}
|
||||||
|
public List<CaseServiceViewModel>? ReadList(CaseServiceSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||||
|
var list = model == null ? _caseServiceStorage.GetFullList() : _caseServiceStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public CaseServiceViewModel? ReadElement(CaseServiceSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Id: {Id}", model.Id);
|
||||||
|
var element = _caseServiceStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement found. Id: {Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
public bool Create(CaseServiceBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_caseServiceStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(CaseServiceBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_caseServiceStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(CaseServiceBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_caseServiceStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(CaseServiceBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("CaseService. Id: {Id}", model.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,30 +21,19 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_customerStorage = customerStorage;
|
_customerStorage = customerStorage;
|
||||||
}
|
}
|
||||||
public bool Create(CustomerBindingModel model)
|
public List<CustomerViewModel>? ReadList(CustomerSearchModel? model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||||
if (_customerStorage.Insert(model) == null)
|
var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("ReadList return null list");
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
return true;
|
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
public CustomerViewModel? ReadElement(CustomerSearchModel model)
|
||||||
public bool Delete(CustomerBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model, false);
|
|
||||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
|
||||||
if (_customerStorage.Delete(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Delete operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomerViewModel ReadElement(CustomerSearchModel model)
|
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -60,7 +49,16 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ReadElement found. Id: {Id}", element.Id);
|
_logger.LogInformation("ReadElement found. Id: {Id}", element.Id);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
public bool Create(CustomerBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_customerStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
public bool Update(CustomerBindingModel model)
|
public bool Update(CustomerBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
@ -71,20 +69,17 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public bool Delete(CustomerBindingModel model)
|
||||||
public List<CustomerViewModel>? ReadList(CustomerSearchModel? model)
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
CheckModel(model, false);
|
||||||
var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model);
|
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||||
if (list == null)
|
if (_customerStorage.Delete(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadList return null list");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
return true;
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(CustomerBindingModel model, bool withParams = true)
|
private void CheckModel(CustomerBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -98,29 +93,36 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
|||||||
if (string.IsNullOrEmpty(model.Login))
|
if (string.IsNullOrEmpty(model.Login))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Login is empty");
|
_logger.LogWarning("Login is empty");
|
||||||
throw new ArgumentNullException("Не заполнен логин");
|
throw new ArgumentException("Не введён логин");
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.Name))
|
var existingCustomer = _customerStorage.GetElement(new()
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Name is empty");
|
Login = model.Login
|
||||||
throw new ArgumentNullException("Не заполнено имя");
|
});
|
||||||
}
|
if (existingCustomer != null)
|
||||||
if (string.IsNullOrEmpty(model.Surname))
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Surname is empty");
|
_logger.LogWarning("Customer with login {Login} already exists", model.Login);
|
||||||
throw new ArgumentNullException("Не заполнена фамилия");
|
throw new ArgumentException("Клиент с таким логином уже существует");
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.Password))
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Password is empty");
|
_logger.LogWarning("Password is empty");
|
||||||
throw new ArgumentNullException("Не заполнен пароль");
|
throw new ArgumentException("Не введён пароль");
|
||||||
}
|
}
|
||||||
var ExistingCustomer = _customerStorage.GetElement
|
if (model.Password.Length > 30)
|
||||||
(new CustomerSearchModel() { Login = model.Login });
|
|
||||||
if (ExistingCustomer != null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("There is already a user with this login");
|
_logger.LogWarning("Password {Password} length > 30", model.Password);
|
||||||
throw new ArgumentException("Пользователь с таким логином уже есть");
|
throw new ArgumentException("Длина пароля должна быть не больше 30 символов");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Name))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Name is empty");
|
||||||
|
throw new ArgumentException("Не введёно имя");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Surname))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Surname is empty");
|
||||||
|
throw new ArgumentException("Не введёна фамилия");
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Customer. Id: {Id}", model.Id);
|
_logger.LogInformation("Customer. Id: {Id}", model.Id);
|
||||||
}
|
}
|
||||||
|
96
LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkerLogic.cs
Normal file
96
LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkerLogic.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.BusinessLogicsContracts;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace LawFirmBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class WorkerLogic : IWorkerLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IWorkerStorage _workerStorage;
|
||||||
|
public WorkerLogic(ILogger<WorkerLogic> logger, IWorkerStorage workerStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_workerStorage = workerStorage;
|
||||||
|
}
|
||||||
|
public List<WorkerViewModel>? ReadList(WorkerSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||||
|
var list = model == null ? _workerStorage.GetFullList() : _workerStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public WorkerViewModel? ReadElement(WorkerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. Id: {Id}", model.Id);
|
||||||
|
var element = _workerStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement found. Id: {Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
public bool Create(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_workerStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_workerStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_workerStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(WorkerBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Worker. Id: {Id}", model.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
using LawFirmContracts.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class CaseServiceBindingModel : ICaseServiceModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int CaseId { get; set; }
|
||||||
|
public int ServiceId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
18
LawFirm/LawFirmContracts/BindingModels/WorkerBindingModel.cs
Normal file
18
LawFirm/LawFirmContracts/BindingModels/WorkerBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class WorkerBindingModel : IWorkerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Login { get; set; } = string.Empty;
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string Surname { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -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 ICaseServiceLogic
|
||||||
|
{
|
||||||
|
List<CaseServiceViewModel>? ReadList(CaseServiceSearchModel? model);
|
||||||
|
CaseServiceViewModel? ReadElement(CaseServiceSearchModel model);
|
||||||
|
bool Create(CaseServiceBindingModel model);
|
||||||
|
bool Update(CaseServiceBindingModel model);
|
||||||
|
bool Delete(CaseServiceBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IWorkerLogic
|
||||||
|
{
|
||||||
|
List<WorkerViewModel>? ReadList(WorkerSearchModel? model);
|
||||||
|
WorkerViewModel? ReadElement(WorkerSearchModel model);
|
||||||
|
bool Create(WorkerBindingModel model);
|
||||||
|
bool Update(WorkerBindingModel model);
|
||||||
|
bool Delete(WorkerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
21
LawFirm/LawFirmContracts/Models/ICaseServiceModel.cs
Normal file
21
LawFirm/LawFirmContracts/Models/ICaseServiceModel.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using LawFirmContracts.Id;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.Models
|
||||||
|
{
|
||||||
|
public interface ICaseServiceModel : IId
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// дела id
|
||||||
|
/// </summary>
|
||||||
|
int CaseId { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// услуги id
|
||||||
|
/// </summary>
|
||||||
|
int ServiceId { get; }
|
||||||
|
}
|
||||||
|
}
|
29
LawFirm/LawFirmContracts/Models/IWorkerModel.cs
Normal file
29
LawFirm/LawFirmContracts/Models/IWorkerModel.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.Id;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.Models
|
||||||
|
{
|
||||||
|
public interface IWorkerModel : IId
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Логин
|
||||||
|
/// </summary>
|
||||||
|
string Login { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Пароль
|
||||||
|
/// </summary>
|
||||||
|
string Password { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Имя
|
||||||
|
/// </summary>
|
||||||
|
string Name { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Фамилия
|
||||||
|
/// </summary>
|
||||||
|
string Surname { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class CaseServiceSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -10,5 +10,6 @@ namespace LawFirmContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? Login { get; set; }
|
public string? Login { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
LawFirm/LawFirmContracts/SearchModels/WorkerSearchModel.cs
Normal file
13
LawFirm/LawFirmContracts/SearchModels/WorkerSearchModel.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class WorkerSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.StorageContracts
|
||||||
|
{
|
||||||
|
public interface ICaseServiceStorage
|
||||||
|
{
|
||||||
|
List<CaseServiceViewModel> GetFullList();
|
||||||
|
List<CaseServiceViewModel> GetFilteredList(CaseServiceSearchModel model);
|
||||||
|
CaseServiceViewModel? GetElement(CaseServiceSearchModel model);
|
||||||
|
CaseServiceViewModel? Insert(CaseServiceBindingModel model);
|
||||||
|
CaseServiceViewModel? Update(CaseServiceBindingModel model);
|
||||||
|
CaseServiceViewModel? Delete(CaseServiceBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
21
LawFirm/LawFirmContracts/StorageContracts/IWorkerStorage.cs
Normal file
21
LawFirm/LawFirmContracts/StorageContracts/IWorkerStorage.cs
Normal file
@ -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.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IWorkerStorage
|
||||||
|
{
|
||||||
|
List<WorkerViewModel> GetFullList();
|
||||||
|
List<WorkerViewModel> GetFilteredList(WorkerSearchModel model);
|
||||||
|
WorkerViewModel? GetElement(WorkerSearchModel model);
|
||||||
|
WorkerViewModel? Insert(WorkerBindingModel model);
|
||||||
|
WorkerViewModel? Update(WorkerBindingModel model);
|
||||||
|
WorkerViewModel? Delete(WorkerBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
16
LawFirm/LawFirmContracts/ViewModels/CaseServiceViewModel.cs
Normal file
16
LawFirm/LawFirmContracts/ViewModels/CaseServiceViewModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using LawFirmContracts.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class CaseServiceViewModel : ICaseServiceModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int CaseId { get; set; }
|
||||||
|
public int ServiceId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
24
LawFirm/LawFirmContracts/ViewModels/WorkerViewModel.cs
Normal file
24
LawFirm/LawFirmContracts/ViewModels/WorkerViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using LawFirmContracts.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 WorkerViewModel : IWorkerModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Логин")]
|
||||||
|
public string Login { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Пароль")]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Имя")]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
|
public string Surname { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
86
LawFirm/LawFirmDatabase/Implements/CaseServiceStorage.cs
Normal file
86
LawFirm/LawFirmDatabase/Implements/CaseServiceStorage.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Implements
|
||||||
|
{
|
||||||
|
public class CaseServiceStorage : ICaseServiceStorage
|
||||||
|
{
|
||||||
|
public List<CaseServiceViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.CaseServices
|
||||||
|
.Include(x => x.Case)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<CaseServiceViewModel> GetFilteredList(CaseServiceSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.CaseServices
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Include(x => x.Case)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public CaseServiceViewModel? GetElement(CaseServiceSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.CaseServices
|
||||||
|
.Include(x => x.Case)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CaseServiceViewModel? Insert(CaseServiceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var newCaseService = CaseService.Create(context, model);
|
||||||
|
if (newCaseService != null)
|
||||||
|
{
|
||||||
|
context.CaseServices.Add(newCaseService);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newCaseService.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public CaseServiceViewModel? Update(CaseServiceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var CaseService = context.CaseServices.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (CaseService == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CaseService.Update(context, model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return CaseService.GetViewModel;
|
||||||
|
}
|
||||||
|
public CaseServiceViewModel? Delete(CaseServiceBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var CaseService = context.CaseServices.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (CaseService == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.CaseServices.Remove(CaseService);
|
||||||
|
context.SaveChanges();
|
||||||
|
return CaseService.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,23 +16,38 @@ namespace LawFirmDatabase.Implements
|
|||||||
public List<CustomerViewModel> GetFullList()
|
public List<CustomerViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
return context.Customers.Select(x => x.GetViewModel).ToList();
|
return context.Customers
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
public List<CustomerViewModel> GetFilteredList(CustomerSearchModel model)
|
public List<CustomerViewModel> GetFilteredList(CustomerSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
return context.Customers.Select(x => x.GetViewModel).Where(x => x.Id == model.Id).ToList();
|
return context.Customers
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
public CustomerViewModel? GetElement(CustomerSearchModel model)
|
public CustomerViewModel? GetElement(CustomerSearchModel model)
|
||||||
{
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
if (model.Id.HasValue)
|
if (model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return context.Customers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
return context.Customers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrEmpty(model.Login))
|
else if (!string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))
|
||||||
{
|
{
|
||||||
return context.Customers.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel;
|
return context.Customers
|
||||||
|
.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel;
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
return context.Customers
|
||||||
|
.FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password)?.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -51,7 +66,8 @@ namespace LawFirmDatabase.Implements
|
|||||||
public CustomerViewModel? Update(CustomerBindingModel model)
|
public CustomerViewModel? Update(CustomerBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
var customer = context.Customers.FirstOrDefault(x => x.Id == model.Id);
|
var customer = context.Customers
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (customer == null)
|
if (customer == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@ -63,7 +79,8 @@ namespace LawFirmDatabase.Implements
|
|||||||
public CustomerViewModel? Delete(CustomerBindingModel model)
|
public CustomerViewModel? Delete(CustomerBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
var customer = context.Customers.FirstOrDefault(x => x.Id == model.Id);
|
var customer = context.Customers
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (customer == null)
|
if (customer == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -18,12 +18,12 @@ namespace LawFirmDatabase.Implements
|
|||||||
public List<ItemViewModel> GetFullList()
|
public List<ItemViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
return context.Items.Include(x => x.Services).Select(x => x.GetViewModel).ToList();
|
return context.Items.Include(x => x.Payment).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
public List<ItemViewModel> GetFilteredList(ItemSearchModel model)
|
public List<ItemViewModel> GetFilteredList(ItemSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
return context.Items.Where(x => x.Id == model.Id).Include(x => x.Services).Select(x => x.GetViewModel).ToList();
|
return context.Items.Where(x => x.Id == model.Id).Include(x => x.Payment).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
public ItemViewModel? GetElement(ItemSearchModel model)
|
public ItemViewModel? GetElement(ItemSearchModel model)
|
||||||
{
|
{
|
||||||
@ -34,11 +34,11 @@ namespace LawFirmDatabase.Implements
|
|||||||
using var context = new LawFirmDBContext();
|
using var context = new LawFirmDBContext();
|
||||||
if (model.Id.HasValue)
|
if (model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return context.Items.Include(x => x.Services).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
return context.Items.Include(x => x.Payment).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(model.Name))
|
if (!string.IsNullOrEmpty(model.Name))
|
||||||
{
|
{
|
||||||
return context.Items.Include(x => x.Services).FirstOrDefault(x => x.Name == model.Name)?.GetViewModel;
|
return context.Items.Include(x => x.Payment).FirstOrDefault(x => x.Name == model.Name)?.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
84
LawFirm/LawFirmDatabase/Implements/WorkerStorage.cs
Normal file
84
LawFirm/LawFirmDatabase/Implements/WorkerStorage.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmDatabase.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Implements
|
||||||
|
{
|
||||||
|
public class WorkerStorage : IWorkerStorage
|
||||||
|
{
|
||||||
|
public List<WorkerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Workers
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public List<WorkerViewModel> GetFilteredList(WorkerSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
return context.Workers
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public WorkerViewModel? GetElement(WorkerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Workers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
//другие варианты поиска не реализуются (заглушка для роли Worker)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public WorkerViewModel? Insert(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var newWorker = Worker.Create(model);
|
||||||
|
if (newWorker != null)
|
||||||
|
{
|
||||||
|
context.Workers.Add(newWorker);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newWorker.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public WorkerViewModel? Update(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var worker = context.Workers
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (worker == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
worker.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return worker.GetViewModel;
|
||||||
|
}
|
||||||
|
public WorkerViewModel? Delete(WorkerBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new LawFirmDBContext();
|
||||||
|
var worker = context.Workers
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (worker == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Workers.Remove(worker);
|
||||||
|
context.SaveChanges();
|
||||||
|
return worker.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,9 +26,11 @@ namespace LawFirmDatabase
|
|||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
public virtual DbSet<Customer> Customers { get; set; }
|
public virtual DbSet<Customer> Customers { get; set; }
|
||||||
|
public virtual DbSet<Worker> Workers { get; set; }
|
||||||
public virtual DbSet<Item> Items { get; set; }
|
public virtual DbSet<Item> Items { get; set; }
|
||||||
public virtual DbSet<Case> Cases { get; set; }
|
public virtual DbSet<Case> Cases { get; set; }
|
||||||
public virtual DbSet<Payment> Payments { get; set; }
|
public virtual DbSet<Payment> Payments { get; set; }
|
||||||
public virtual DbSet<Service> Services { get; set; }
|
public virtual DbSet<Service> Services { get; set; }
|
||||||
|
public virtual DbSet<CaseService> CaseServices { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
using LawFirmDatabase;
|
using LawFirmDatabase;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
@ -11,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace LawFirmDatabase.Migrations
|
namespace LawFirmDatabase.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(LawFirmDBContext))]
|
[DbContext(typeof(LawFirmDBContext))]
|
||||||
[Migration("20230408032638_InitMigration")]
|
[Migration("20230408133321_InitialCreate")]
|
||||||
partial class InitMigration
|
partial class InitialCreate
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -32,20 +33,52 @@ namespace LawFirmDatabase.Migrations
|
|||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CustomerId")
|
b.Property<int>("CustomerId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int?>("WorkerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CustomerId");
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.HasIndex("WorkerId");
|
||||||
|
|
||||||
b.ToTable("Cases");
|
b.ToTable("Cases");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.CaseService", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ServiceId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.ToTable("CaseServices");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -83,6 +116,9 @@ namespace LawFirmDatabase.Migrations
|
|||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ItemId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
@ -95,7 +131,7 @@ namespace LawFirmDatabase.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("PaymentId");
|
b.HasIndex("ItemId");
|
||||||
|
|
||||||
b.ToTable("Items");
|
b.ToTable("Items");
|
||||||
});
|
});
|
||||||
@ -111,8 +147,11 @@ namespace LawFirmDatabase.Migrations
|
|||||||
b.Property<int>("CaseId")
|
b.Property<int>("CaseId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DatePayment")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
b.Property<decimal>("Sum")
|
b.Property<decimal>("Sum")
|
||||||
.HasColumnType("decimal (10,2)");
|
.HasColumnType("decimal (15,2)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -140,72 +179,106 @@ namespace LawFirmDatabase.Migrations
|
|||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<decimal>("Price")
|
b.Property<decimal>("Price")
|
||||||
.HasColumnType("decimal (10,2)");
|
.HasColumnType("decimal (15,2)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CaseId");
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
b.HasIndex("ItemId");
|
|
||||||
|
|
||||||
b.ToTable("Services");
|
b.ToTable("Services");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Worker", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Login")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Workers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("LawFirmDatabase.Models.Customer", "Customer")
|
b.HasOne("LawFirmDatabase.Models.Customer", "Customer")
|
||||||
.WithMany("Cases")
|
.WithMany("Cases")
|
||||||
.HasForeignKey("CustomerId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Customer");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("LawFirmDatabase.Models.Payment", "Payments")
|
|
||||||
.WithMany("Items")
|
|
||||||
.HasForeignKey("PaymentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Payments");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
|
||||||
.WithMany("Payments")
|
|
||||||
.HasForeignKey("CaseId")
|
.HasForeignKey("CaseId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Cases");
|
b.HasOne("LawFirmDatabase.Models.Worker", null)
|
||||||
|
.WithMany("Cases")
|
||||||
|
.HasForeignKey("WorkerId");
|
||||||
|
|
||||||
|
b.Navigation("Customer");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.CaseService", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
b.HasOne("LawFirmDatabase.Models.Case", "Case")
|
||||||
|
.WithMany("CaseServices")
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Case");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Payment", "Payment")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ItemId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Payment");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Case")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("CaseId")
|
.HasForeignKey("CaseId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("LawFirmDatabase.Models.Item", "Items")
|
b.Navigation("Case");
|
||||||
.WithMany("Services")
|
});
|
||||||
.HasForeignKey("ItemId")
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Case")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Cases");
|
b.Navigation("Case");
|
||||||
|
|
||||||
b.Navigation("Items");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Payments");
|
b.Navigation("CaseServices");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
@ -213,14 +286,9 @@ namespace LawFirmDatabase.Migrations
|
|||||||
b.Navigation("Cases");
|
b.Navigation("Cases");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Worker", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Services");
|
b.Navigation("Cases");
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Items");
|
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
@ -1,11 +1,12 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
namespace LawFirmDatabase.Migrations
|
namespace LawFirmDatabase.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class InitMigration : Migration
|
public partial class InitialCreate : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
@ -26,24 +27,68 @@ namespace LawFirmDatabase.Migrations
|
|||||||
table.PrimaryKey("PK_Customers", x => x.Id);
|
table.PrimaryKey("PK_Customers", x => x.Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Workers",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Surname = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Workers", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Cases",
|
name: "Cases",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
DateCreated = table.Column<DateTime>(type: "date", nullable: false),
|
||||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
CustomerId = table.Column<int>(type: "int", nullable: false)
|
CustomerId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
CaseId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
WorkerId = table.Column<int>(type: "int", nullable: true)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Cases", x => x.Id);
|
table.PrimaryKey("PK_Cases", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Cases_Customers_CustomerId",
|
name: "FK_Cases_Customers_CaseId",
|
||||||
column: x => x.CustomerId,
|
column: x => x.CaseId,
|
||||||
principalTable: "Customers",
|
principalTable: "Customers",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Cases_Workers_WorkerId",
|
||||||
|
column: x => x.WorkerId,
|
||||||
|
principalTable: "Workers",
|
||||||
|
principalColumn: "Id");
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "CaseServices",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
CaseId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ServiceId = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_CaseServices", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_CaseServices_Cases_CaseId",
|
||||||
|
column: x => x.CaseId,
|
||||||
|
principalTable: "Cases",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
@ -52,7 +97,8 @@ namespace LawFirmDatabase.Migrations
|
|||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
Sum = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
DatePayment = table.Column<DateTime>(type: "date", nullable: false),
|
||||||
|
Sum = table.Column<decimal>(type: "decimal (15,2)", nullable: false),
|
||||||
CaseId = table.Column<int>(type: "int", nullable: false)
|
CaseId = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
@ -66,27 +112,6 @@ namespace LawFirmDatabase.Migrations
|
|||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Items",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Price = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
|
||||||
PaymentId = table.Column<int>(type: "int", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Items", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Items_Payments_PaymentId",
|
|
||||||
column: x => x.PaymentId,
|
|
||||||
principalTable: "Payments",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Services",
|
name: "Services",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -94,7 +119,7 @@ namespace LawFirmDatabase.Migrations
|
|||||||
Id = table.Column<int>(type: "int", nullable: false)
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
Price = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
Price = table.Column<decimal>(type: "decimal (15,2)", nullable: false),
|
||||||
ItemId = table.Column<int>(type: "int", nullable: false),
|
ItemId = table.Column<int>(type: "int", nullable: false),
|
||||||
CaseId = table.Column<int>(type: "int", nullable: false)
|
CaseId = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
@ -107,23 +132,49 @@ namespace LawFirmDatabase.Migrations
|
|||||||
principalTable: "Cases",
|
principalTable: "Cases",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Items",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<decimal>(type: "decimal (10,2)", nullable: false),
|
||||||
|
PaymentId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ItemId = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Items", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Services_Items_ItemId",
|
name: "FK_Items_Payments_ItemId",
|
||||||
column: x => x.ItemId,
|
column: x => x.ItemId,
|
||||||
principalTable: "Items",
|
principalTable: "Payments",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Cases_CustomerId",
|
name: "IX_Cases_CaseId",
|
||||||
table: "Cases",
|
table: "Cases",
|
||||||
column: "CustomerId");
|
column: "CaseId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Items_PaymentId",
|
name: "IX_Cases_WorkerId",
|
||||||
|
table: "Cases",
|
||||||
|
column: "WorkerId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_CaseServices_CaseId",
|
||||||
|
table: "CaseServices",
|
||||||
|
column: "CaseId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Items_ItemId",
|
||||||
table: "Items",
|
table: "Items",
|
||||||
column: "PaymentId");
|
column: "ItemId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Payments_CaseId",
|
name: "IX_Payments_CaseId",
|
||||||
@ -134,22 +185,20 @@ namespace LawFirmDatabase.Migrations
|
|||||||
name: "IX_Services_CaseId",
|
name: "IX_Services_CaseId",
|
||||||
table: "Services",
|
table: "Services",
|
||||||
column: "CaseId");
|
column: "CaseId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Services_ItemId",
|
|
||||||
table: "Services",
|
|
||||||
column: "ItemId");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Services");
|
name: "CaseServices");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Items");
|
name: "Items");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Services");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Payments");
|
name: "Payments");
|
||||||
|
|
||||||
@ -158,6 +207,9 @@ namespace LawFirmDatabase.Migrations
|
|||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Customers");
|
name: "Customers");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Workers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
using LawFirmDatabase;
|
using LawFirmDatabase;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
@ -29,20 +30,52 @@ namespace LawFirmDatabase.Migrations
|
|||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("CustomerId")
|
b.Property<int>("CustomerId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreated")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int?>("WorkerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CustomerId");
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.HasIndex("WorkerId");
|
||||||
|
|
||||||
b.ToTable("Cases");
|
b.ToTable("Cases");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.CaseService", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("CaseId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ServiceId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
|
b.ToTable("CaseServices");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -80,6 +113,9 @@ namespace LawFirmDatabase.Migrations
|
|||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ItemId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
@ -92,7 +128,7 @@ namespace LawFirmDatabase.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("PaymentId");
|
b.HasIndex("ItemId");
|
||||||
|
|
||||||
b.ToTable("Items");
|
b.ToTable("Items");
|
||||||
});
|
});
|
||||||
@ -108,8 +144,11 @@ namespace LawFirmDatabase.Migrations
|
|||||||
b.Property<int>("CaseId")
|
b.Property<int>("CaseId")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DatePayment")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
b.Property<decimal>("Sum")
|
b.Property<decimal>("Sum")
|
||||||
.HasColumnType("decimal (10,2)");
|
.HasColumnType("decimal (15,2)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@ -137,72 +176,106 @@ namespace LawFirmDatabase.Migrations
|
|||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<decimal>("Price")
|
b.Property<decimal>("Price")
|
||||||
.HasColumnType("decimal (10,2)");
|
.HasColumnType("decimal (15,2)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("CaseId");
|
b.HasIndex("CaseId");
|
||||||
|
|
||||||
b.HasIndex("ItemId");
|
|
||||||
|
|
||||||
b.ToTable("Services");
|
b.ToTable("Services");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Worker", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Login")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Workers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("LawFirmDatabase.Models.Customer", "Customer")
|
b.HasOne("LawFirmDatabase.Models.Customer", "Customer")
|
||||||
.WithMany("Cases")
|
.WithMany("Cases")
|
||||||
.HasForeignKey("CustomerId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Customer");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("LawFirmDatabase.Models.Payment", "Payments")
|
|
||||||
.WithMany("Items")
|
|
||||||
.HasForeignKey("PaymentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Payments");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
|
||||||
.WithMany("Payments")
|
|
||||||
.HasForeignKey("CaseId")
|
.HasForeignKey("CaseId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Cases");
|
b.HasOne("LawFirmDatabase.Models.Worker", null)
|
||||||
|
.WithMany("Cases")
|
||||||
|
.HasForeignKey("WorkerId");
|
||||||
|
|
||||||
|
b.Navigation("Customer");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.CaseService", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("LawFirmDatabase.Models.Case", "Cases")
|
b.HasOne("LawFirmDatabase.Models.Case", "Case")
|
||||||
|
.WithMany("CaseServices")
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Case");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Payment", "Payment")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ItemId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Payment");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Case")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("CaseId")
|
.HasForeignKey("CaseId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("LawFirmDatabase.Models.Item", "Items")
|
b.Navigation("Case");
|
||||||
.WithMany("Services")
|
});
|
||||||
.HasForeignKey("ItemId")
|
|
||||||
|
modelBuilder.Entity("LawFirmDatabase.Models.Service", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("LawFirmDatabase.Models.Case", "Case")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CaseId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Cases");
|
b.Navigation("Case");
|
||||||
|
|
||||||
b.Navigation("Items");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Case", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Payments");
|
b.Navigation("CaseServices");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Customer", b =>
|
||||||
@ -210,14 +283,9 @@ namespace LawFirmDatabase.Migrations
|
|||||||
b.Navigation("Cases");
|
b.Navigation("Cases");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Item", b =>
|
modelBuilder.Entity("LawFirmDatabase.Models.Worker", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Services");
|
b.Navigation("Cases");
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("LawFirmDatabase.Models.Payment", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Items");
|
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,17 @@ namespace LawFirmDatabase.Models
|
|||||||
{
|
{
|
||||||
public class Case : ICaseModel
|
public class Case : ICaseModel
|
||||||
{
|
{
|
||||||
|
[Required, Column(TypeName = "date")]
|
||||||
|
public DateTime DateCreated { get; private set; } = DateTime.Now;
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
[NotMapped]
|
|
||||||
public DateTime DateCreated { get; private set; }
|
|
||||||
[Required]
|
[Required]
|
||||||
public int CustomerId { get; private set; }
|
public int CustomerId { get; private set; }
|
||||||
[ForeignKey("CaseId")]
|
[ForeignKey("CaseId")]
|
||||||
public virtual List<Payment> Payments { get; set; } = new();
|
public virtual List<CaseService> CaseServices { get; set; } = new();
|
||||||
public virtual Customer Customer { get; set; } = new();
|
public virtual Customer Customer { get; set; } = new();
|
||||||
public static Case? Create(LawFirmDBContext context, ICaseModel? model)
|
public static Case? Create(LawFirmDBContext context, CaseBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -35,24 +35,24 @@ namespace LawFirmDatabase.Models
|
|||||||
}
|
}
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Name= model.Name,
|
||||||
DateCreated = model.DateCreated,
|
DateCreated = model.DateCreated,
|
||||||
Customer = context.Customers.First(x => x.Id == model.CustomerId)
|
Customer = context.Customers.First(x => x.Id == model.CustomerId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public void Update(LawFirmDBContext context, CaseBindingModel? model)
|
||||||
public void Update(LawFirmDBContext context, ICaseModel? model)
|
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Id = model.Id;
|
Name = model.Name;
|
||||||
DateCreated = model.DateCreated;
|
DateCreated = model.DateCreated;
|
||||||
Customer = context.Customers.First(x => x.Id == model.CustomerId);
|
Customer = context.Customers.First(x => x.Id == model.CustomerId);
|
||||||
}
|
|
||||||
|
|
||||||
public CaseViewModel? GetViewModel => new()
|
|
||||||
|
}
|
||||||
|
public CaseViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Name= Name,
|
Name= Name,
|
||||||
|
50
LawFirm/LawFirmDatabase/Models/CaseService.cs
Normal file
50
LawFirm/LawFirmDatabase/Models/CaseService.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Models
|
||||||
|
{
|
||||||
|
public class CaseService : ICaseServiceModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int CaseId { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public int ServiceId { get; private set; }
|
||||||
|
public virtual Case Case { get; set; } = new();
|
||||||
|
public static CaseService? Create(LawFirmDBContext context, ICaseServiceModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
|
||||||
|
Case = context.Cases.First(x => x.Id == model.CaseId),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(LawFirmDBContext context, ICaseServiceModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Case = context.Cases.First(x => x.Id == model.CaseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CaseServiceViewModel? GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
CaseId = CaseId,
|
||||||
|
ServiceId = ServiceId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -24,9 +24,10 @@ namespace LawFirmDatabase.Models
|
|||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Surname { get; private set; } = string.Empty;
|
public string Surname { get; private set; } = string.Empty;
|
||||||
[ForeignKey("CustomerId")]
|
|
||||||
|
[ForeignKey("CaseId")]
|
||||||
public virtual List<Case> Cases { get; set; } = new();
|
public virtual List<Case> Cases { get; set; } = new();
|
||||||
public static Customer? Create(ICustomerModel? model)
|
public static Customer? Create(CustomerBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -38,29 +39,28 @@ namespace LawFirmDatabase.Models
|
|||||||
Login = model.Login,
|
Login = model.Login,
|
||||||
Password = model.Password,
|
Password = model.Password,
|
||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
Surname = model.Surname,
|
Surname = model.Surname
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public void Update(CustomerBindingModel? model)
|
||||||
public void Update(ICustomerModel? model)
|
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Id = model.Id;
|
||||||
Login = model.Login;
|
Login = model.Login;
|
||||||
Password = model.Password;
|
Password = model.Password;
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
Surname = model.Surname;
|
Surname = model.Surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomerViewModel GetViewModel => new()
|
public CustomerViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Login = Login,
|
Login = Login,
|
||||||
Password = Password,
|
Password = Password,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Surname = Surname
|
Surname = Surname,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ namespace LawFirmDatabase.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public int PaymentId { get; private set; }
|
public int PaymentId { get; private set; }
|
||||||
[ForeignKey("ItemId")]
|
[ForeignKey("ItemId")]
|
||||||
public virtual List<Service> Services { get; set; } = new();
|
public virtual Payment Payment { get; set; } = new();
|
||||||
public virtual Payment Payments { get; set; } = new();
|
|
||||||
public static Item? Create(LawFirmDBContext context, ItemBindingModel? model)
|
public static Item? Create(LawFirmDBContext context, ItemBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -31,7 +30,7 @@ namespace LawFirmDatabase.Models
|
|||||||
{
|
{
|
||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
Price = model.Price,
|
Price = model.Price,
|
||||||
Payments = context.Payments.First(x => x.Id == model.PaymentId)
|
Payment = context.Payments.First(x => x.Id == model.PaymentId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(LawFirmDBContext context, ItemBindingModel? model)
|
public void Update(LawFirmDBContext context, ItemBindingModel? model)
|
||||||
@ -42,14 +41,14 @@ namespace LawFirmDatabase.Models
|
|||||||
}
|
}
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
Payments = context.Payments.First(x => x.Id == model.PaymentId);
|
Payment = context.Payments.First(x => x.Id == model.PaymentId);
|
||||||
}
|
}
|
||||||
public ItemViewModel GetViewModel => new()
|
public ItemViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Price = Price,
|
Price = Price,
|
||||||
PaymentId = PaymentId,
|
PaymentId = PaymentId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,15 +16,13 @@ namespace LawFirmDatabase.Models
|
|||||||
public class Payment : IPaymentModel
|
public class Payment : IPaymentModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[NotMapped]
|
[Required, Column(TypeName = "date")]
|
||||||
public DateTime DatePayment { get; private set; } = DateTime.Now;
|
public DateTime DatePayment { get; private set; } = DateTime.Now;
|
||||||
[Required, Column(TypeName = "decimal (10,2)")]
|
[Required, Column(TypeName = "decimal (15,2)")]
|
||||||
public decimal Sum { get; private set; }
|
public decimal Sum { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int CaseId { get; private set; }
|
public int CaseId { get; private set; }
|
||||||
[ForeignKey("PaymentId")]
|
public virtual Case Case { get; set; } = new();
|
||||||
public virtual List<Item> Items { get; set; } = new();
|
|
||||||
public virtual Case Cases { get; set; } = new();
|
|
||||||
|
|
||||||
public static Payment? Create(LawFirmDBContext context, IPaymentModel? model)
|
public static Payment? Create(LawFirmDBContext context, IPaymentModel? model)
|
||||||
{
|
{
|
||||||
@ -35,9 +33,9 @@ namespace LawFirmDatabase.Models
|
|||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Sum = model.Sum,
|
|
||||||
DatePayment = model.DatePayment,
|
DatePayment = model.DatePayment,
|
||||||
Cases = context.Cases.First(x => x.Id == model.CaseId)
|
Sum = model.Sum,
|
||||||
|
Case = context.Cases.First(x => x.Id == model.CaseId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,16 +46,16 @@ namespace LawFirmDatabase.Models
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Id = model.Id;
|
Id = model.Id;
|
||||||
Sum = model.Sum;
|
|
||||||
DatePayment = model.DatePayment;
|
DatePayment = model.DatePayment;
|
||||||
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
Sum = model.Sum;
|
||||||
|
Case = context.Cases.First(x => x.Id == model.CaseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaymentViewModel? GetViewModel => new()
|
public PaymentViewModel? GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Sum = Sum,
|
|
||||||
DatePayment = DatePayment,
|
DatePayment = DatePayment,
|
||||||
|
Sum = Sum,
|
||||||
CaseId = CaseId,
|
CaseId = CaseId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ namespace LawFirmDatabase.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
[Required, Column(TypeName = "decimal (10,2)")]
|
[Required, Column(TypeName = "decimal (15,2)")]
|
||||||
public decimal Price { get; private set; }
|
public decimal Price { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int ItemId { get; private set; }
|
public int ItemId { get; private set; }
|
||||||
|
[Required]
|
||||||
public int CaseId { get; private set; }
|
public int CaseId { get; private set; }
|
||||||
public virtual Item Items { get; set; } = new();
|
public virtual Case Case { get; set; } = new();
|
||||||
public virtual Case Cases { get; set; } = new();
|
|
||||||
|
|
||||||
public static Service? Create(LawFirmDBContext context, IServiceModel? model)
|
public static Service? Create(LawFirmDBContext context, IServiceModel? model)
|
||||||
{
|
{
|
||||||
@ -36,8 +36,7 @@ namespace LawFirmDatabase.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Name = model.Name,
|
Name = model.Name,
|
||||||
Price = model.Price,
|
Price = model.Price,
|
||||||
Items = context.Items.First(x => x.Id == model.ItemId),
|
Case = context.Cases.First(x => x.Id == model.CaseId)
|
||||||
Cases = context.Cases.First(x => x.Id == model.CaseId)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,16 +49,14 @@ namespace LawFirmDatabase.Models
|
|||||||
Id = model.Id;
|
Id = model.Id;
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
Items = context.Items.First(x => x.Id == model.ItemId);
|
Case = context.Cases.First(x => x.Id == model.CaseId);
|
||||||
Cases = context.Cases.First(x => x.Id == model.CaseId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceViewModel? GetViewModel => new()
|
public ServiceViewModel? GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Price = Price,
|
Price = Price
|
||||||
ItemId = ItemId,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
65
LawFirm/LawFirmDatabase/Models/Worker.cs
Normal file
65
LawFirm/LawFirmDatabase/Models/Worker.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.Models;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Azure;
|
||||||
|
|
||||||
|
namespace LawFirmDatabase.Models
|
||||||
|
{
|
||||||
|
public class Worker : IWorkerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string Login { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public string Surname { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
[ForeignKey("WorkerId")]
|
||||||
|
public virtual List<Case> Cases { get; set; } = new();
|
||||||
|
public static Worker? Create(WorkerBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Login = model.Login,
|
||||||
|
Password = model.Password,
|
||||||
|
Name = model.Name,
|
||||||
|
Surname = model.Surname
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(WorkerBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Id = model.Id;
|
||||||
|
Login = model.Login;
|
||||||
|
Password = model.Password;
|
||||||
|
Name = model.Name;
|
||||||
|
Surname = model.Surname;
|
||||||
|
}
|
||||||
|
public WorkerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Login = Login,
|
||||||
|
Password = Password,
|
||||||
|
Name = Name,
|
||||||
|
Surname = Surname
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user