82 lines
2.9 KiB
C#
82 lines
2.9 KiB
C#
|
|
using DevExpress.CodeParser;
|
|||
|
|
using DevExpress.ExpressApp.Security;
|
|||
|
|
using DevExpress.ExpressApp.WebApi.Services;
|
|||
|
|
using DurnyklyYol.Blazor.Server.DTO;
|
|||
|
|
using DurnyklyYol.Module.BusinessObjects;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|
|||
|
|
namespace DurnyklyYol.Blazor.Server.Controllers
|
|||
|
|
{
|
|||
|
|
[ApiController]
|
|||
|
|
[Route("api/[controller]")]
|
|||
|
|
[Authorize]
|
|||
|
|
public class GoodsController : ControllerBase
|
|||
|
|
{
|
|||
|
|
private readonly IDataService dataService;
|
|||
|
|
private readonly ISecurityProvider securityProvider;
|
|||
|
|
|
|||
|
|
public GoodsController(IDataService dataService, ISecurityProvider securityProvider)
|
|||
|
|
{
|
|||
|
|
this.dataService = dataService;
|
|||
|
|
this.securityProvider = securityProvider;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Authorize]
|
|||
|
|
[HttpGet]
|
|||
|
|
public IActionResult Get([FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10, [FromQuery] GoodsState? state = null)
|
|||
|
|
{
|
|||
|
|
var objectSpace = dataService.GetObjectSpace<Goods>();
|
|||
|
|
var userID = (Guid)securityProvider.GetSecurity().UserId;
|
|||
|
|
var goodsQuery = objectSpace.GetObjectsQuery<Goods>()
|
|||
|
|
.Where(cl => cl.Client.Oid == userID)
|
|||
|
|
.Select(sl => new GoodsDto {
|
|||
|
|
No = sl.No,
|
|||
|
|
Oid = sl.Oid,
|
|||
|
|
Name = sl.Name,
|
|||
|
|
PlacesCount = sl.PlaceCount,
|
|||
|
|
Volume = sl.Volume,
|
|||
|
|
ShopNo = sl.ShopNo,
|
|||
|
|
Carrier = sl.Cargo.Carrier.Number,
|
|||
|
|
From = sl.Cargo.StartsFrom,
|
|||
|
|
To = sl.Cargo.DestinationTo,
|
|||
|
|
ClientId = sl.Client.Oid,
|
|||
|
|
DepartedAt = sl.Cargo.StartedAt,
|
|||
|
|
Depth = sl.Depth,
|
|||
|
|
Width = sl.Width,
|
|||
|
|
Height = sl.Height,
|
|||
|
|
CargoId = sl.Cargo.Oid,
|
|||
|
|
CargoState = sl.Cargo.State,
|
|||
|
|
State = sl.State,
|
|||
|
|
Price = sl.Price,
|
|||
|
|
Image1 = sl.Image1 != null ? string.Format("/FileData/{0}-{1}", sl.Image1.Oid, sl.Image1.FileName) : "",
|
|||
|
|
Image2 = sl.Image2 != null ? string.Format("/FileData/{0}-{1}", sl.Image2.Oid, sl.Image2.FileName) : "",
|
|||
|
|
Image3 = sl.Image3 != null ? string.Format("/FileData/{0}-{1}", sl.Image3.Oid, sl.Image3.FileName) : "",
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (state != null) {
|
|||
|
|
goodsQuery.Where(wh => wh.State == state);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var totalRecords = goodsQuery.Count();
|
|||
|
|
|
|||
|
|
var goods = goodsQuery
|
|||
|
|
.Skip((pageNumber - 1) * pageSize)
|
|||
|
|
.Take(pageSize)
|
|||
|
|
.ToList();
|
|||
|
|
|
|||
|
|
var response = new
|
|||
|
|
{
|
|||
|
|
TotalRecords = totalRecords,
|
|||
|
|
PageNumber = pageNumber,
|
|||
|
|
PageSize = pageSize,
|
|||
|
|
Data = goods
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
return Ok(response);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|