Добавление DinnerLogic. Фикс название Dinner.

This commit is contained in:
Кашин Максим 2023-04-07 00:16:35 +04:00
parent dbdb2d0632
commit 07948de46a
6 changed files with 139 additions and 9 deletions

View File

@ -48,7 +48,7 @@
@Html.DisplayFor(modelItem => item.DinnerName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DinnetPrice)
@Html.DisplayFor(modelItem => item.DinnerPrice)
</td>
</tr>
}

View File

@ -0,0 +1,130 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelBusinessLogic.BusinessLogics
{
public class DinnerLogic : IDinnerLogic
{
private readonly ILogger _logger;
private readonly IDinnerStorage _dinnerStorage;
public DinnerLogic(ILogger<DinnerLogic> logger, IDinnerStorage dinnerStorage)
{
_logger = logger;
_dinnerStorage = dinnerStorage;
}
public bool Create(DinnerBindingModel model)
{
CheckModel(model);
if (_dinnerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(DinnerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_dinnerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public DinnerViewModel? ReadElement(DinnerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DinnerName:{DinnerName}.Id:{Id}", model.DinnerName, model.Id);
var element = _dinnerStorage.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<DinnerViewModel>? ReadList(DinnerSearchModel? model)
{
_logger.LogInformation("ReadList. DinnerName:{DinnerName}.Id:{ Id}", model?.DinnerName, model?.Id);
var list = model == null ? _dinnerStorage.GetFullList() : _dinnerStorage.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(DinnerBindingModel model)
{
CheckModel(model);
if (_dinnerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(DinnerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.DinnerName))
{
throw new ArgumentNullException("Нет имени обеда", nameof(model.DinnerName));
}
if (model.DinnerPrice < 0)
{
throw new ArgumentNullException("Стоимость обеда не может быть меньше 0", nameof(model.DinnerPrice));
}
_logger.LogInformation("Dinner. DinnerName:{DinnerName}.DinnerPrice:{ DinnerPrice}. Id: { Id}", model.DinnerName, model.DinnerPrice, model.Id);
}
}
}

View File

@ -6,7 +6,7 @@ namespace HotelContracts.BindingModels
{
public string DinnerName { get; set; } = string.Empty;
public double DinnetPrice { get; set; }
public double DinnerPrice { get; set; }
public int HeadwaiterId { get; set; }

View File

@ -13,7 +13,7 @@ namespace HotelContracts.ViewModels
public string DinnerName { get; set; } = string.Empty;
[DisplayName("Цена обеда")]
public double DinnetPrice { get; set; }
public double DinnerPrice { get; set; }
}
}

View File

@ -20,7 +20,7 @@ namespace HotelDataBaseImplement.Models
public string DinnerName { get; set; } = string.Empty;
[Required]
public double DinnetPrice { get; set; }
public double DinnerPrice { get; set; }
public virtual Headwaiter Headwaiters { get; set; }
@ -39,7 +39,7 @@ namespace HotelDataBaseImplement.Models
{
Id = model.Id,
DinnerName = model.DinnerName,
DinnetPrice = model.DinnetPrice
DinnerPrice = model.DinnerPrice
};
}
public static Dinner Create(DinnerViewModel model)
@ -48,7 +48,7 @@ namespace HotelDataBaseImplement.Models
{
Id = model.Id,
DinnerName = model.DinnerName,
DinnetPrice = model.DinnetPrice
DinnerPrice = model.DinnerPrice
};
}
public void Update(DinnerBindingModel model)
@ -58,13 +58,13 @@ namespace HotelDataBaseImplement.Models
return;
}
DinnerName = model.DinnerName;
DinnetPrice = model.DinnetPrice;
DinnerPrice = model.DinnerPrice;
}
public DinnerViewModel GetViewModel => new()
{
Id = Id,
DinnerName = DinnerName,
DinnetPrice = DinnetPrice
DinnerPrice = DinnerPrice
};
}
}

View File

@ -3,7 +3,7 @@
public interface IDinnerModel : IId
{
string DinnerName { get; }
double DinnetPrice { get; }
double DinnerPrice { get; }
int HeadwaiterId { get; }
}
}