Compare commits

...

2 Commits

3 changed files with 21 additions and 3 deletions

View File

@ -55,6 +55,11 @@ namespace BankDatabaseImplement.Implements
{
using var context = new BankDatabase();
var operation = context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).Include(x => x.Transfer).FirstOrDefault(x => x.Id == model.Id);
var transfer = context.Transfers.FirstOrDefault(x => x.OperationId == model.Id);
if (transfer != null)
{
return null;
}
if (operation == null)
{
return null;
@ -67,6 +72,11 @@ namespace BankDatabaseImplement.Implements
{
using var context = new BankDatabase();
var operation = context.Operations.Include(x => x.SenderCard).Include(x => x.RecipientCard).Include(x => x.Transfer).FirstOrDefault(rec => rec.Id == model.Id);
var transfer = context.Transfers.FirstOrDefault(x => x.OperationId == model.Id);
if (transfer != null)
{
return null;
}
if (operation != null)
{
context.Operations.Remove(operation);

View File

@ -73,7 +73,11 @@ namespace BankDatabaseImplement.Implements
var Request = context.Requests.FirstOrDefault(rec => rec.Id == model.Id);
if (Request == null)
{
return null;
throw new Exception("Заявка не найдена");
}
if (Request.Status != RequestStatus.Принята)
{
throw new InvalidOperationException("Заявка уже выполнена");
}
Request.Update(model);
context.SaveChanges();
@ -93,6 +97,10 @@ namespace BankDatabaseImplement.Implements
var element = context.Requests
.Include(x => x.Cards)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element?.Status != RequestStatus.Принята)
{
return null;
}
if (element != null)
{
context.Requests.Remove(element);

View File

@ -57,11 +57,11 @@ namespace BankDatabaseImplement.Models
Sum = model.Sum;
}
public bool ChangeStatus(RequestStatus status)
public bool Execute()
{
if(Status == RequestStatus.Принята)
{
Status = status;
Status = RequestStatus.Выполнена;
return true;
}
return false;