Merge branch 'ManagersApp' of https://git.is.ulstu.ru/Artyom_Yashin/PIbd-23_Yashin_A_Zakharov_R_CourseWork_Bank into ManagersApp
This commit is contained in:
commit
135fde1a80
@ -117,18 +117,18 @@ namespace BankDatabaseImplement.Implements
|
||||
using var context = new BankDatabase();
|
||||
return context.Accounts
|
||||
.Where(a => model.SelectedAccountIds == null || model.SelectedAccountIds.Contains(a.Id))
|
||||
.Select(a => new ReportRequestsViewModel()
|
||||
.Select(account => new ReportRequestsViewModel()
|
||||
{
|
||||
AccountNumber = a.Number,
|
||||
Requests = context.Requests
|
||||
.Include(x => x.Withdrawal)
|
||||
.ThenInclude(x => x.Accounts)
|
||||
.Where(x => x.Withdrawal != null && x.Withdrawal.Accounts
|
||||
.Select(x => x.AccountId)
|
||||
.ToList()
|
||||
.Contains(a.Id))
|
||||
.Select (r => r.GetViewModel)
|
||||
.ToList()
|
||||
AccountNumber = account.Number,
|
||||
Requests = context.AccountWithdrawals
|
||||
.Include(x => x.Withdrawal)
|
||||
.ThenInclude(x => x.Request)
|
||||
.Where(x => x.AccountId == account.Id)
|
||||
.Select(x => x.Withdrawal)
|
||||
.Where(x => x.RequestId != null)
|
||||
.Select(x => x.Request)
|
||||
.Select(r => r.GetViewModel)
|
||||
.ToList(),
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
@ -77,44 +77,6 @@ namespace BankDatabaseImplement.Implements
|
||||
return newWithdrawal.GetViewModel;
|
||||
}
|
||||
|
||||
private void MakeWithdrawal(BankDatabase context, WithdrawalBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
int count = model.Sum;
|
||||
if (count == 0)
|
||||
return;
|
||||
var dictionary = model.WithdrawalAccounts;
|
||||
var keys = dictionary.Keys;
|
||||
foreach (int key in keys)
|
||||
{
|
||||
(IAccountModel, int) value = new();
|
||||
bool result = dictionary.TryGetValue(key, out value);
|
||||
if (!result)
|
||||
throw new InvalidOperationException("Value was not got");
|
||||
Account account = context.Accounts.FirstOrDefault(x => x.Id == key) ??
|
||||
throw new InvalidOperationException("Needed account was not found");
|
||||
int dif = count;
|
||||
if (account.Money < dif)
|
||||
dif = account.Money;
|
||||
value.Item2 = dif;
|
||||
dictionary[key] = value;
|
||||
count -= dif;
|
||||
account.Update(new AccountBindingModel
|
||||
{
|
||||
Id = account.Id,
|
||||
Number = account.Number,
|
||||
ReleaseDate = account.ReleaseDate,
|
||||
ManagerId = account.ManagerId,
|
||||
Money = account.Money - dif,
|
||||
});
|
||||
if (count == 0)
|
||||
break;
|
||||
}
|
||||
if (count > 0)
|
||||
throw new InvalidOperationException("The accounts did not have enough money");
|
||||
}
|
||||
|
||||
public WithdrawalViewModel? Update(WithdrawalBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
@ -122,22 +84,20 @@ namespace BankDatabaseImplement.Implements
|
||||
Withdrawal? withdrawal;
|
||||
try
|
||||
{
|
||||
withdrawal = context.Withdrawals.FirstOrDefault(rec =>
|
||||
rec.Id == model.Id);
|
||||
withdrawal = context.Withdrawals.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (withdrawal == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
withdrawal.Update(model);
|
||||
context.SaveChanges();
|
||||
throw new InvalidOperationException("Updating withdrawal was not found");
|
||||
withdrawal.Update(model);
|
||||
MakeWithdrawal(context, model);
|
||||
withdrawal.UpdateAccounts(context, model);
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return withdrawal.GetViewModel;
|
||||
}
|
||||
|
||||
@ -180,6 +140,44 @@ namespace BankDatabaseImplement.Implements
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MakeWithdrawal(BankDatabase context, WithdrawalBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
int count = model.Sum;
|
||||
if (count == 0)
|
||||
return;
|
||||
var dictionary = model.WithdrawalAccounts;
|
||||
var keys = dictionary.Keys;
|
||||
foreach (int key in keys)
|
||||
{
|
||||
(IAccountModel, int) value = new();
|
||||
bool result = dictionary.TryGetValue(key, out value);
|
||||
if (!result)
|
||||
throw new InvalidOperationException("Value was not got");
|
||||
Account account = context.Accounts.FirstOrDefault(x => x.Id == key) ??
|
||||
throw new InvalidOperationException("Needed account was not found");
|
||||
int dif = count;
|
||||
if (account.Money < dif)
|
||||
dif = account.Money;
|
||||
value.Item2 = dif;
|
||||
dictionary[key] = value;
|
||||
count -= dif;
|
||||
account.Update(new AccountBindingModel
|
||||
{
|
||||
Id = account.Id,
|
||||
Number = account.Number,
|
||||
ReleaseDate = account.ReleaseDate,
|
||||
ManagerId = account.ManagerId,
|
||||
Money = account.Money - dif,
|
||||
});
|
||||
if (count == 0)
|
||||
break;
|
||||
}
|
||||
if (count > 0)
|
||||
throw new InvalidOperationException("The accounts did not have enough money");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,16 +86,17 @@ namespace BankDatabaseImplement.Models
|
||||
context.SaveChanges();
|
||||
foreach (var wa in WithdrawalAccounts)
|
||||
{
|
||||
wa.Sum = model.WithdrawalAccounts[wa.AccountId].Item2;
|
||||
model.WithdrawalAccounts.Remove(wa.AccountId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var Withdrawal = context.Withdrawals.First(x => x.Id == Id);
|
||||
var withdrawal = context.Withdrawals.First(x => x.Id == Id);
|
||||
foreach (var account in model.WithdrawalAccounts)
|
||||
{
|
||||
context.AccountWithdrawals.Add(new AccountWithdrawal
|
||||
{
|
||||
Withdrawal = Withdrawal,
|
||||
Withdrawal = withdrawal,
|
||||
Account = context.Accounts.First(x => x.Id == account.Key),
|
||||
Sum = account.Value.Item2,
|
||||
});
|
||||
|
@ -486,18 +486,21 @@ namespace BankManagersClientApp.Controllers
|
||||
case "word":
|
||||
APIClient.PostRequest("/api/report/saverequeststoword", new ReportBindingModel
|
||||
{
|
||||
SelectedAccountIds = accounts
|
||||
SelectedAccountIds = accounts,
|
||||
FileName = "C:\\Users\\user\\Downloads\\RequestList.docx",
|
||||
});
|
||||
break;
|
||||
case "excel":
|
||||
APIClient.PostRequest("/api/report/saverequeststoexcel", new ReportBindingModel
|
||||
{
|
||||
SelectedAccountIds = accounts
|
||||
SelectedAccountIds = accounts,
|
||||
FileName = "C:\\Users\\user\\Downloads\\RequestList.docx",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
@ -20,7 +20,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<input id="word" type="radio" name="format" value="word" />
|
||||
<input id="word" type="radio" name="format" value="word" checked />
|
||||
<label for="word">Получать в формате Word</label>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -18,9 +18,17 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void SaveRequestsToWord(ReportBindingModel? model)
|
||||
public void SaveRequestsToWord(ReportBindingModel model)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
_logic.SaveRequestsToWordFile(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения переводов в ворд");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void SaveRequestsToExcel(ReportBindingModel? model)
|
||||
|
Loading…
Reference in New Issue
Block a user