38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
|
|
/// <summary>
|
|
/// AncestralTabletStatisticsController 的摘要描述
|
|
/// </summary>
|
|
public class AncestralTabletStatisticsController:ApiController
|
|
{
|
|
private Model.ezEntities db = new Model.ezEntities();
|
|
[HttpGet]
|
|
[Route("api/ancestraltablet/statistics/positions/availablepositions")]
|
|
public IHttpActionResult GetAvailablePositions()
|
|
{
|
|
var query =
|
|
from a in db.AncestralTabletArea // 区域表
|
|
join p in db.AncestralTabletPosition
|
|
on a.AreaId equals p.AreaId into ap
|
|
from p in ap.DefaultIfEmpty()
|
|
join r in db.AncestralTabletRegistrant
|
|
on p.PositionId equals r.PositionId into pr
|
|
from r in pr.DefaultIfEmpty()
|
|
group new { a, p, r } by new { a.AreaId, a.AreaName } into g
|
|
select new
|
|
{
|
|
AreaId = g.Key.AreaId,
|
|
AreaName = g.Key.AreaName,
|
|
TotalPositions = g.Count(x => x.p != null), // 总位置数
|
|
AvailableCount = g.Count(x => x.p != null && x.r == null) // 可用位置数(未登记)
|
|
};
|
|
|
|
var result = query.ToList();
|
|
return Ok(result);
|
|
}
|
|
|
|
} |