Создание классов BusinessLogic для роли Поставщик. Фиксы модификаторов доступа в CreditProgramSearchModel и наследований во View моделях. Изменениие типа данных Percent с int на float. Прописаны недостающие using в StoragesContracts.
This commit is contained in:
parent
98690a9868
commit
1083f48386
@ -6,4 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
116
Bank/BankBusinessLogic/BusinessLogics/BankOperatorLogic.cs
Normal file
116
Bank/BankBusinessLogic/BusinessLogics/BankOperatorLogic.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using BankContracts.StoragesContracts;
|
||||
|
||||
namespace BankBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class BankOperatorLogic : IBankOperatorLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBankOperatorStorage _BankOperatorStorage;
|
||||
|
||||
public BankOperatorLogic(ILogger<BankOperatorLogic> logger, IBankOperatorStorage BankOperatorStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_BankOperatorStorage = BankOperatorStorage;
|
||||
}
|
||||
public List<BankOperatorViewModel>? ReadList(BankOperatorSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _BankOperatorStorage.GetFullList() : _BankOperatorStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public BankOperatorViewModel? ReadElement(BankOperatorSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}. Login: { Login}", model.Id, model.Login);
|
||||
var element = _BankOperatorStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}. Login: { Login}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(BankOperatorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_BankOperatorStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(BankOperatorBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_BankOperatorStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(BankOperatorBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_BankOperatorStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(BankOperatorBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.FirstName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет имени!", nameof(model.FirstName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.LastName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет фамилии!", nameof(model.LastName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина!", nameof(model.Login));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля!", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("FirstName:{ FirstName}. LastName: {LastName}. Login: {Login} .Id: { Id}",
|
||||
model.FirstName, model.LastName, model.Login, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
107
Bank/BankBusinessLogic/BusinessLogics/CreditProgramLogic.cs
Normal file
107
Bank/BankBusinessLogic/BusinessLogics/CreditProgramLogic.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using BankContracts.StoragesContracts;
|
||||
|
||||
namespace BankBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class CreditProgramLogic : ICreditProgramLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICreditProgramStorage _CreditProgramStorage;
|
||||
public CreditProgramLogic(ILogger<CreditProgramLogic> logger, ICreditProgramStorage CreditProgramStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_CreditProgramStorage = CreditProgramStorage;
|
||||
}
|
||||
public List<CreditProgramViewModel>? ReadList(CreditProgramSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _CreditProgramStorage.GetFullList() : _CreditProgramStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public CreditProgramViewModel? ReadElement(CreditProgramSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _CreditProgramStorage.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(CreditProgramBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CreditProgramStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CreditProgramBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CreditProgramStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(CreditProgramBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_CreditProgramStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CreditProgramBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия валюты!", nameof(model.Name));
|
||||
}
|
||||
if (model.Persent <= 0)
|
||||
{
|
||||
throw new InvalidOperationException("Процент кредитования неположительный!");
|
||||
}
|
||||
_logger.LogInformation("Name:{ Name}. Percent: {Percent}. Id: { Id}", model.Name, model.Persent, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,10 +3,98 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BankBusinessLogic.BusinessLogics
|
||||
{
|
||||
internal class CurrencyLogic
|
||||
public class CurrencyLogic : ICurrencyLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICurrencyStorage _CurrencyStorage;
|
||||
public CurrencyLogic(ILogger<CurrencyLogic> logger, ICurrencyStorage CurrencyStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_CurrencyStorage = CurrencyStorage;
|
||||
}
|
||||
public List<CurrencyViewModel>? ReadList(CurrencySearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _CurrencyStorage.GetFullList() : _CurrencyStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public CurrencyViewModel? ReadElement(CurrencySearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _CurrencyStorage.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(CurrencyBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CurrencyStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(CurrencyBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CurrencyStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(CurrencyBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_CurrencyStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(CurrencyBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия валюты!", nameof(model.Name));
|
||||
}
|
||||
_logger.LogInformation("Name:{ Name}.Id: { Id}", model.Name, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
112
Bank/BankBusinessLogic/BusinessLogics/CurrencyPurchaseLogic.cs
Normal file
112
Bank/BankBusinessLogic/BusinessLogics/CurrencyPurchaseLogic.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using BankContracts.StoragesContracts;
|
||||
|
||||
|
||||
namespace BankBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class CurrencyPurchaseLogic : ICurrencyPurchaseLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICurrencyPurchaseStorage _CurrencyPurchaseStorage;
|
||||
public CurrencyPurchaseLogic(ILogger<CurrencyPurchaseLogic> logger, ICurrencyPurchaseStorage CurrencyPurchaseStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_CurrencyPurchaseStorage = CurrencyPurchaseStorage;
|
||||
}
|
||||
public CurrencyPurchaseViewModel? ReadElement(CurrencyPurchaseSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _CurrencyPurchaseStorage.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<CurrencyPurchaseViewModel>? ReadList(CurrencyPurchaseSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _CurrencyPurchaseStorage.GetFullList() : _CurrencyPurchaseStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public bool Create(CurrencyPurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CurrencyPurchaseStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(CurrencyPurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_CurrencyPurchaseStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(CurrencyPurchaseBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_CurrencyPurchaseStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(CurrencyPurchaseBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.BankOperatorId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Id оператора банка меньше нуля!");
|
||||
}
|
||||
if(model.CurrencyId < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Id валюты меньше нуля!");
|
||||
}
|
||||
if (model.Amount <= 0) {
|
||||
throw new InvalidOperationException("Количество закупленной валюты неположительно!");
|
||||
}
|
||||
_logger.LogInformation("Id: {Id}. Amount:{ Amount}. BankOperatorId: { BankOperatorId}. CurrencyId: {CurrencyId}.", model.Id, model.Amount, model.BankOperatorId, model.CurrencyId);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,6 @@ namespace BankContracts.SearchModels
|
||||
{
|
||||
public class CreditProgramSearchModel
|
||||
{
|
||||
int? Id { get; set; }
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BankContracts.ViewModels;
|
||||
|
||||
namespace BankContracts.StoragesContracts
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BankContracts.ViewModels;
|
||||
|
||||
namespace BankContracts.StoragesContracts
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
@ -7,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankContracts.ViewModels
|
||||
{
|
||||
public class BankOperatorViewModel
|
||||
public class BankOperatorViewModel : IBankOperatorModel
|
||||
{
|
||||
[DisplayName("Логин")]
|
||||
public string Login { get; set; } = String.Empty;
|
||||
|
@ -8,12 +8,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankContracts.ViewModels
|
||||
{
|
||||
public class CreditProgramViewModel
|
||||
public class CreditProgramViewModel : ICreditProgramModel
|
||||
{
|
||||
[DisplayName("Название кредитной программы")]
|
||||
public string Name { get; set; } = String.Empty;
|
||||
[DisplayName("Процент кредитования")]
|
||||
public int Persent { get; set; }
|
||||
public float Persent { get; set; }
|
||||
public Dictionary<int, ICurrencyModel> Currencies { get; set; } = new();
|
||||
[DisplayName("Номер программы")]
|
||||
public int Id { get; set; }
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using BankDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
@ -7,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankContracts.ViewModels
|
||||
{
|
||||
public class CurrencyPurchaseViewModel
|
||||
public class CurrencyPurchaseViewModel : ICurrencyPurchaseModel
|
||||
{
|
||||
[DisplayName("Количество валюты")]
|
||||
public float Amount { get; set; }
|
||||
|
@ -9,7 +9,7 @@ namespace BankDataModels.Models
|
||||
public interface ICreditProgramModel : IId
|
||||
{
|
||||
string Name { get;}
|
||||
int Persent { get;}
|
||||
float Persent { get;}
|
||||
Dictionary<int, ICurrencyModel> Currencies { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user