добавлены файлы в проект ..Contracts и начата логика магазина
This commit is contained in:
parent
973afb771a
commit
745dbe385f
70
SushiBarBusinessLogic/ShopLogic.cs
Normal file
70
SushiBarBusinessLogic/ShopLogic.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModel;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModel;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels;
|
||||
|
||||
namespace SushiBarBusinessLogic
|
||||
{
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public ShopLogic(ILogger logger, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.Name);
|
||||
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.Name);
|
||||
var element = _shopStorage.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(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
}
|
||||
|
||||
private bool CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if(model == null)
|
||||
throw new ArgumentNullException($"{nameof(model)} is null");
|
||||
if (!withParams) return false;
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет такого магазина", nameof(model.Name));
|
||||
}
|
||||
_logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}",
|
||||
model.ShopName, model.Address, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
14
SushiBarContracts/BindingModel/ShopBindingModel.cs
Normal file
14
SushiBarContracts/BindingModel/ShopBindingModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using SushiBarDataModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BindingModel
|
||||
{
|
||||
public class ShopBindingModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Address { get; set; }
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, (ISushiModel, int)> ShopSushis { get; set; } = new();
|
||||
}
|
||||
}
|
17
SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
17
SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using SushiBarContracts.BindingModel;
|
||||
using SushiBarContracts.SearchModel;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBarContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IShopLogic
|
||||
{
|
||||
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count);
|
||||
}
|
||||
}
|
8
SushiBarContracts/SearchModel/ShopSearchModel.cs
Normal file
8
SushiBarContracts/SearchModel/ShopSearchModel.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace SushiBarContracts.SearchModel
|
||||
{
|
||||
public class ShopSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
16
SushiBarContracts/StoragesContracts/IShopStorage.cs
Normal file
16
SushiBarContracts/StoragesContracts/IShopStorage.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using SushiBarContracts.BindingModel;
|
||||
using SushiBarContracts.SearchModel;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarContracts.StoragesContracts
|
||||
{
|
||||
public interface IShopStorage
|
||||
{
|
||||
List<ShopViewModel> GetFullList();
|
||||
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||
ShopViewModel? GetElement(ShopSearchModel model);
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
}
|
||||
}
|
21
SushiBarContracts/ViewModels/ShopViewModel.cs
Normal file
21
SushiBarContracts/ViewModels/ShopViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using SushiBarDataModels;
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
public class ShopViewModel : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название магазина")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, (ISushiModel, int)> ShopSushis { get; set; } = new();
|
||||
}
|
||||
}
|
@ -4,9 +4,9 @@ namespace SushiBarDataModels
|
||||
{
|
||||
public interface IShopModel : IId
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Address { get; set; }
|
||||
DateTime DateOpening { get; set; }
|
||||
Dictionary<int, (ISushiModel, int)> ShopSushis{ get; set; }
|
||||
string Name { get; }
|
||||
string Address { get; }
|
||||
DateTime DateOpening { get; }
|
||||
Dictionary<int, (ISushiModel, int)> ShopSushis{ get; }
|
||||
}
|
||||
}
|
||||
|
6
SushiBarDataModels/ShopBindingModel.cs
Normal file
6
SushiBarDataModels/ShopBindingModel.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace SushiBarDataModels
|
||||
{
|
||||
public class ShopBindingModel : IShopModel
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user