79 lines
3.1 KiB
C#
79 lines
3.1 KiB
C#
using Back.Common;
|
|
using Back.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Shared.DTOs;
|
|
using Shared.DTOs.Serch;
|
|
|
|
namespace Back.Controllers
|
|
{
|
|
|
|
[Route("api/[controller]")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class OrdersController : ControllerBase
|
|
{
|
|
private readonly ServOrders _servOrders;
|
|
private readonly ServPromotion _servPromotion;
|
|
private readonly ServPricing _servPricing;
|
|
private readonly servUser _servUser;
|
|
|
|
public OrdersController(ServOrders servOrders, ServPromotion servPromotion, ServPricing servPricing, servUser servUser)
|
|
{
|
|
_servOrders = servOrders;
|
|
_servPricing = servPricing;
|
|
_servPromotion = servPromotion;
|
|
_servUser = servUser;
|
|
|
|
}
|
|
[HttpGet("GetAllPromotion")]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<List<PromotionDto>>> GetAllPromotion() =>Ok(await _servPromotion.GetAll());
|
|
|
|
[HttpGet("GetAllPricing")]
|
|
[AllowAnonymous]
|
|
public async Task<ActionResult<List<PricingDto>>> GetAllPricing() => Ok(await _servPricing.GetPricing());
|
|
[HttpPost("GetAllOrder")]
|
|
public async Task<ActionResult<PagingDto< OrderDto>>> GetAllOrder(ItemSerachOrder itemSerach)
|
|
{
|
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
|
var UserID = claim.Value;
|
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
|
int CompanyID = user.RolUsers.First().CompanyID;
|
|
|
|
return Ok(await _servOrders.GetOrdersByCompanyID(CompanyID,itemSerach));
|
|
}
|
|
[HttpGet("GetOrderDetails/{OrderID}")]
|
|
public async Task<ActionResult<List<OrderItemDto>>> GetOrderDetails(int OrderID)
|
|
{
|
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
|
var UserID = claim.Value;
|
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
|
int CompanyID = user.RolUsers.First().CompanyID;
|
|
|
|
return Ok(await _servOrders.GetOrderItems( OrderID, CompanyID));
|
|
}
|
|
[HttpDelete("CancelOrder/{OrderID}")]
|
|
public async Task<ActionResult<List<OrderItemDto>>> CancelOrder(int OrderID)
|
|
{
|
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
|
var UserID = claim.Value;
|
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
|
int CompanyID = user.RolUsers.First().CompanyID;
|
|
|
|
var order =await _servOrders.GetOrder(OrderID, CompanyID);
|
|
if (order==null)
|
|
return NotFound();
|
|
|
|
if (order.Status==StatusOrder.Create)
|
|
{
|
|
order.Status = StatusOrder.Cancel;
|
|
order.ApprovalDate = DateTime.Now.ConvertMiladiToShamsi();
|
|
return Ok(await _servOrders.UpdateOrder(order));
|
|
}
|
|
else return BadRequest(new List<string> { "در این وضعیت امکان ابطال نیست" });
|
|
}
|
|
}
|
|
}
|