Compare commits

...

2 Commits

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) public void UpdateDeals(BankDatabase context, PaymentBindingModel model)
{ {
var dealPayments = context.DealPayments.Where(rec => rec.PaymentId == model.Id).ToList(); 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.DealPayments.RemoveRange(dealPayments.Where(rec => !model.DealPayments.ContainsKey(rec.DealId)));
context.SaveChanges(); context.SaveChanges();

View File

@ -2,6 +2,7 @@
using BankContracts.BusinessLogicsContracts; using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels; using BankContracts.SearchModels;
using BankContracts.ViewModels; using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers namespace BankRestApi.Controllers
@ -44,6 +45,19 @@ namespace BankRestApi.Controllers
throw; 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] [HttpPost]
public void CreateDeal(DealBindingModel model) public void CreateDeal(DealBindingModel model)

View File

@ -2,6 +2,7 @@
using BankContracts.BusinessLogicsContracts; using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels; using BankContracts.SearchModels;
using BankContracts.ViewModels; using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers namespace BankRestApi.Controllers
@ -44,6 +45,19 @@ namespace BankRestApi.Controllers
throw; 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] [HttpPost]
public void CreatePayment(PaymentBindingModel model) public void CreatePayment(PaymentBindingModel model)
@ -58,6 +72,24 @@ namespace BankRestApi.Controllers
throw; 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] [HttpPatch]
public void UpdatePayment(PaymentBindingModel model) public void UpdatePayment(PaymentBindingModel model)

View File

@ -1,6 +1,9 @@
using BankContracts.BindingModels; using BankContracts.BindingModels;
using BankContracts.ViewModels; using BankContracts.ViewModels;
using BankDatabaseImplement.Models;
using BankDataModels.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata;
using OperatorApp.Models; using OperatorApp.Models;
using System.Diagnostics; using System.Diagnostics;
@ -149,18 +152,34 @@ namespace OperatorApp.Controllers
return View(); return View();
} }
[HttpPost] [HttpPost]
public void CreatePayment(int clientid) public void CreatePayment(List<int> deals)
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); 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, 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="row">
<div class="col-4">Сделки:</div> <div class="col-4">Сделки:</div>
<div class="col-8"> <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> </div>
<div class="row"> <div class="row">