Косметика

This commit is contained in:
Programmist73 2023-05-20 04:09:55 +04:00
parent 2ddc277226
commit 3cc984e5da
9 changed files with 83 additions and 57 deletions

View File

@ -21,15 +21,12 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
private readonly IDebitingStorage _debitingStorage;
private readonly ICardStorage _cardStorage;
public CashWithdrawalLogic(ILogger<CashWithdrawalLogic> logger, ICashWithdrawalStorage cashWithdrawalStorage,
IDebitingStorage debitingStorage, ICardStorage cardStorage)
IDebitingStorage debitingStorage)
{
_logger = logger;
_cashWithdrawalStorage = cashWithdrawalStorage;
_debitingStorage = debitingStorage;
_cardStorage = cardStorage;
}
public CashWithdrawalViewModel? ReadElement(CashWithdrawalSearchModel model)
@ -81,32 +78,19 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
if (flag)
{
//проверка на то, что карта не просрочилась
if (CheckCardPeriod(model))
if (_cashWithdrawalStorage.Insert(model) == null)
{
if (_cashWithdrawalStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
_logger.LogWarning("Insert operation failed");
return false;
}
_debitingStorage.Update(new DebitingBindingModel
{
Id = model.DebitingId,
DateClose = DateTime.Now,
Status = StatusEnum.Закрыта
});
return false;
}
else
_debitingStorage.Update(new DebitingBindingModel
{
_debitingStorage.Update(new DebitingBindingModel
{
Id = model.DebitingId,
DateClose = DateTime.Now,
Status = StatusEnum.Карта_просрочена
});
}
Id = model.DebitingId,
DateClose = DateTime.Now,
Status = StatusEnum.Закрыта
});
}
else
{
@ -186,26 +170,5 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
_logger.LogInformation("CashWithdrawal: AccountId:{AccountId}. Sum:{Sum}. DateOperation:{DateOperation}. Id:{Id}",
model.AccountId, model.Sum, model.DateOperation, model?.Id);
}
bool CheckCardPeriod(CashWithdrawalBindingModel model)
{
var debiting = _debitingStorage.GetElement(new DebitingSearchModel
{
Id = model.DebitingId
});
var card = _cardStorage.GetElement(new CardSearchModel
{
Id = debiting.CardId
});
//если карта просрочена
if(card.Period < DateTime.Now)
{
return false;
}
return true;
}
}
}

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BankYouBankruptContracts.ViewModels.Client.Default;
using BankYouBankruptDataModels.Enums;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
@ -16,16 +17,27 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly ICreditingStorage _creditingStorage;
private readonly ICardStorage _cardStorage;
public CreditingLogic(ILogger<CreditingLogic> logger, ICreditingStorage creditingStorage) {
public CreditingLogic(ILogger<CreditingLogic> logger, ICreditingStorage creditingStorage, ICardStorage cardStorage) {
_logger = logger;
_creditingStorage = creditingStorage;
_cardStorage = cardStorage;
}
public bool Create(CreditingBindingModel model)
{
CheckModel(model);
if (!CheckCardPeriod(model))
{
model.Status = StatusEnum.Карта_просрочена;
}
else
{
model.Status = StatusEnum.Открыта;
}
if (_creditingStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
@ -111,5 +123,22 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
_logger.LogInformation("Crediting. Sum:{Sum}.CardId:{CardId}.Date:{date}.Id:{Id}",
model.Sum, model.CardId, model.DateOpen.ToString(), model.Id);
}
}
//проверка карты на просроченность
bool CheckCardPeriod(CreditingBindingModel model)
{
var card = _cardStorage.GetElement(new CardSearchModel
{
Id = model.CardId
});
//если карта просрочена
if (card.Period < DateTime.Now)
{
return false;
}
return true;
}
}
}

View File

@ -9,27 +9,43 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BankYouBankruptContracts.ViewModels.Client.Default;
using BankYouBankruptDataModels.Enums;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
public class DebitingLogic : IDebitingLogic
{
private readonly ILogger _logger;
private readonly IDebitingStorage _debitingStorage;
public DebitingLogic(ILogger<DebitingLogic> logger, IDebitingStorage debitingStorage) {
private readonly ICardStorage _cardStorage;
public DebitingLogic(ILogger<DebitingLogic> logger, IDebitingStorage debitingStorage, ICardStorage cardStorage) {
_logger = logger;
_debitingStorage = debitingStorage;
_cardStorage = cardStorage;
}
public bool Create(DebitingBindingModel model)
{
CheckModel(model);
if (_debitingStorage.Insert(model) == null)
if (!CheckCardPeriod(model))
{
model.Status = StatusEnum.Карта_просрочена;
}
else
{
model.Status = StatusEnum.Открыта;
}
if (_debitingStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
@ -111,5 +127,22 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
_logger.LogInformation("Debiting. Sum:{Sum}.CardId:{CardId}.DateOpen:{DateOpen}.DateOpen:{DateOpen}.Id:{Id}",
model.Sum, model.CardId, model.DateOpen.ToString(), model.DateClose.ToString(), model.Id);
}
}
//проверка карты на просроченность
bool CheckCardPeriod(DebitingBindingModel model)
{
var card = _cardStorage.GetElement(new CardSearchModel
{
Id = model.CardId
});
//если карта просрочена
if (card.Period < DateTime.Now)
{
return false;
}
return true;
}
}
}

View File

@ -1,4 +1,5 @@
@using BankYouBankruptContracts.ViewModels.Client.Default
@using BankYouBankruptDataModels.Enums;
@model List<CreditingViewModel>
@ -51,7 +52,7 @@
@Html.DisplayFor(modelItem => item.Sum)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
@item.Status.ToString().Replace("_", " ")
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOpen)

View File

@ -51,7 +51,7 @@
@Html.DisplayFor(modelItem => item.Sum)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
@item.Status.ToString().Replace("_", " ")
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOpen)

View File

@ -56,7 +56,8 @@ namespace BankYouBankruptDatabaseImplement.Models
CardId = model.CardId,
Card = context.Cards.First(x => x.Id == model.CardId),
Sum = model.Sum,
DateOpen = model.DateOpen
DateOpen = model.DateOpen,
Status = model.Status
};
}

View File

@ -51,7 +51,7 @@ namespace BankYouBankruptDatabaseImplement.Models
Card = context.Cards.First(x => x.Id == model.CardId),
Sum = model.Sum,
DateOpen = model.DateOpen,
Status = StatusEnum.Открыта
Status = model.Status
};
}

View File

@ -48,7 +48,6 @@ namespace BankYouBankruptRestApi.Controllers
}
[HttpGet]
public List<CardViewModel>? GetUsersCardsList(int id)
{