2023-04-07 00:11:08 +04:00
|
|
|
|
using HotelContracts.BindingModels;
|
|
|
|
|
using HotelContracts.BusinessLogicsContracts;
|
|
|
|
|
using HotelContracts.SearchModels;
|
|
|
|
|
using HotelContracts.StoragesContracts;
|
|
|
|
|
using HotelContracts.ViewModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace HotelBusinessLogic.BusinessLogics;
|
|
|
|
|
|
|
|
|
|
public class CleaningLogic : ICleaningLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ICleaningStorage _cleaningStorage;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
public CleaningLogic(ICleaningStorage cleaningStorage, ILogger<MaitreLogic> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_cleaningStorage = cleaningStorage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<CleaningViewModel>? ReadList(CleaningSearchModel? model)
|
|
|
|
|
{
|
|
|
|
|
var list = model == null ? _cleaningStorage.GetFullList() : _cleaningStorage.GetFilteredList(model);
|
|
|
|
|
_logger.LogInformation("ReadList .Count:{Count}", list.Count);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CleaningViewModel? ReadElement(CleaningSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
_logger.LogInformation("ReadElement .Id:{Id}", model.Id);
|
|
|
|
|
var element = _cleaningStorage.GetElement(model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadElement element not found");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadElement find .Id:{Id}", element.Id);
|
|
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Create(CleaningBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_cleaningStorage.Insert(model) != null) return true;
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(CleaningBindingModel model)
|
|
|
|
|
{
|
2023-05-19 20:55:43 +04:00
|
|
|
|
CheckModel(model, false);
|
2023-04-07 00:11:08 +04:00
|
|
|
|
if (_cleaningStorage.Update(model) != null) return true;
|
|
|
|
|
_logger.LogWarning("Update operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Delete(CleaningBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
_logger.LogInformation("Delete .Id:{Id}", model.Id);
|
|
|
|
|
if (_cleaningStorage.Delete(model) != null) return true;
|
|
|
|
|
_logger.LogWarning("Delete operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckModel(CleaningBindingModel? model, bool withParams = true)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
if (!withParams)
|
|
|
|
|
return;
|
2023-05-19 17:52:18 +04:00
|
|
|
|
if (model.RoomId <= 0)
|
2023-04-07 00:11:08 +04:00
|
|
|
|
throw new ArgumentException("RoomId must be more then 0");
|
|
|
|
|
}
|
|
|
|
|
}
|