diff --git a/Bank/BankDatabaseImplement/Implements/OperationStorage.cs b/Bank/BankDatabaseImplement/Implements/OperationStorage.cs index 07e5085..9c4a430 100644 --- a/Bank/BankDatabaseImplement/Implements/OperationStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/OperationStorage.cs @@ -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); diff --git a/Bank/BankDatabaseImplement/Implements/RequestStorage.cs b/Bank/BankDatabaseImplement/Implements/RequestStorage.cs index c529353..086bae4 100644 --- a/Bank/BankDatabaseImplement/Implements/RequestStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/RequestStorage.cs @@ -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);