Pay fix
This commit is contained in:
parent
ae632c5cb4
commit
5c574a0dec
@ -89,7 +89,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
public bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption) {
|
public bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption) {
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
model.PayOption = paymeantOption;
|
model.PayOption = paymeantOption;
|
||||||
if (_storage.UpdatePay == null) {
|
if (_storage.UpdatePay(model) == null) {
|
||||||
_logger.LogWarning("update operation failed");
|
_logger.LogWarning("update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ namespace ElectronicsShopContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? ID { get; set; }
|
public int? ID { get; set; }
|
||||||
public int? OrderID { get; set; }
|
public int? OrderID { get; set; }
|
||||||
public double? SumPay { get; set; }
|
|
||||||
public int? ClientID { get; set; }
|
public int? ClientID { get; set; }
|
||||||
public DateTime? DateFrom{ get; set; }
|
public DateTime? DateFrom{ get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime? DateTo { get; set; }
|
||||||
|
@ -32,6 +32,7 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
|||||||
if (order == null) {
|
if (order == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
order.Update(model);
|
||||||
order.UpdateProducts(context, model);
|
order.UpdateProducts(context, model);
|
||||||
transcation.Commit();
|
transcation.Commit();
|
||||||
return order.GetViewModel;
|
return order.GetViewModel;
|
||||||
|
@ -25,7 +25,6 @@ namespace ElectronicsShopDataBaseImplement.Implements {
|
|||||||
return newPayment.GetViewModel;
|
return newPayment.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo тут должен меняться статус оплаты
|
|
||||||
public PaymeantViewModel? UpdatePay(PaymeantBindingModel model) {
|
public PaymeantViewModel? UpdatePay(PaymeantBindingModel model) {
|
||||||
using var context = new Database();
|
using var context = new Database();
|
||||||
var paymeant = context.Paymeants.FirstOrDefault(x => x.ID == model.ID);
|
var paymeant = context.Paymeants.FirstOrDefault(x => x.ID == model.ID);
|
||||||
@ -39,7 +38,11 @@ namespace ElectronicsShopDataBaseImplement.Implements {
|
|||||||
|
|
||||||
public PaymeantViewModel? GetElement(PaymeantSearchModel model) {
|
public PaymeantViewModel? GetElement(PaymeantSearchModel model) {
|
||||||
using var context = new Database();
|
using var context = new Database();
|
||||||
return context.Paymeants.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
|
if (model.OrderID.HasValue) {
|
||||||
|
return context.Paymeants.FirstOrDefault(x => x.OrderID == model.OrderID)?.GetViewModel;
|
||||||
|
}
|
||||||
|
return context.Paymeants
|
||||||
|
.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaymeantViewModel> GetFillteredList(PaymeantSearchModel model) {
|
public List<PaymeantViewModel> GetFillteredList(PaymeantSearchModel model) {
|
||||||
@ -50,9 +53,16 @@ namespace ElectronicsShopDataBaseImplement.Implements {
|
|||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
else if (model.ClientID.HasValue) {
|
||||||
|
|
||||||
return context.Paymeants
|
return context.Paymeants
|
||||||
.Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList();
|
.Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
return context.Paymeants
|
||||||
|
.Where(x => x.OrderID == model.OrderID)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public List<PaymeantViewModel>? GetFullList() {
|
public List<PaymeantViewModel>? GetFullList() {
|
||||||
using var context = new Database();
|
using var context = new Database();
|
||||||
|
@ -8,6 +8,7 @@ using ElectronicsShopContracts.SearchModels;
|
|||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
using ElectronicsShopDataBaseImplement.Models;
|
using ElectronicsShopDataBaseImplement.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.Identity.Client;
|
using Microsoft.Identity.Client;
|
||||||
using MigraDoc.Rendering;
|
using MigraDoc.Rendering;
|
||||||
|
|
||||||
@ -74,19 +75,64 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void CreatePaymeant (PaymeantBindingModel model) {
|
public void CreatePaymeant (PaymeantBindingModel model) {
|
||||||
try {
|
try {
|
||||||
|
if (_payLogic.ReadList(new PaymeantSearchModel { OrderID = model.OrderID })?.Count > 0) {
|
||||||
|
var order = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID });
|
||||||
|
|
||||||
|
if (order == null) {
|
||||||
|
throw new Exception("Ошибка получения данных");
|
||||||
|
}
|
||||||
|
|
||||||
|
_orderLogic.Update(new OrderBindingModel {
|
||||||
|
ID = order.ID,
|
||||||
|
ClientID = order.ClientID,
|
||||||
|
DateCreate = order.DateCreate,
|
||||||
|
Sum = order.Sum - model.SumPayment,
|
||||||
|
ProductList = order.ProductList,
|
||||||
|
});
|
||||||
|
|
||||||
|
var payemeant = _payLogic.ReadElement(new PaymeantSearchModel { OrderID = model.OrderID })
|
||||||
|
?? throw new Exception("Ошибка получения оплаты");
|
||||||
|
payemeant.SumPayment += model.SumPayment;
|
||||||
|
|
||||||
|
_payLogic.SetStatus(new PaymeantBindingModel {
|
||||||
|
ID = payemeant.ID,
|
||||||
|
OrderID = payemeant.OrderID,
|
||||||
|
SumPayment = payemeant.SumPayment,
|
||||||
|
PayOption = payemeant.PayOption,
|
||||||
|
ClientID = payemeant.ClientID,
|
||||||
|
DatePaymeant = payemeant.DatePaymeant,
|
||||||
|
PayProductList = payemeant.PayProductList,
|
||||||
|
}, model.PayOption);
|
||||||
|
}
|
||||||
|
else {
|
||||||
var products = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID })?.ProductList;
|
var products = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID })?.ProductList;
|
||||||
|
|
||||||
if (products == null) {
|
if (products == null) {
|
||||||
throw new Exception("Ошибка получения товаров");
|
throw new Exception("Ошибка получения данных");
|
||||||
}
|
}
|
||||||
|
|
||||||
model.PayProductList = products;
|
model.PayProductList = products;
|
||||||
_payLogic.CreatePay(model);
|
_payLogic.CreatePay(model);
|
||||||
|
|
||||||
if (model.PayOption == 0) {
|
|
||||||
_orderLogic.Delete(new OrderBindingModel { ID = model.OrderID});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (model.PayOption == 0) {
|
||||||
|
_orderLogic.Delete(new OrderBindingModel { ID = model.OrderID });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var order = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID });
|
||||||
|
|
||||||
|
if (order == null) {
|
||||||
|
throw new Exception("Ошибка получения данных");
|
||||||
|
}
|
||||||
|
|
||||||
|
_orderLogic.Update(new OrderBindingModel {
|
||||||
|
ID = order.ID,
|
||||||
|
ClientID = order.ClientID,
|
||||||
|
DateCreate = order.DateCreate,
|
||||||
|
Sum = order.Sum - model.SumPayment,
|
||||||
|
ProductList = order.ProductList,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
_logger.LogError(ex, "Ошибка создания оплаты");
|
_logger.LogError(ex, "Ошибка создания оплаты");
|
||||||
|
@ -82,8 +82,11 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public OrderViewModel? GetOrder(int _clientID) {
|
public OrderViewModel? GetOrder(int? _clientID, int? _orderID) {
|
||||||
try {
|
try {
|
||||||
|
if (_orderID.HasValue) {
|
||||||
|
return _order.ReadElement(new OrderSearchModel { ID = _orderID });
|
||||||
|
}
|
||||||
return _order.ReadElement(new OrderSearchModel { ClientID = _clientID });
|
return _order.ReadElement(new OrderSearchModel { ClientID = _clientID });
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
Binary file not shown.
@ -235,7 +235,10 @@ namespace ElectronicsShopUserApp.Controllers {
|
|||||||
_productList.Add(product.ID, (product, count));
|
_productList.Add(product.ID, (product, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
(int, Dictionary<int, (IProductModel, int)>) tuple = (id, _productList);
|
double sum = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_orderid={id}").Sum;
|
||||||
|
|
||||||
|
|
||||||
|
(double ,int, Dictionary<int, (IProductModel, int)>) tuple = (sum, id, _productList);
|
||||||
return View(tuple);
|
return View(tuple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
@using ElectronicsShopContracts.ViewModels
|
@using ElectronicsShopContracts.ViewModels
|
||||||
@using ElectronicsShopDataModels.Models
|
@using ElectronicsShopDataModels.Models
|
||||||
|
|
||||||
@model (int, Dictionary<int, (IProductModel, int)>)
|
@model (double, int, Dictionary<int, (IProductModel, int)>)
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Payment";
|
ViewData["Title"] = "Payment";
|
||||||
@ -15,7 +15,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">
|
||||||
<input id="id" type="hidden" name="id" readonly value="@Model.Item1" />
|
<input id="id" type="hidden" name="id" readonly value="@Model.Item2" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class=" text-center">
|
<div class=" text-center">
|
||||||
@ -29,7 +29,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">
|
||||||
<input type="text" name="sum" id="sum" readonly />
|
<input type="text" name="sum" id="sum" readonly value="@Model.Item1"/>
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" value="Оплатить!" class="btn btn-primary" />
|
<input type="submit" value="Оплатить!" class="btn btn-primary" />
|
||||||
</div>
|
</div>
|
||||||
@ -51,7 +51,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var item in Model.Item2)
|
@foreach (var item in Model.Item3)
|
||||||
{
|
{
|
||||||
<tr class="element">
|
<tr class="element">
|
||||||
<th>
|
<th>
|
||||||
@ -80,25 +80,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
|
||||||
$('#btn').on('click', function () {
|
|
||||||
calc();
|
|
||||||
});
|
|
||||||
|
|
||||||
let sum = 0;
|
|
||||||
const elementRows = document.querySelectorAll('.element');
|
|
||||||
calc();
|
|
||||||
|
|
||||||
function calc() {
|
|
||||||
elementRows.forEach(row => {
|
|
||||||
const count = parseInt(row.querySelector('.count').innerHTML, 10);
|
|
||||||
const countsum = parseInt(row.querySelector('.countsum').innerHTML, 10);
|
|
||||||
const rowTotal = count * countsum;
|
|
||||||
sum += rowTotal;
|
|
||||||
});
|
|
||||||
$('#sum').val(sum);
|
|
||||||
}
|
|
||||||
</script>
|
|
Loading…
Reference in New Issue
Block a user