walt
This commit is contained in:
@@ -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> { "سفارش در این حالت امکان پرداخت ندارد" });
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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";
|
||||
|
@@ -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
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user