Repository navigation
Expand file tree
/
Copy pathOrderHistoryApiController.cs
More file actions
51 lines (45 loc) · 1.72 KB
/
Copy pathOrderHistoryApiController.cs
File metadata and controls
51 lines (45 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SimplCommerce.Infrastructure.Data;
using SimplCommerce.Module.Core.Extensions;
using SimplCommerce.Module.Orders.Models;
namespace SimplCommerce.Module.Orders.Areas.Orders.Controllers
{
[Area("Orders")]
[Authorize(Roles = "admin, vendor")]
public class OrderHistoryApiController : Controller
{
private readonly IRepository<OrderHistory> _orderHistoryRepository;
private readonly IWorkContext _workContext;
public OrderHistoryApiController(IRepository<OrderHistory> orderHistoryRepository, IWorkContext workContext)
{
_orderHistoryRepository = orderHistoryRepository;
_workContext = workContext;
}
[HttpGet("api/orders/{orderId}/history")]
public async Task<IActionResult> Get(long orderId)
{
var query = _orderHistoryRepository.Query()
.Where(x => x.OrderId == orderId);
var currentUser = await _workContext.GetCurrentUser();
if (!User.IsInRole("admin"))
{
query = query.Where(x => x.Order.VendorId == currentUser.VendorId);
}
var histories = await query
.Select(x => new
{
OldStatus = x.OldStatus.ToString(),
NewStatus = x.NewStatus.ToString(),
CreatedById = x.CreatedById,
CreatedByFullName = x.CreatedBy.FullName,
x.Note,
x.CreatedOn
}).ToListAsync();
return Ok(histories);
}
}
}