правки

This commit is contained in:
Софья Якобчук 2024-05-01 23:48:28 +04:00
parent 65decf8f3f
commit 0e7a46e2e1
28 changed files with 725 additions and 770 deletions

View File

@ -142,8 +142,6 @@ namespace LawCompanyBusinessLogic.BusinessLogics
FIO = model.FIO,
Phone = model.Phone,
Email = model.Email,
ExecutorId = model.ExecutorId,
});
if (element != null && element.Id != model.Id)
{

View File

@ -1,140 +1,140 @@
using LawCompanyContracts.BindingModels;
using LawCompanyDataModels.Models;
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.BusinessLogicContracts;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using LawCompanyDataModels.Models;
using Microsoft.Extensions.Logging;
namespace LawCompanyBusinessLogic.BusinessLogics
{
public class ConsultationLogic : IConsultationLogic
{
private readonly ILogger _logger;
private readonly IConsultationStorage _consultationStorage;
public class ConsultationLogic : IConsultationLogic
{
private readonly ILogger _logger;
private readonly IConsultationStorage _consultationStorage;
public ConsultationLogic(ILogger<ConsultationLogic> logger, IConsultationStorage consultationStorage)
{
_logger = logger;
_consultationStorage = consultationStorage;
}
public ConsultationLogic(ILogger<ConsultationLogic> logger, IConsultationStorage consultationStorage)
{
_logger = logger;
_consultationStorage = consultationStorage;
}
public bool Create(ConsultationBindingModel model)
{
CheckModel(model);
if (_consultationStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Create(ConsultationBindingModel model)
{
CheckModel(model);
if (_consultationStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ConsultationBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_consultationStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Delete(ConsultationBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_consultationStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ConsultationViewModel? ReadElement(ConsultationSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ConsultationDate:{ConsultationDate}. Id:{Id}", model.ConsultationDate, model.Id);
var element = _consultationStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public ConsultationViewModel? ReadElement(ConsultationSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ConsultationDate:{ConsultationDate}. Id:{Id}", model.ConsultationDate, model.Id);
var element = _consultationStorage.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<ConsultationViewModel>? ReadList(ConsultationSearchModel? model)
{
_logger.LogInformation("ReadList. ConsultationDate:{ConsultationDate}.Id:{Id}", model?.ConsultationDate, model?.Id);
var list = model == null ? _consultationStorage.GetFullList() : _consultationStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public List<ConsultationViewModel>? ReadList(ConsultationSearchModel? model)
{
_logger.LogInformation("ReadList. ConsultationDate:{ConsultationDate}.Id:{Id}", model?.ConsultationDate, model?.Id);
var list = model == null ? _consultationStorage.GetFullList() : _consultationStorage.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(ConsultationBindingModel model)
{
CheckModel(model);
if (_consultationStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
public bool Update(ConsultationBindingModel model)
{
CheckModel(model);
if (_consultationStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _consultationStorage.GetElement(model);
var element = _consultationStorage.GetElement(model);
if (element == null)
{
return false;
}
if (element == null)
{
return false;
}
element.ConsultationLawyers[lawyer.Id] = lawyer;
element.ConsultationLawyers[lawyer.Id] = lawyer;
_consultationStorage.Update(new()
{
Id = element.Id,
Cost = element.Cost,
ConsultationDate = element.ConsultationDate,
CaseId = element.CaseId,
ConsultationLawyers = element.ConsultationLawyers,
GuarantorId = element.GuarantorId,
});
_consultationStorage.Update(new()
{
Id = element.Id,
Cost = element.Cost,
ConsultationDate = element.ConsultationDate,
CaseId = element.CaseId,
ConsultationLawyers = element.ConsultationLawyers,
GuarantorId = element.GuarantorId,
});
return true;
}
private void CheckModel(ConsultationBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty((model.ConsultationDate).ToString()))
{
throw new ArgumentNullException("Не поставлено время", nameof(model.ConsultationDate));
}
return true;
}
private void CheckModel(ConsultationBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty((model.ConsultationDate).ToString()))
{
throw new ArgumentNullException("Не поставлено время", nameof(model.ConsultationDate));
}
_logger.LogInformation("Consultation. ConsultationDate:{ConsultationDate}. Id: {Id} ", model.ConsultationDate, model.Id);
var element = _consultationStorage.GetElement(new ConsultationSearchModel
{
ConsultationDate = model.ConsultationDate
_logger.LogInformation("Consultation. ConsultationDate:{ConsultationDate}. Id: {Id} ", model.ConsultationDate, model.Id);
var element = _consultationStorage.GetElement(new ConsultationSearchModel
{
ConsultationDate = model.ConsultationDate
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("На данное время уже назначена консультация");
}
}
}
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("На данное время уже назначена консультация");
}
}
}
}

View File

@ -17,7 +17,7 @@ namespace LawCompanyBusinessLogic.BusinessLogics
private readonly ILogger _logger;
private readonly IExecutorStorage _executorStorage;
public ExecutorLogic(ILogger logger, IExecutorStorage executorStorage)
public ExecutorLogic(ILogger<ExecutorLogic> logger, IExecutorStorage executorStorage)
{
_logger = logger;
_executorStorage = executorStorage;
@ -119,8 +119,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Исполнитель с такими данными уже есть");
}
}
throw new InvalidOperationException("Исполнитель с такими данными уже есть");
}
}
}
}

View File

@ -7,115 +7,115 @@ using Microsoft.Extensions.Logging;
namespace LawCompanyBusinessLogic.BusinessLogics
{
public class GuarantorLogic : IGuarantorLogic
{
private readonly ILogger _logger;
private readonly IGuarantorStorage _guarantorStorage;
public class GuarantorLogic : IGuarantorLogic
{
private readonly ILogger _logger;
private readonly IGuarantorStorage _guarantorStorage;
public GuarantorLogic(ILogger logger, IGuarantorStorage guarantorStorage)
{
_logger = logger;
_guarantorStorage = guarantorStorage;
}
public GuarantorLogic(ILogger<GuarantorLogic> logger, IGuarantorStorage guarantorStorage)
{
_logger = logger;
_guarantorStorage = guarantorStorage;
}
public bool Create(GuarantorBindingModel model)
{
CheckModel(model);
if (_guarantorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Create(GuarantorBindingModel model)
{
CheckModel(model);
if (_guarantorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(GuarantorBindingModel model)
{
CheckModel(model);
if (_guarantorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Update(GuarantorBindingModel model)
{
CheckModel(model);
if (_guarantorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(GuarantorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_guarantorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Delete(GuarantorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_guarantorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<GuarantorViewModel>? ReadList(GuarantorSearchModel? model)
{
_logger.LogInformation("ReadList. GuarantorName:{GuarantorName}.Id:{Id}", model?.FIO, model?.Id);
var list = model == null ? _guarantorStorage.GetFullList() : _guarantorStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public List<GuarantorViewModel>? ReadList(GuarantorSearchModel? model)
{
_logger.LogInformation("ReadList. GuarantorName:{GuarantorName}.Id:{Id}", model?.FIO, model?.Id);
var list = model == null ? _guarantorStorage.GetFullList() : _guarantorStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public GuarantorViewModel? ReadElement(GuarantorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. GuarantorName:{GuarantorName}. Id:{Id}", model.FIO, model.Id);
var element = _guarantorStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public GuarantorViewModel? ReadElement(GuarantorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. GuarantorName:{GuarantorName}. Id:{Id}", model.FIO, model.Id);
var element = _guarantorStorage.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(GuarantorBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FIO))
{
throw new ArgumentNullException("Нет имени поручителя", nameof(model.FIO));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет e-mail поручителя", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля поручителя", nameof(model.Password));
}
private void CheckModel(GuarantorBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FIO))
{
throw new ArgumentNullException("Нет имени поручителя", nameof(model.FIO));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет e-mail поручителя", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля поручителя", nameof(model.Password));
}
_logger.LogInformation("Guarantor. GuarantorName:{FIO}. E-mail:{Email}. Password: {Password} Id: {Id} ", model.FIO, model.Email, model.Password, model.Id);
var element = _guarantorStorage.GetElement(new GuarantorSearchModel
{
FIO = model.FIO,
Email = model.Email,
Password = model.Password,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Поручитель с такими данными уже есть");
}
}
}
_logger.LogInformation("Guarantor. GuarantorName:{FIO}. E-mail:{Email}. Password: {Password} Id: {Id} ", model.FIO, model.Email, model.Password, model.Id);
var element = _guarantorStorage.GetElement(new GuarantorSearchModel
{
FIO = model.FIO,
Email = model.Email,
Password = model.Password,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Поручитель с такими данными уже есть");
}
}
}
}

View File

@ -7,148 +7,147 @@ using Microsoft.Extensions.Logging;
namespace LawCompanyBusinessLogic.BusinessLogics
{
public class LawyerLogic : ILawyerLogic
{
private readonly ILogger _logger;
private readonly ILawyerStorage _lawyerStorage;
public class LawyerLogic : ILawyerLogic
{
private readonly ILogger _logger;
private readonly ILawyerStorage _lawyerStorage;
public LawyerLogic(ILogger<LawyerLogic> logger, ILawyerStorage lawyerStorage)
{
_logger = logger;
_lawyerStorage = lawyerStorage;
}
public LawyerLogic(ILogger<LawyerLogic> logger, ILawyerStorage lawyerStorage)
{
_logger = logger;
_lawyerStorage = lawyerStorage;
}
public bool Create(LawyerBindingModel model)
{
CheckModel(model);
if (_lawyerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Create(LawyerBindingModel model)
{
CheckModel(model);
if (_lawyerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(LawyerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_lawyerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Delete(LawyerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_lawyerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<LawyerViewModel>? ReadHearingElementList(HearingSearchModel? model)
{
if (model == null)
{
return null;
}
var list = _lawyerStorage.GetLawyerHearingList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public List<LawyerViewModel>? ReadHearingElementList(HearingSearchModel? model)
{
if (model == null)
{
return null;
}
var list = _lawyerStorage.GetLawyerHearingList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public List<LawyerViewModel>? ReadConsultationElementList(ConsultationSearchModel? model)
{
if (model == null)
{
return null;
}
var list = _lawyerStorage.GetLawyerConsultationList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public List<LawyerViewModel>? ReadConsultationElementList(ConsultationSearchModel? model)
{
if (model == null)
{
return null;
}
var list = _lawyerStorage.GetLawyerConsultationList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public LawyerViewModel? ReadElement(LawyerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. LawyerName:{FIO}. Id:{Id}", model.FIO, model.Id);
var element = _lawyerStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public LawyerViewModel? ReadElement(LawyerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. LawyerName:{FIO}. Id:{Id}", model.FIO, model.Id);
var element = _lawyerStorage.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<LawyerViewModel>? ReadList(LawyerSearchModel? model)
{
_logger.LogInformation("ReadList. LawyerName:{LawyerName}.Id:{Id}", model?.FIO, model?.Id);
var list = model == null ? _lawyerStorage.GetFullList() : _lawyerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public List<LawyerViewModel>? ReadList(LawyerSearchModel? model)
{
_logger.LogInformation("ReadList. LawyerName:{LawyerName}.Id:{Id}", model?.FIO, model?.Id);
var list = model == null ? _lawyerStorage.GetFullList() : _lawyerStorage.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(LawyerBindingModel model)
{
CheckModel(model);
if (_lawyerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(LawyerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FIO))
{
throw new ArgumentNullException("Нет имени юриста", nameof(model.FIO));
}
if (string.IsNullOrEmpty(model.Phone))
{
throw new ArgumentNullException("Нет телефона юриста", nameof(model.Phone));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет e-mail юриста", nameof(model.Email));
}
public bool Update(LawyerBindingModel model)
{
CheckModel(model);
if (_lawyerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(LawyerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FIO))
{
throw new ArgumentNullException("Нет имени юриста", nameof(model.FIO));
}
if (string.IsNullOrEmpty(model.Phone))
{
throw new ArgumentNullException("Нет телефона юриста", nameof(model.Phone));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет e-mail юриста", nameof(model.Email));
}
_logger.LogInformation("Lawyer. LawyerName:{FIO}. Phone: {Phone}. E-mail:{Email}. Id: {Id} ", model.FIO, model.Phone, model.Email, model.Id);
var element = _lawyerStorage.GetElement(new LawyerSearchModel
{
FIO = model.FIO,
Phone = model.Phone,
Email = model.Email,
GuarantorId = model.GuarantorId,
_logger.LogInformation("Lawyer. LawyerName:{FIO}. Phone: {Phone}. E-mail:{Email}. Id: {Id} ", model.FIO, model.Phone, model.Email, model.Id);
var element = _lawyerStorage.GetElement(new LawyerSearchModel
{
FIO = model.FIO,
Phone = model.Phone,
Email = model.Email,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Юрист с такими данными уже есть");
}
}
}
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Юрист с такими данными уже есть");
}
}
}
}

View File

@ -2,13 +2,13 @@
namespace LawCompanyContracts.BindingModels
{
public class ConsultationBindingModel : IConsultationModel
{
public int Id { get; set; }
public double Cost { get; set; }
public DateTime ConsultationDate { get; set; }
public int CaseId { get; set; }
public int GuarantorId { get; set; }
public Dictionary<int, ILawyerModel> ConsultationLawyers { get; set; } = new();
}
public class ConsultationBindingModel : IConsultationModel
{
public int Id { get; set; }
public double Cost { get; set; }
public DateTime ConsultationDate { get; set; }
public int CaseId { get; set; }
public int GuarantorId { get; set; }
public Dictionary<int, ILawyerModel> ConsultationLawyers { get; set; } = new();
}
}

View File

@ -2,13 +2,13 @@
namespace LawCompanyContracts.BindingModels
{
public class GuarantorBindingModel : IGuarantorModel
{
public int Id { get; set; }
public string FIO { get; set; } = string.Empty;
public class GuarantorBindingModel : IGuarantorModel
{
public int Id { get; set; }
public string FIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
public string Password { get; set; } = string.Empty;
}
}

View File

@ -2,12 +2,12 @@
namespace LawCompanyContracts.BindingModels
{
public class LawyerBindingModel : ILawyerModel
{
public int Id { get; set; }
public string FIO { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public int? GuarantorId { get; set; }
}
public class LawyerBindingModel : ILawyerModel
{
public int Id { get; set; }
public string FIO { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public int? GuarantorId { get; set; }
}
}

View File

@ -1,17 +1,17 @@
using LawCompanyContracts.BindingModels;
using LawCompanyDataModels.Models;
using LawCompanyDataModels.Models;
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.ViewModels;
namespace LawCompanyContracts.BusinessLogicContracts
{
public interface IConsultationLogic
{
List<ConsultationViewModel>? ReadList(ConsultationSearchModel? model);
ConsultationViewModel? ReadElement(ConsultationSearchModel model);
bool Create(ConsultationBindingModel model);
bool Update(ConsultationBindingModel model);
bool Delete(ConsultationBindingModel model);
bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer);
}
public interface IConsultationLogic
{
List<ConsultationViewModel>? ReadList(ConsultationSearchModel? model);
ConsultationViewModel? ReadElement(ConsultationSearchModel model);
bool Create(ConsultationBindingModel model);
bool Update(ConsultationBindingModel model);
bool Delete(ConsultationBindingModel model);
bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer);
}
}

View File

@ -1,20 +1,15 @@
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyContracts.BusinessLogicContracts
{
public interface IGuarantorLogic
{
List<GuarantorViewModel>? ReadList(GuarantorSearchModel? model);
GuarantorViewModel? ReadElement(GuarantorSearchModel model);
bool Create(GuarantorBindingModel model);
bool Update(GuarantorBindingModel model);
bool Delete(GuarantorBindingModel model);
}
public interface IGuarantorLogic
{
List<GuarantorViewModel>? ReadList(GuarantorSearchModel? model);
GuarantorViewModel? ReadElement(GuarantorSearchModel model);
bool Create(GuarantorBindingModel model);
bool Update(GuarantorBindingModel model);
bool Delete(GuarantorBindingModel model);
}
}

View File

@ -1,22 +1,17 @@
using LawCompanyContracts.BindingModels;
using LawCompanyDataModels.Models;
using LawCompanyDataModels.Models;
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyContracts.BusinessLogicContracts
{
public interface IHearingLogic
{
List<HearingViewModel>? ReadList(HearingSearchModel? model);
HearingViewModel? ReadElement(HearingSearchModel model);
bool Create(HearingBindingModel model);
bool Update(HearingBindingModel model);
bool Delete(HearingBindingModel model);
bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel client);
}
public interface IHearingLogic
{
List<HearingViewModel>? ReadList(HearingSearchModel? model);
HearingViewModel? ReadElement(HearingSearchModel model);
bool Create(HearingBindingModel model);
bool Update(HearingBindingModel model);
bool Delete(HearingBindingModel model);
bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel client);
}
}

View File

@ -1,22 +1,17 @@
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyContracts.BusinessLogicContracts
{
public interface ILawyerLogic
{
List<LawyerViewModel>? ReadHearingElementList(HearingSearchModel? model);
List<LawyerViewModel>? ReadConsultationElementList(ConsultationSearchModel? model);
List<LawyerViewModel>? ReadList(LawyerSearchModel? model);
LawyerViewModel? ReadElement(LawyerSearchModel model);
bool Create(LawyerBindingModel model);
bool Update(LawyerBindingModel model);
bool Delete(LawyerBindingModel model);
}
public interface ILawyerLogic
{
List<LawyerViewModel>? ReadHearingElementList(HearingSearchModel? model);
List<LawyerViewModel>? ReadConsultationElementList(ConsultationSearchModel? model);
List<LawyerViewModel>? ReadList(LawyerSearchModel? model);
LawyerViewModel? ReadElement(LawyerSearchModel model);
bool Create(LawyerBindingModel model);
bool Update(LawyerBindingModel model);
bool Delete(LawyerBindingModel model);
}
}

View File

@ -1,11 +1,13 @@
namespace LawCompanyContracts.SearchModels
{
public class ConsultationSearchModel
{
public int? Id { get; set; }
public double? Cost { get; set; }
public DateTime? ConsultationDate { get; set; }
public int? CaseId { get; set; }
public int? GuarantorId { get; set; }
}
public class ConsultationSearchModel
{
public int? Id { get; set; }
public double? Cost { get; set; }
public DateTime? ConsultationDate { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? CaseId { get; set; }
public int? GuarantorId { get; set; }
}
}

View File

@ -1,16 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyContracts.SearchModels
namespace LawCompanyContracts.SearchModels
{
public class GuarantorSearchModel
{
public int? Id { get; set; }
public string? FIO { get; set; }
public string? Email { get; set; }
public string? Password { get; set; }
}
public class GuarantorSearchModel
{
public int? Id { get; set; }
public string? FIO { get; set; }
public string? Email { get; set; }
public string? Password { get; set; }
}
}

View File

@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyContracts.SearchModels
namespace LawCompanyContracts.SearchModels
{
public class HearingSearchModel
{
public int? Id { get; set; }
public DateTime? HearingDate { get; set; }
public int? GuarantorId { get; set; }
}
public class HearingSearchModel
{
public int? Id { get; set; }
public DateTime? HearingDate { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? GuarantorId { get; set; }
}
}

View File

@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyContracts.SearchModels
namespace LawCompanyContracts.SearchModels
{
public class LawyerSearchModel
{
public int? Id { get; set; }
public string? FIO { get; set; }
public string? Phone { get; set; }
public string? Email { get; set; }
public int? GuarantorId { get; set; }
}
public class LawyerSearchModel
{
public int? Id { get; set; }
public string? FIO { get; set; }
public string? Phone { get; set; }
public string? Email { get; set; }
public int? GuarantorId { get; set; }
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyContracts.SearchModels
namespace LawCompanyContracts.SearchModels
{
public class VisitSearchModel
{

View File

@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels;
namespace LawCompanyContracts.StoragesContracts
{
public interface ICaseStorage
{
List<CaseViewModel> GetFullList();
List<CaseViewModel> GetFilteredList(CaseSearchModel model);
CaseViewModel? GetElement(CaseSearchModel model);
CaseViewModel? Insert(CaseBindingModel model);
CaseViewModel? Update(CaseBindingModel model);
CaseViewModel? Delete(CaseBindingModel model);
}
public interface ICaseStorage
{
List<CaseViewModel> GetFullList();
List<CaseViewModel> GetFilteredList(CaseSearchModel model);
CaseViewModel? GetElement(CaseSearchModel model);
CaseViewModel? Insert(CaseBindingModel model);
CaseViewModel? Update(CaseBindingModel model);
CaseViewModel? Delete(CaseBindingModel model);
}
}

View File

@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels;
namespace LawCompanyContracts.StoragesContracts
{
public interface IConsultationStorage
{
List<ConsultationViewModel> GetFullList();
List<ConsultationViewModel> GetFilteredList(ConsultationSearchModel model);
ConsultationViewModel? GetElement(ConsultationSearchModel model);
ConsultationViewModel? Insert(ConsultationBindingModel model);
ConsultationViewModel? Update(ConsultationBindingModel model);
ConsultationViewModel? Delete(ConsultationBindingModel model);
}
public interface IConsultationStorage
{
List<ConsultationViewModel> GetFullList();
List<ConsultationViewModel> GetFilteredList(ConsultationSearchModel model);
ConsultationViewModel? GetElement(ConsultationSearchModel model);
ConsultationViewModel? Insert(ConsultationBindingModel model);
ConsultationViewModel? Update(ConsultationBindingModel model);
ConsultationViewModel? Delete(ConsultationBindingModel model);
}
}

View File

@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels;
namespace LawCompanyContracts.StoragesContracts
{
public interface IGuarantorStorage
{
List<GuarantorViewModel> GetFullList();
List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model);
GuarantorViewModel? GetElement(GuarantorSearchModel model);
GuarantorViewModel? Insert(GuarantorBindingModel model);
GuarantorViewModel? Update(GuarantorBindingModel model);
GuarantorViewModel? Delete(GuarantorBindingModel model);
}
public interface IGuarantorStorage
{
List<GuarantorViewModel> GetFullList();
List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model);
GuarantorViewModel? GetElement(GuarantorSearchModel model);
GuarantorViewModel? Insert(GuarantorBindingModel model);
GuarantorViewModel? Update(GuarantorBindingModel model);
GuarantorViewModel? Delete(GuarantorBindingModel model);
}
}

View File

@ -4,13 +4,13 @@ using LawCompanyContracts.ViewModels;
namespace LawCompanyContracts.StoragesContracts
{
public class IHearingStorage
{
List<HearingViewModel> GetFullList();
List<HearingViewModel> GetFilteredList(HearingSearchModel model);
HearingViewModel? GetElement(HearingSearchModel model);
HearingViewModel? Insert(HearingBindingModel model);
HearingViewModel? Update(HearingBindingModel model);
HearingViewModel? Delete(HearingBindingModel model);
}
public interface IHearingStorage
{
List<HearingViewModel> GetFullList();
List<HearingViewModel> GetFilteredList(HearingSearchModel model);
HearingViewModel? GetElement(HearingSearchModel model);
HearingViewModel? Insert(HearingBindingModel model);
HearingViewModel? Update(HearingBindingModel model);
HearingViewModel? Delete(HearingBindingModel model);
}
}

View File

@ -4,15 +4,15 @@ using LawCompanyContracts.ViewModels;
namespace LawCompanyContracts.StoragesContracts
{
public class ILawyerStorage
{
List<LawyerViewModel> GetFullList();
List<LawyerViewModel> GetFilteredList(LawyerSearchModel model);
List<LawyerViewModel> GetLawyerConsultationList(ConsultationSearchModel model);
List<LawyerViewModel> GetLawyerHearingList(HearingSearchModel model);
LawyerViewModel? GetElement(LawyerSearchModel model);
LawyerViewModel? Insert(LawyerBindingModel model);
LawyerViewModel? Update(LawyerBindingModel model);
LawyerViewModel? Delete(LawyerBindingModel model);
}
public interface ILawyerStorage
{
List<LawyerViewModel> GetFullList();
List<LawyerViewModel> GetFilteredList(LawyerSearchModel model);
List<LawyerViewModel> GetLawyerConsultationList(ConsultationSearchModel model);
List<LawyerViewModel> GetLawyerHearingList(HearingSearchModel model);
LawyerViewModel? GetElement(LawyerSearchModel model);
LawyerViewModel? Insert(LawyerBindingModel model);
LawyerViewModel? Update(LawyerBindingModel model);
LawyerViewModel? Delete(LawyerBindingModel model);
}
}

View File

@ -3,20 +3,18 @@ using System.ComponentModel;
namespace LawCompanyContracts.ViewModels
{
public class ConsultationViewModel : IConsultationModel
{
[DisplayName("Номер консультации")]
public int Id { get; set; }
[DisplayName("Цена консультации")]
public double Cost { get; set; }
[DisplayName("Дата консультации")]
public DateTime ConsultationDate { get; set; }
[DisplayName("Дело")]
public string CaseName { get; set; } = string.Empty;
public int CaseId { get; set; }
[DisplayName("Имя поручителя")]
public string GuarantorName { get; set; } = string.Empty;
public int GuarantorId { get; set; }
public Dictionary<int, ILawyerModel> ConsultationLawyers { get; set; } = new();
}
public class ConsultationViewModel : IConsultationModel
{
[DisplayName("Номер консультации")]
public int Id { get; set; }
[DisplayName("Цена консультации")]
public double Cost { get; set; }
[DisplayName("Дата консультации")]
public DateTime ConsultationDate { get; set; }
[DisplayName("Дело")]
public string CaseName { get; set; } = string.Empty;
public int CaseId { get; set; }
public int GuarantorId { get; set; }
public Dictionary<int, ILawyerModel> ConsultationLawyers { get; set; } = new();
}
}

View File

@ -3,14 +3,14 @@ using System.ComponentModel;
namespace LawCompanyContracts.ViewModels
{
public class GuarantorViewModel : IGuarantorModel
{
public int Id { get; set; }
[DisplayName("Имя поручителя")]
public string FIO { get; set; } = string.Empty;
[DisplayName("E-mail поручителя")]
public string Email { get; set; } = string.Empty;
[DisplayName("Пароль поручителя")]
public string Password { get; set; } = string.Empty;
}
public class GuarantorViewModel : IGuarantorModel
{
public int Id { get; set; }
[DisplayName("Имя поручителя")]
public string FIO { get; set; } = string.Empty;
[DisplayName("E-mail поручителя")]
public string Email { get; set; } = string.Empty;
[DisplayName("Пароль поручителя")]
public string Password { get; set; } = string.Empty;
}
}

View File

@ -3,16 +3,16 @@ using System.ComponentModel;
namespace LawCompanyContracts.ViewModels
{
public class LawyerViewModel : ILawyerModel
{
[DisplayName("Номер юриста")]
public int Id { get; set; }
[DisplayName("Имя юриста")]
public string FIO { get; set; } = string.Empty;
[DisplayName("Телефон юриста")]
public string Phone { get; set; } = string.Empty;
[DisplayName("E-mail юриста")]
public string Email { get; set; } = string.Empty;
public int? GuarantorId { get; set; }
}
public class LawyerViewModel : ILawyerModel
{
[DisplayName("Номер юриста")]
public int Id { get; set; }
[DisplayName("Имя юриста")]
public string FIO { get; set; } = string.Empty;
[DisplayName("Телефон юриста")]
public string Phone { get; set; } = string.Empty;
[DisplayName("E-mail юриста")]
public string Email { get; set; } = string.Empty;
public int? GuarantorId { get; set; }
}
}

View File

@ -3,101 +3,96 @@ using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using LawCompanyDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LawCompanyDatabaseImplement.Implements
{
public class GuarantorStorage : IGuarantorStorage
{
public List<GuarantorViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Select(x => x.GetViewModel)
.ToList();
}
public class GuarantorStorage : IGuarantorStorage
{
public List<GuarantorViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Select(x => x.GetViewModel)
.ToList();
}
public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return new();
}
if (!string.IsNullOrEmpty(model.Email))
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
public List<GuarantorViewModel> GetFilteredList(GuarantorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return new();
}
if (!string.IsNullOrEmpty(model.Email))
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Guarantors
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
public GuarantorViewModel? GetElement(GuarantorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new LawCompanyDatabase();
public GuarantorViewModel? GetElement(GuarantorSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO)
&& string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new LawCompanyDatabase();
return context.Guarantors
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email)
&& x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
return context.Guarantors
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email)
&& x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public GuarantorViewModel? Insert(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var newGuarantor = Guarantor.Create(model);
if (newGuarantor == null)
{
return null;
}
context.Guarantors.Add(newGuarantor);
context.SaveChanges();
return newGuarantor.GetViewModel;
}
public GuarantorViewModel? Insert(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var newGuarantor = Guarantor.Create(context, model);
if (newGuarantor == null)
{
return null;
}
context.Guarantors.Add(newGuarantor);
context.SaveChanges();
return newGuarantor.GetViewModel;
}
public GuarantorViewModel? Update(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id);
if (executor == null)
{
return null;
}
executor.Update(model);
context.SaveChanges();
return executor.GetViewModel;
}
public GuarantorViewModel? Update(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id);
if (executor == null)
{
return null;
}
executor.Update(model);
context.SaveChanges();
return executor.GetViewModel;
}
public GuarantorViewModel? Delete(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Guarantors.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
public GuarantorViewModel? Delete(GuarantorBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Guarantors.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -6,105 +6,105 @@ using LawCompanyDatabaseImplement.Models;
namespace LawCompanyDatabaseImplement.Implements
{
public class LawyerStorage : ILawyerStorage
{
public List<LawyerViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Select(x => x.GetViewModel)
.ToList();
}
public List<LawyerViewModel> GetFilteredList(LawyerSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue && string.IsNullOrEmpty(model.FIO))
{
return new();
}
if (!string.IsNullOrEmpty(model.Email))
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.GuarantorId.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Where(x => x.GuarantorId.Equals(model.GuarantorId))
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
public LawyerViewModel? GetElement(LawyerSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue
&& string.IsNullOrEmpty(model.FIO))
{
return null;
}
using var context = new LawCompanyDatabase();
return context.Lawyers
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.GuarantorId.HasValue && x.GuarantorId == model.GuarantorId))
?.GetViewModel;
}
public LawyerViewModel? Insert(LawyerBindingModel model)
{
using var context = new LawCompanyDatabase();
var newLawyer = Lawyer.Create(model);
if (newLawyer == null)
{
return null;
}
context.Lawyers.Add(newLawyer);
context.SaveChanges();
return newLawyer.GetViewModel;
}
public LawyerViewModel? Update(LawyerBindingModel model)
{
using var context = new LawCompanyDatabase();
var lawyer = context.Lawyers.FirstOrDefault(x => x.Id == model.Id);
if (lawyer == null)
{
return null;
}
lawyer.Update(model);
context.SaveChanges();
return lawyer.GetViewModel;
}
public LawyerViewModel? Delete(LawyerBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Lawyers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Lawyers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public List<LawyerViewModel> GetLawyerHearingList(HearingSearchModel model)
{
using var context = new LawCompanyDatabase();
return context.HearingLawyers.Where(x => x.HearingId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList();
public class LawyerStorage : ILawyerStorage
{
public List<LawyerViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Select(x => x.GetViewModel)
.ToList();
}
public List<LawyerViewModel> GetFilteredList(LawyerSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue && string.IsNullOrEmpty(model.FIO))
{
return new();
}
if (!string.IsNullOrEmpty(model.Email))
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Where(x => x.Email.Equals(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.GuarantorId.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Where(x => x.GuarantorId.Equals(model.GuarantorId))
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Lawyers
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
public LawyerViewModel? GetElement(LawyerSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && !model.GuarantorId.HasValue
&& string.IsNullOrEmpty(model.FIO))
{
return null;
}
using var context = new LawCompanyDatabase();
return context.Lawyers
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.GuarantorId.HasValue && x.GuarantorId == model.GuarantorId))
?.GetViewModel;
}
public LawyerViewModel? Insert(LawyerBindingModel model)
{
using var context = new LawCompanyDatabase();
var newLawyer = Lawyer.Create(context, model);
if (newLawyer == null)
{
return null;
}
context.Lawyers.Add(newLawyer);
context.SaveChanges();
return newLawyer.GetViewModel;
}
public LawyerViewModel? Update(LawyerBindingModel model)
{
using var context = new LawCompanyDatabase();
var lawyer = context.Lawyers.FirstOrDefault(x => x.Id == model.Id);
if (lawyer == null)
{
return null;
}
lawyer.Update(model);
context.SaveChanges();
return lawyer.GetViewModel;
}
public LawyerViewModel? Delete(LawyerBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Lawyers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Lawyers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public List<LawyerViewModel> GetLawyerHearingList(HearingSearchModel model)
{
using var context = new LawCompanyDatabase();
return context.HearingLawyers.Where(x => x.HearingId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList();
}
public List<LawyerViewModel> GetLawyerConsultationList(ConsultationSearchModel model)
{
using var context = new LawCompanyDatabase();
return context.ConsultationLawyers.Where(x => x.ConsultationId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList();
}
public List<LawyerViewModel> GetLawyerConsultationList(ConsultationSearchModel model)
{
using var context = new LawCompanyDatabase();
return context.ConsultationLawyers.Where(x => x.ConsultationId == model.Id).Select(x => x.Lawyer.GetViewModel).ToList();
}
}
}
}
}

View File

@ -3,7 +3,7 @@ using LawCompanyContracts.BindingModels;
using LawCompanyContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using LawFirmDatabaseImplement.Models;
using LawCompanyDatabaseImplement.Models;
namespace LawCompanyDatabaseImplement.Models
{