diff --git a/Hotel/HostrelHeadwaiterApp/Views/Home/FormationDinner.cshtml b/Hotel/HostrelHeadwaiterApp/Views/Home/FormationDinner.cshtml index 61f1a3e..1befa76 100644 --- a/Hotel/HostrelHeadwaiterApp/Views/Home/FormationDinner.cshtml +++ b/Hotel/HostrelHeadwaiterApp/Views/Home/FormationDinner.cshtml @@ -48,7 +48,7 @@ @Html.DisplayFor(modelItem => item.DinnerName) - @Html.DisplayFor(modelItem => item.DinnetPrice) + @Html.DisplayFor(modelItem => item.DinnerPrice) } diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/DinnerLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/DinnerLogic.cs new file mode 100644 index 0000000..b97212d --- /dev/null +++ b/Hotel/HotelBusinessLogic/BusinessLogics/DinnerLogic.cs @@ -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 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? 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); + } + } +} diff --git a/Hotel/HotelContracts/BindingModels/DinnerBindingModel.cs b/Hotel/HotelContracts/BindingModels/DinnerBindingModel.cs index 27cc821..f665af7 100644 --- a/Hotel/HotelContracts/BindingModels/DinnerBindingModel.cs +++ b/Hotel/HotelContracts/BindingModels/DinnerBindingModel.cs @@ -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; } diff --git a/Hotel/HotelContracts/ViewModels/DinnerViewModel.cs b/Hotel/HotelContracts/ViewModels/DinnerViewModel.cs index 623f2ab..bca0b92 100644 --- a/Hotel/HotelContracts/ViewModels/DinnerViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/DinnerViewModel.cs @@ -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; } } } diff --git a/Hotel/HotelDataBaseImplement/Models/Dinner.cs b/Hotel/HotelDataBaseImplement/Models/Dinner.cs index a40768c..e77ac60 100644 --- a/Hotel/HotelDataBaseImplement/Models/Dinner.cs +++ b/Hotel/HotelDataBaseImplement/Models/Dinner.cs @@ -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 }; } } diff --git a/Hotel/HotelDataModels/Models/IDinnerModel.cs b/Hotel/HotelDataModels/Models/IDinnerModel.cs index e69a0aa..6391411 100644 --- a/Hotel/HotelDataModels/Models/IDinnerModel.cs +++ b/Hotel/HotelDataModels/Models/IDinnerModel.cs @@ -3,7 +3,7 @@ public interface IDinnerModel : IId { string DinnerName { get; } - double DinnetPrice { get; } + double DinnerPrice { get; } int HeadwaiterId { get; } } }