walt
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Shared.DTOs;
|
using Shared.DTOs;
|
||||||
using Shared.DTOs.Serch;
|
using Shared.DTOs.Serch;
|
||||||
|
using Shared.Enums;
|
||||||
|
|
||||||
namespace Back.Controllers
|
namespace Back.Controllers
|
||||||
{
|
{
|
||||||
@@ -19,14 +20,16 @@ namespace Back.Controllers
|
|||||||
private readonly ServPromotion _servPromotion;
|
private readonly ServPromotion _servPromotion;
|
||||||
private readonly ServPricing _servPricing;
|
private readonly ServPricing _servPricing;
|
||||||
private readonly servUser _servUser;
|
private readonly servUser _servUser;
|
||||||
|
private readonly servCompany _servCompany;
|
||||||
public OrdersController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser)
|
private readonly ServWalt _servWalt;
|
||||||
|
public OrdersController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser, servCompany servCompany, ServWalt servWalt)
|
||||||
{
|
{
|
||||||
_servOrders = servOrders;
|
_servOrders = servOrders;
|
||||||
_servPricing = servPricing;
|
_servPricing = servPricing;
|
||||||
_servPromotion = servPromotion;
|
_servPromotion = servPromotion;
|
||||||
_servUser = servUser;
|
_servUser = servUser;
|
||||||
|
_servCompany = servCompany;
|
||||||
|
_servWalt = servWalt;
|
||||||
}
|
}
|
||||||
[HttpGet("GetAllPromotion")]
|
[HttpGet("GetAllPromotion")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
@@ -146,5 +149,46 @@ namespace Back.Controllers
|
|||||||
else return BadRequest(new List<string> { "خطا در ثبت سفارش" });
|
else return BadRequest(new List<string> { "خطا در ثبت سفارش" });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
[HttpGet("SubmitOrderBywallet/{OrderID}")]
|
||||||
|
public async Task<ActionResult<OrderDto>> SubmitOrder(int OrderID)
|
||||||
|
{
|
||||||
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
||||||
|
var UserID = claim.Value;
|
||||||
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
||||||
|
var Company = user.RolUsers.First().Company;
|
||||||
|
int CompanyID = Company.ID;
|
||||||
|
var order =await _servOrders.GetOrder(OrderID, CompanyID);
|
||||||
|
|
||||||
|
if (order.Status==StatusOrder.Create)
|
||||||
|
{
|
||||||
|
if (Company.Credit >= order.TPrice)
|
||||||
|
{
|
||||||
|
Company.Credit -= order.TPrice;
|
||||||
|
var comUpdate=await _servCompany.AddORUpdateCompany(Company);
|
||||||
|
if (comUpdate!=null)
|
||||||
|
{
|
||||||
|
if (await _servWalt.AddDocument(new CreditDocuments
|
||||||
|
{
|
||||||
|
CompanyID = CompanyID,
|
||||||
|
Date = DateTime.Now.ConvertMiladiToShamsi(),
|
||||||
|
Title = $"بابت سفارش {order.ID}",
|
||||||
|
type = CreditDocumentType.Decrease,
|
||||||
|
Value = order.TPrice
|
||||||
|
}))
|
||||||
|
return Ok();
|
||||||
|
else
|
||||||
|
return BadRequest(new List<string> { "خطا در بروزرسانی سند سفارش" });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return BadRequest(new List<string> { "خطا در بروزرسانی شرکت" });
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return BadRequest(new List<string> { "اعتبار کیف پول کافی نمی باشد" });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return BadRequest(new List<string> { "سفارش در این حالت امکان پرداخت ندارد" });
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -80,6 +80,7 @@ builder.Services.AddScoped<Servstuff>();
|
|||||||
builder.Services.AddScoped<ServPromotion>();
|
builder.Services.AddScoped<ServPromotion>();
|
||||||
builder.Services.AddScoped<ServOrders>();
|
builder.Services.AddScoped<ServOrders>();
|
||||||
builder.Services.AddScoped<ServPricing>();
|
builder.Services.AddScoped<ServPricing>();
|
||||||
|
builder.Services.AddScoped<ServWalt>();
|
||||||
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
||||||
|
|
||||||
string origins = "OriginTaxPayer";
|
string origins = "OriginTaxPayer";
|
||||||
|
@@ -63,7 +63,9 @@ namespace Back.Services
|
|||||||
}
|
}
|
||||||
public async Task<Order> GetOrder(int OrderID, int CompanyID)
|
public async Task<Order> GetOrder(int OrderID, int CompanyID)
|
||||||
{
|
{
|
||||||
return await _repoOrder.Get(w => w.ID == OrderID && w.CompanyID == CompanyID) .FirstOrDefaultAsync();
|
return await _repoOrder.Get(w => w.ID == OrderID && w.CompanyID == CompanyID)
|
||||||
|
.Include(inc=>inc.OrderItems)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
public async Task<bool> UpdateOrder(Order order)
|
public async Task<bool> UpdateOrder(Order order)
|
||||||
{
|
{
|
||||||
|
19
Back/Services/ServWalt.cs
Normal file
19
Back/Services/ServWalt.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Back.Data.Contracts;
|
||||||
|
using Back.Data.Models;
|
||||||
|
|
||||||
|
namespace Back.Services
|
||||||
|
{
|
||||||
|
public class ServWalt
|
||||||
|
{
|
||||||
|
private readonly IAsyncRepository<CreditDocuments> _repoCreditDocuments;
|
||||||
|
|
||||||
|
public ServWalt(IAsyncRepository<CreditDocuments> repoCreditDocuments)
|
||||||
|
{
|
||||||
|
_repoCreditDocuments = repoCreditDocuments;
|
||||||
|
}
|
||||||
|
public async Task<bool> AddDocument(CreditDocuments document)
|
||||||
|
{
|
||||||
|
return await _repoCreditDocuments.AddBoolResultAsync(document);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -175,9 +175,22 @@
|
|||||||
}
|
}
|
||||||
private async Task OnClickPay()
|
private async Task OnClickPay()
|
||||||
{
|
{
|
||||||
// result.Status = ComponentStatus.success;
|
PreloadService.Show(SpinnerColor.Dark);
|
||||||
// result.Action = ComponentAction.add;
|
var rsp = await hc.Get($"Orders/SubmitOrderBywallet/{order.ID}");
|
||||||
// await OnMultipleOfThree.InvokeAsync(result);
|
PreloadService.Hide();
|
||||||
|
if (rsp.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
result = new ActionInResultComponent();
|
||||||
|
result.Status = ComponentStatus.success;
|
||||||
|
result.Action = ComponentAction.add;
|
||||||
|
await OnMultipleOfThree.InvokeAsync(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var request = await rsp.Content.ReadFromJsonAsync<List<string>>();
|
||||||
|
ShowDangerAlert(request[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user