Controllers для роли Поставщик. Фикс GetElement в BankOperatorStorage. Добавление Password в соответствующую SearchModel.

This commit is contained in:
ksenianeva 2023-04-07 19:27:26 +04:00
parent ca1680640e
commit eae5828619
6 changed files with 382 additions and 5 deletions

View File

@ -10,5 +10,6 @@ namespace BankContracts.SearchModels
{
public int? Id { get; set; }
public string? Login { get; set; }
public string? Password { get; set; }
}
}

View File

@ -28,14 +28,24 @@ namespace BankDatabaseImplement.Implements
public BankOperatorViewModel? GetElement(BankOperatorSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new BankDatabase();
return context.BankOperators
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password))
{
using var context = new BankDatabase();
return context.BankOperators
.FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password)
?.GetViewModel;
}
else
{
using var context = new BankDatabase();
return context.BankOperators
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
public List<BankOperatorViewModel> GetFilteredList(BankOperatorSearchModel model)

View File

@ -0,0 +1,86 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class BankOperatorController : Controller
{
private readonly ILogger _logger;
private readonly IBankOperatorLogic _bankOperator;
public BankOperatorController(ILogger<BankOperatorController> logger, IBankOperatorLogic bankOperatorC)
{
_logger = logger;
_bankOperator = bankOperatorC;
}
[HttpGet]
public BankOperatorViewModel? Login(string login, string password)
{
try
{
return _bankOperator.ReadElement(new BankOperatorSearchModel
{
Login = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void CreateBankOperator(BankOperatorBindingModel model)
{
try
{
_bankOperator.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания зачисления");
throw;
}
}
[HttpPatch]
public void UpdateBankOperator(BankOperatorBindingModel model)
{
try
{
_bankOperator.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления зачисления");
throw;
}
}
[HttpDelete]
public void DeleteBankOperator(int bankOperatorId)
{
try
{
BankOperatorBindingModel model = new BankOperatorBindingModel
{
Id = bankOperatorId
};
_bankOperator.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления зачисления");
throw;
}
}
}
}

View File

@ -0,0 +1,94 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CreditProgramController : Controller
{
private readonly ILogger _logger;
private readonly ICreditProgramLogic _creditProgram;
public CreditProgramController(ILogger<CreditProgramController> logger, ICreditProgramLogic creditProgram)
{
_logger = logger;
_creditProgram = creditProgram;
}
[HttpGet]
public List<CreditProgramViewModel>? GetCreditProgramsList()
{
try
{
return _creditProgram.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка кредитных программ");
throw;
}
}
[HttpGet]
public List<CreditProgramViewModel>? GetCreditPrograms(int bankOperatorId)
{
try
{
return _creditProgram.ReadList(new CreditProgramSearchModel { BankOperatorId = bankOperatorId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка кредитных программ оператора id={Id}", bankOperatorId);
throw;
}
}
[HttpPost]
public void CreateCreditProgram(CreditProgramBindingModel model)
{
try
{
_creditProgram.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания кредитной программы");
throw;
}
}
[HttpPatch]
public void UpdateCreditProgram(CreditProgramBindingModel model)
{
try
{
_creditProgram.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления кредитной программы");
throw;
}
}
[HttpDelete]
public void DeleteCreditProgram(int creditProgramId)
{
try
{
CreditProgramBindingModel model = new CreditProgramBindingModel
{
Id = creditProgramId,
};
_creditProgram.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления кредитной программы");
throw;
}
}
}
}

View File

@ -0,0 +1,93 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CurrencyController : Controller
{
private readonly ILogger _logger;
private readonly ICurrencyLogic _currency;
public CurrencyController(ILogger<CurrencyController> logger, ICurrencyLogic currency)
{
_logger = logger;
_currency = currency;
}
[HttpGet]
public List<CurrencyViewModel>? GetCurrencysList()
{
try
{
return _currency.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка валют");
throw;
}
}
[HttpGet]
public List<CurrencyViewModel>? GetCurrencys(int bankOperatorId)
{
try
{
return _currency.ReadList(new CurrencySearchModel { BankOperatorId = bankOperatorId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка валют оператора id={Id}", bankOperatorId);
throw;
}
}
[HttpPost]
public void CreateCurrency(CurrencyBindingModel model)
{
try
{
_currency.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания валюты");
throw;
}
}
[HttpPatch]
public void UpdateCurrency(CurrencyBindingModel model)
{
try
{
_currency.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления валюты");
throw;
}
}
[HttpDelete]
public void DeleteCurrency(int currencyId)
{
try
{
CurrencyBindingModel model = new CurrencyBindingModel
{
Id = currencyId,
};
_currency.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления валюты");
throw;
}
}
}
}

View File

@ -0,0 +1,93 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CurrencyPurchaseController : Controller
{
private readonly ILogger _logger;
private readonly ICurrencyPurchaseLogic _currencyPurchase;
public CurrencyPurchaseController(ILogger<CurrencyPurchaseController> logger, ICurrencyPurchaseLogic currencyPurchase)
{
_logger = logger;
_currencyPurchase = currencyPurchase;
}
[HttpGet]
public List<CurrencyPurchaseViewModel>? GetCurrencyPurchasesList()
{
try
{
return _currencyPurchase.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка закупки валют");
throw;
}
}
[HttpGet]
public List<CurrencyPurchaseViewModel>? GetCurrencyPurchases(int bankOperatorId)
{
try
{
return _currencyPurchase.ReadList(new CurrencyPurchaseSearchModel { BankOperatorId = bankOperatorId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка закупки валют оператора id={Id}", bankOperatorId);
throw;
}
}
[HttpPost]
public void CreateCurrencyPurchase(CurrencyPurchaseBindingModel model)
{
try
{
_currencyPurchase.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания закупки валют");
throw;
}
}
[HttpPatch]
public void UpdateCurrencyPurchase(CurrencyPurchaseBindingModel model)
{
try
{
_currencyPurchase.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления закупки валют");
throw;
}
}
[HttpDelete]
public void DeleteCurrencyPurchase(int currencyPurchaseId)
{
try
{
CurrencyPurchaseBindingModel model = new CurrencyPurchaseBindingModel
{
Id = currencyPurchaseId,
};
_currencyPurchase.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления закупки валют");
throw;
}
}
}
}