神祖牌位管理模組,掛單模組前端URL添加HTTP_HOST
This commit is contained in:
180
web/App_Code/api/AncestralTabletAreaController.cs
Normal file
180
web/App_Code/api/AncestralTabletAreaController.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using Model;
|
||||
using PagedList;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using static AncestralTabletPositionController;
|
||||
using static regionController;
|
||||
|
||||
/// <summary>
|
||||
/// AncestralTabletController 的摘要描述
|
||||
/// </summary>
|
||||
public class AncestralTabletAreaController: ApiController
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
public class AreaViewModel
|
||||
{
|
||||
public int? AreaId { get; set; }
|
||||
public string AreaName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "區域編號為必填")]
|
||||
public string AreaCode { get; set; }
|
||||
public int? ParentAreaId { get; set; }
|
||||
public string AreaType { get; set; }
|
||||
public int? Price { get; set; }
|
||||
public int? SortOrder { get; set; }
|
||||
public bool IsDisabled { get; set; } = false;
|
||||
public string Description { get; set; }
|
||||
}
|
||||
public class RegionDto
|
||||
{
|
||||
public int AreaId { get; set; }
|
||||
public string AreaName { get; set; }
|
||||
public string AreaCode { get; set; }
|
||||
public int? SortOrder { get; set; }
|
||||
public int? ParentAreaId { get; set; }
|
||||
public string AreaType { get; set; }
|
||||
public bool IsDisabled { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int? Price { set; get; }
|
||||
|
||||
public List<RegionDto> Children { get; set; } = new List<RegionDto>();
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/area/getlist")]
|
||||
public IHttpActionResult GetList()
|
||||
{
|
||||
var allArea = _db.AncestralTabletArea.ToList();
|
||||
|
||||
var rootRegions = allArea
|
||||
.Where(r => r.ParentAreaId == null)
|
||||
.OrderBy(r => r.SortOrder)
|
||||
.ToList();
|
||||
|
||||
var tree = rootRegions
|
||||
.Select(r => BuildRegionDto(r, allArea))
|
||||
.ToList();
|
||||
return Ok(tree);
|
||||
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/area/getereawithposition")]
|
||||
public IHttpActionResult GetEreaWithPosition()
|
||||
{
|
||||
//获取有神位位置的区域
|
||||
var allArea = _db.AncestralTabletArea
|
||||
.Where(a => a.AncestralTabletPosition.Count()>0)
|
||||
.Select(a => new
|
||||
{
|
||||
a.AreaId,
|
||||
a.AreaName,
|
||||
})
|
||||
.ToList();
|
||||
return Ok(allArea);
|
||||
|
||||
}
|
||||
private RegionDto BuildRegionDto(AncestralTabletArea area, List<AncestralTabletArea> allArea)
|
||||
{
|
||||
return new RegionDto
|
||||
{
|
||||
AreaId = area.AreaId,
|
||||
AreaName = area.AreaName,
|
||||
AreaCode = area.AreaCode,
|
||||
SortOrder = area.SortOrder,
|
||||
ParentAreaId = area.ParentAreaId,
|
||||
AreaType = area.AreaType,
|
||||
IsDisabled = area.IsDisabled,
|
||||
Description = area.Description,
|
||||
Price = area.Price,
|
||||
Children = allArea
|
||||
.Where(r => r.ParentAreaId == area.AreaId)
|
||||
.OrderBy(r => r.SortOrder)
|
||||
.Select(child => BuildRegionDto(child, allArea))
|
||||
.ToList(),
|
||||
};
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/area/create")]
|
||||
public async Task<IHttpActionResult> CreateArea([FromBody] AreaViewModel tabletArea)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
try
|
||||
{
|
||||
var area = new AncestralTabletArea
|
||||
{
|
||||
AreaName = tabletArea.AreaName,
|
||||
AreaCode = tabletArea.AreaCode,
|
||||
ParentAreaId = tabletArea.ParentAreaId,
|
||||
AreaType = tabletArea.AreaType,
|
||||
Price = tabletArea.Price,
|
||||
SortOrder = tabletArea.SortOrder,
|
||||
IsDisabled = tabletArea.IsDisabled,
|
||||
Description = tabletArea.Description
|
||||
};
|
||||
_db.AncestralTabletArea.Add(area);
|
||||
await _db.SaveChangesAsync();
|
||||
tabletArea.AreaId = area.AreaId;
|
||||
return Ok(new { message = "區域建立成功", area = tabletArea });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("api/ancestraltablet/area/edit")]
|
||||
public async Task<IHttpActionResult> EditArea([FromBody] AreaViewModel tabletArea)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
try
|
||||
{
|
||||
var oldArea = _db.AncestralTabletArea.Find(tabletArea.AreaId);
|
||||
if (oldArea == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
oldArea.AreaName = tabletArea.AreaName;
|
||||
oldArea.AreaCode = tabletArea.AreaCode;
|
||||
oldArea.ParentAreaId = tabletArea.ParentAreaId;
|
||||
oldArea.Price = tabletArea.Price;
|
||||
oldArea.SortOrder = tabletArea.SortOrder;
|
||||
oldArea.Description = tabletArea.Description;
|
||||
oldArea.IsDisabled = tabletArea.IsDisabled;
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { message = "區域修改成功", area = tabletArea });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return InternalServerError(ex);
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("api/ancestraltablet/area/position/getlist")]
|
||||
public IHttpActionResult GetPositionList([FromUri] int areaId)
|
||||
{
|
||||
var positions = _db.AncestralTabletPosition
|
||||
.Where(p => p.AreaId == areaId)
|
||||
.Select(p => new AncestralTabletPositionDto
|
||||
{
|
||||
PositionId = p.PositionId,
|
||||
AreaId = p.AreaId,
|
||||
PositionCode = p.PositionCode,
|
||||
PositionName = p.PositionName,
|
||||
Price = p.Price,
|
||||
StatusCode = p.StatusCode,
|
||||
Description = p.Description,
|
||||
RowNo = p.RowNo,
|
||||
ColumnNo = p.ColumnNo
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return Ok(positions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user