116 lines
3.4 KiB
C#
116 lines
3.4 KiB
C#
|
using HotelContracts.BindingModels;
|
|||
|
using HotelContracts.BusinessLogicsContracts;
|
|||
|
using HotelContracts.SearchModels;
|
|||
|
using HotelContracts.StoragesContracts;
|
|||
|
using HotelContracts.ViewModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace HotelBusinessLogic
|
|||
|
{
|
|||
|
public class WorkerLogic : IWorkerLogic
|
|||
|
{
|
|||
|
private readonly IWorkerStorage _workerStorage;
|
|||
|
|
|||
|
public WorkerLogic(IWorkerStorage workerStorage)
|
|||
|
{
|
|||
|
_workerStorage = workerStorage;
|
|||
|
}
|
|||
|
public WorkerViewModel? ReadElement(WorkerSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
|
|||
|
var element = _workerStorage.GetElement(model);
|
|||
|
if (element == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return element;
|
|||
|
}
|
|||
|
|
|||
|
public List<WorkerViewModel>? ReadList(WorkerSearchModel? model)
|
|||
|
{
|
|||
|
var list = model == null ? _workerStorage.GetFullList() : _workerStorage.GetFilteredList(model);
|
|||
|
if (list == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
public bool Create(WorkerBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_workerStorage.Insert(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(WorkerBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model, false);
|
|||
|
if (_workerStorage.Delete(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(WorkerBindingModel model)
|
|||
|
{
|
|||
|
CheckModel(model);
|
|||
|
if (_workerStorage.Update(model) == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private void CheckModel(WorkerBindingModel model, bool withParams = true)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
throw new ArgumentNullException(nameof(model));
|
|||
|
}
|
|||
|
if (!withParams)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.Phone))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Нет поля номер телефона", nameof(model.Phone));
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(model.FIO))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Нет поля ФИО", nameof(model.FIO));
|
|||
|
}
|
|||
|
if (model.PostId <= 0)
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Некорректный идентификатор должности", nameof(model.PostId));
|
|||
|
}
|
|||
|
if (model.WorkExperience < 0)
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Рабочий опыт не может быть меньше 0", nameof(model.WorkExperience));
|
|||
|
}
|
|||
|
if (model.PostId <= 0)
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Некорректный идентификатор должности", nameof(model.PostId));
|
|||
|
}
|
|||
|
if (model.Salary <= 0)
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Зарплата не может быть меньше 0", nameof(model.Salary));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|