Compare commits
2 Commits
46a7483dc7
...
68cd7db894
Author | SHA1 | Date | |
---|---|---|---|
68cd7db894 | |||
f7436c0d17 |
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user