diff --git a/Bank/BankBusinessLogic/BankBusinessLogic.csproj b/Bank/BankBusinessLogic/BankBusinessLogic.csproj index 27ac386..70a5c88 100644 --- a/Bank/BankBusinessLogic/BankBusinessLogic.csproj +++ b/Bank/BankBusinessLogic/BankBusinessLogic.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/Bank/BankBusinessLogic/BusinessLogics/BankOperatorLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/BankOperatorLogic.cs new file mode 100644 index 0000000..d51e075 --- /dev/null +++ b/Bank/BankBusinessLogic/BusinessLogics/BankOperatorLogic.cs @@ -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 logger, IBankOperatorStorage BankOperatorStorage) + { + _logger = logger; + _BankOperatorStorage = BankOperatorStorage; + } + public List? 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); + } + } +} diff --git a/Bank/BankBusinessLogic/BusinessLogics/CreditProgramLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/CreditProgramLogic.cs new file mode 100644 index 0000000..6088dd0 --- /dev/null +++ b/Bank/BankBusinessLogic/BusinessLogics/CreditProgramLogic.cs @@ -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 logger, ICreditProgramStorage CreditProgramStorage) + { + _logger = logger; + _CreditProgramStorage = CreditProgramStorage; + } + public List? 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); + } + } +} diff --git a/Bank/BankBusinessLogic/BusinessLogics/CurrencyLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/CurrencyLogic.cs index 0c7d8a4..4418579 100644 --- a/Bank/BankBusinessLogic/BusinessLogics/CurrencyLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogics/CurrencyLogic.cs @@ -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 logger, ICurrencyStorage CurrencyStorage) + { + _logger = logger; + _CurrencyStorage = CurrencyStorage; + } + public List? 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); + } } } diff --git a/Bank/BankBusinessLogic/BusinessLogics/CurrencyPurchaseLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/CurrencyPurchaseLogic.cs new file mode 100644 index 0000000..64eae3b --- /dev/null +++ b/Bank/BankBusinessLogic/BusinessLogics/CurrencyPurchaseLogic.cs @@ -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 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? 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); + } + } +} diff --git a/Bank/BankContracts/SearchModels/CreditProgramSearchModel.cs b/Bank/BankContracts/SearchModels/CreditProgramSearchModel.cs index f437982..3791aeb 100644 --- a/Bank/BankContracts/SearchModels/CreditProgramSearchModel.cs +++ b/Bank/BankContracts/SearchModels/CreditProgramSearchModel.cs @@ -8,6 +8,6 @@ namespace BankContracts.SearchModels { public class CreditProgramSearchModel { - int? Id { get; set; } + public int? Id { get; set; } } } diff --git a/Bank/BankContracts/StoragesContracts/ICreditProgramStorage.cs b/Bank/BankContracts/StoragesContracts/ICreditProgramStorage.cs index 0fa48cd..002e96d 100644 --- a/Bank/BankContracts/StoragesContracts/ICreditProgramStorage.cs +++ b/Bank/BankContracts/StoragesContracts/ICreditProgramStorage.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BankContracts.ViewModels; namespace BankContracts.StoragesContracts { diff --git a/Bank/BankContracts/StoragesContracts/ICurrencyPurchaseStorage.cs b/Bank/BankContracts/StoragesContracts/ICurrencyPurchaseStorage.cs index 9ba3a5a..52f068b 100644 --- a/Bank/BankContracts/StoragesContracts/ICurrencyPurchaseStorage.cs +++ b/Bank/BankContracts/StoragesContracts/ICurrencyPurchaseStorage.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BankContracts.ViewModels; namespace BankContracts.StoragesContracts { diff --git a/Bank/BankContracts/ViewModels/BankOperatorViewModel.cs b/Bank/BankContracts/ViewModels/BankOperatorViewModel.cs index ef2d8f8..d637c4e 100644 --- a/Bank/BankContracts/ViewModels/BankOperatorViewModel.cs +++ b/Bank/BankContracts/ViewModels/BankOperatorViewModel.cs @@ -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; diff --git a/Bank/BankContracts/ViewModels/CreditProgramViewModel.cs b/Bank/BankContracts/ViewModels/CreditProgramViewModel.cs index 49c1678..966dc8b 100644 --- a/Bank/BankContracts/ViewModels/CreditProgramViewModel.cs +++ b/Bank/BankContracts/ViewModels/CreditProgramViewModel.cs @@ -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 Currencies { get; set; } = new(); [DisplayName("Номер программы")] public int Id { get; set; } diff --git a/Bank/BankContracts/ViewModels/CurrencyPurchaseViewModel.cs b/Bank/BankContracts/ViewModels/CurrencyPurchaseViewModel.cs index cb17f00..eac2c69 100644 --- a/Bank/BankContracts/ViewModels/CurrencyPurchaseViewModel.cs +++ b/Bank/BankContracts/ViewModels/CurrencyPurchaseViewModel.cs @@ -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; } diff --git a/Bank/BankDataModels/Models/ICreditProgramModel.cs b/Bank/BankDataModels/Models/ICreditProgramModel.cs index a3af93a..5ebc21c 100644 --- a/Bank/BankDataModels/Models/ICreditProgramModel.cs +++ b/Bank/BankDataModels/Models/ICreditProgramModel.cs @@ -9,7 +9,7 @@ namespace BankDataModels.Models public interface ICreditProgramModel : IId { string Name { get;} - int Persent { get;} + float Persent { get;} Dictionary Currencies { get; } } }