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> { "سفارش در این حالت امکان پرداخت ندارد" });
}
}
}