Another fix.
This commit is contained in:
parent
2b6f447621
commit
48abf8eb93
@ -67,8 +67,6 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
|
||||
//метод, отвечающий за изменение баланса счёта
|
||||
public bool ChangeBalance(AccountSearchModel? model, int sum)
|
||||
{
|
||||
try
|
||||
{
|
||||
//ищем счёт
|
||||
var account = ReadElement(model);
|
||||
@ -93,11 +91,6 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Create(AccountBindingModel model)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using BankYouBankruptContracts.BusinessLogicsContracts;
|
||||
using BankYouBankruptContracts.SearchModels;
|
||||
using BankYouBankruptContracts.StoragesContracts;
|
||||
using BankYouBankruptContracts.ViewModels;
|
||||
using BankYouBankruptDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -18,10 +19,13 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
|
||||
private readonly IMoneyTransferStorage _moneyTransferStorage;
|
||||
|
||||
public MoneyTransferLogic(ILogger<MoneyTransferLogic> logger, IMoneyTransferStorage moneyTransferStorage)
|
||||
public readonly ICreditingStorage _creditingStorage;
|
||||
|
||||
public MoneyTransferLogic(ILogger<MoneyTransferLogic> logger, IMoneyTransferStorage moneyTransferStorage, ICreditingStorage creditingStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_moneyTransferStorage = moneyTransferStorage;
|
||||
_creditingStorage = creditingStorage;
|
||||
}
|
||||
|
||||
public MoneyTransferViewModel? ReadElement(MoneyTransferSearchModel model)
|
||||
@ -78,6 +82,18 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!model.CreditingId.HasValue)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
_creditingStorage.Update(new CreditingBindingModel
|
||||
{
|
||||
Id = model.CreditingId.Value,
|
||||
DateClose = DateTime.Now,
|
||||
Status = StatusEnum.Закрыта
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,6 @@ namespace BankYouBankruptContracts.BindingModels
|
||||
|
||||
public DateTime? DateClose { get; set; }
|
||||
|
||||
public StatusEnum Status { get; set; } = StatusEnum.Открыта;
|
||||
public StatusEnum Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,15 @@ namespace BankYouBankruptDatabaseImplement.Implements
|
||||
|
||||
using var context = new BankYouBancruptDatabase();
|
||||
|
||||
if (model.Status.HasValue)
|
||||
{
|
||||
return context.Creditings
|
||||
.Include(x => x.Card)
|
||||
.Where(x => x.Status == model.Status)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.Creditings
|
||||
.Include(x => x.Card)
|
||||
.Select(x => x.GetViewModel)
|
||||
@ -90,7 +99,10 @@ namespace BankYouBankruptDatabaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
|
||||
return crediting.GetViewModel;
|
||||
return context.Creditings
|
||||
.Include(x => x.Card)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -43,7 +43,9 @@ namespace BankYouBankruptDatabaseImplement.Models
|
||||
CardId = CardId,
|
||||
CardNumber = Card.Number,
|
||||
Sum = Sum,
|
||||
DateOpen = DateOpen
|
||||
DateOpen = DateOpen,
|
||||
DateClose = DateClose,
|
||||
Status = Status
|
||||
};
|
||||
|
||||
public static Crediting Create(BankYouBancruptDatabase context, CreditingBindingModel model)
|
||||
|
@ -187,11 +187,6 @@ namespace BankYouBankruptRestApi.Controllers
|
||||
{
|
||||
_moneyTransferLogic.Create(moneyTransfer);
|
||||
|
||||
_accountLogic.ChangeBalance(new AccountSearchModel
|
||||
{
|
||||
Id = moneyTransfer.AccountPayeeId
|
||||
}, moneyTransfer.Sum);
|
||||
|
||||
//если нет отправителя, т. е. операция на перевод денег из нала в виртуал на карту
|
||||
if (moneyTransfer.AccountSenderId.HasValue)
|
||||
{
|
||||
@ -200,6 +195,11 @@ namespace BankYouBankruptRestApi.Controllers
|
||||
Id = moneyTransfer.AccountSenderId
|
||||
}, moneyTransfer.Sum * -1);
|
||||
}
|
||||
|
||||
_accountLogic.ChangeBalance(new AccountSearchModel
|
||||
{
|
||||
Id = moneyTransfer.AccountPayeeId
|
||||
}, moneyTransfer.Sum);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user