Добавление создание платежей в приложении

This commit is contained in:
abazov73 2023-04-08 00:24:07 +04:00
parent ddbda1f6ac
commit c304da164f
5 changed files with 71 additions and 6 deletions

View File

@ -87,7 +87,7 @@ namespace BankDatabaseImplement.Models
public void UpdateDeals(BankDatabase context, PaymentBindingModel model)
{
var dealPayments = context.DealPayments.Where(rec => rec.PaymentId == model.Id).ToList();
if (dealPayments != null && dealPayments.Count > 0)
if (dealPayments != null)
{
context.DealPayments.RemoveRange(dealPayments.Where(rec => !model.DealPayments.ContainsKey(rec.DealId)));
context.SaveChanges();

View File

@ -2,6 +2,7 @@
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
@ -44,6 +45,19 @@ namespace BankRestApi.Controllers
throw;
}
}
[HttpGet]
public DealViewModel? GetDeal(int id)
{
try
{
return _deal.ReadElement(new DealSearchModel { Id = id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения сделки id={id}", id);
throw;
}
}
[HttpPost]
public void CreateDeal(DealBindingModel model)

View File

@ -2,6 +2,7 @@
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
@ -44,6 +45,19 @@ namespace BankRestApi.Controllers
throw;
}
}
[HttpGet]
public PaymentViewModel? GetPayment(int paymentId)
{
try
{
return _payment.ReadElement(new PaymentSearchModel { Id = paymentId});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения выплаты id={paymentId}", paymentId);
throw;
}
}
[HttpPost]
public void CreatePayment(PaymentBindingModel model)
@ -58,6 +72,24 @@ namespace BankRestApi.Controllers
throw;
}
}
[HttpPost]
public void AddDealToPayment(DealViewModel deal, int paymentId)
{
var payment = GetPayment(paymentId);
if (payment == null)
{
throw new InvalidOperationException("Платеж не найден!");
}
payment.DealPayments.Add(deal.Id, deal);
_payment.Update(new PaymentBindingModel
{
Id = payment.Id,
OperatorId = payment.OperatorId,
CurrencyPayments = payment.CurrencyPayments,
DealPayments = payment.DealPayments,
PaymentDate = payment.PaymentDate,
});
}
[HttpPatch]
public void UpdatePayment(PaymentBindingModel model)

View File

@ -1,6 +1,9 @@
using BankContracts.BindingModels;
using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using BankDataModels.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata;
using OperatorApp.Models;
using System.Diagnostics;
@ -149,18 +152,34 @@ namespace OperatorApp.Controllers
return View();
}
[HttpPost]
public void CreatePayment(int clientid)
public void CreatePayment(List<int> deals)
{
if (APIClient.Operator == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/deal/createdeal", new PaymentBindingModel
Dictionary<int, ICurrencyModel> CurrencyPayments = new();
//foreach (int id in deals)
//{
// var deal = APIClient.GetRequest<DealViewModel>($"api/deal/getdeal?id={id}");
// if (deal != null) CurrencyPayments.Add(deal.Id, deal as IModel);
//}
APIClient.PostRequest("api/payment/createpayment", new PaymentBindingModel
{
OperatorId = APIClient.Operator.Id,
});
Response.Redirect("Index");
var payments = APIClient.GetRequest<List<PaymentViewModel>>("api/payment/getpaymentslist");
int addedPaymentId = payments == null ? 1 : payments[payments.Count - 1].Id;
foreach (int id in deals)
{
var deal = APIClient.GetRequest<DealViewModel>($"api/deal/getdeal?id={id}");
if (deal != null)
{
APIClient.PostRequest<DealViewModel>($"api/payment/adddealtopayment?paymentId={addedPaymentId}", deal);
}
}
Response.Redirect("Payments");
}
}
}

View File

@ -8,7 +8,7 @@
<div class="row">
<div class="col-4">Сделки:</div>
<div class="col-8">
<select id="deals" name="deals" class="form-control" asp-items="@(new SelectList(@ViewBag.Deals,"Id", "DealDate"))"></select>
<select id="deals" name="deals" class="form-control" multiple asp-items="@(new SelectList(@ViewBag.Deals,"Id", "DealDate"))"></select>
</div>
</div>
<div class="row">