This commit is contained in:
mmrbnjd
2024-07-29 17:50:46 +03:30
parent 68667b5f95
commit a025225920
5 changed files with 86 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using Shared.DTOs.Serch;
using Shared.Enums;
namespace Back.Controllers
{
@@ -19,14 +20,16 @@ namespace Back.Controllers
private readonly ServPromotion _servPromotion;
private readonly ServPricing _servPricing;
private readonly servUser _servUser;
public OrdersController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser)
private readonly servCompany _servCompany;
private readonly ServWalt _servWalt;
public OrdersController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser, servCompany servCompany, ServWalt servWalt)
{
_servOrders = servOrders;
_servPricing = servPricing;
_servPromotion = servPromotion;
_servUser = servUser;
_servCompany = servCompany;
_servWalt = servWalt;
}
[HttpGet("GetAllPromotion")]
[AllowAnonymous]
@@ -146,5 +149,46 @@ namespace Back.Controllers
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> { "سفارش در این حالت امکان پرداخت ندارد" });
}
}
}

View File

@@ -80,6 +80,7 @@ builder.Services.AddScoped<Servstuff>();
builder.Services.AddScoped<ServPromotion>();
builder.Services.AddScoped<ServOrders>();
builder.Services.AddScoped<ServPricing>();
builder.Services.AddScoped<ServWalt>();
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
string origins = "OriginTaxPayer";

View File

@@ -63,7 +63,9 @@ namespace Back.Services
}
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)
{

19
Back/Services/ServWalt.cs Normal file
View 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);
}
}
}

View File

@@ -175,9 +175,22 @@
}
private async Task OnClickPay()
{
// result.Status = ComponentStatus.success;
// result.Action = ComponentAction.add;
// await OnMultipleOfThree.InvokeAsync(result);
PreloadService.Show(SpinnerColor.Dark);
var rsp = await hc.Get($"Orders/SubmitOrderBywallet/{order.ID}");
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]);
}
}