fix withdrawal logic in storage p.1

This commit is contained in:
Zakharov_Rostislav 2024-05-26 19:35:28 +04:00
parent 42c893e105
commit c95baa32e2

View File

@ -59,13 +59,54 @@ namespace BankDatabaseImplement.Implements
using var context = new BankDatabase();
var newWithdrawal = Withdrawal.Create(context, model);
if (newWithdrawal == null)
{
return null;
using var transaction = context.Database.BeginTransaction();
try
{
//MakeWithdrawal(context, model);
context.Withdrawals.Add(newWithdrawal);
}
context.Withdrawals.Add(newWithdrawal);
catch
{
transaction.Rollback();
throw;
}
context.SaveChanges();
return newWithdrawal.GetViewModel;
}
transaction.Commit();
return newWithdrawal.GetViewModel;
}
//private bool MakeWithdrawal(BankDatabase context, WithdrawalBindingModel model)
//{
// if (model == null)
// return false;
// var dictionary = model.WithdrawalAccounts;
// int count = model.Sum;
// foreach (var el in dictionary)
// {
// int dif = count;
// if (el.Count < dif)
// dif = el.Count;
// el.Count -= dif;
// count -= dif;
// if (el.Count == 0)
// {
// dictionary.Add(el);
// }
// if (count == 0)
// break;
// }
// if (count > 0)
// {
// transaction.Rollback();
// return false;
// }
// foreach (var el in dictionary)
// {
// context.ShopManufactures.Remove(el);
// }
// return true;
//}
public WithdrawalViewModel? Update(WithdrawalBindingModel model)
{