using System; using System.Collections.Generic; using System.Linq; using System.Web.Http; using System.Web.Http.Description; using Learun.Application.Base.SystemModule; using Learun.Application.TwoDevelopment.ZZDT_EC; using Learun.Util; namespace Learun.Application.Web.AppApi { /// /// 图纸文件接口 /// [RoutePrefix("api/DrawingCatalogueApi")] [HandlerApiLogin(FilterMode.Enforce)] [TokenAuthorize] public class DrawingCatalogueApiController : WebApiControllerBase { private ec_drawing_catalogueIBLL ec_drawing_catalogueIBLL = new ec_drawing_catalogueBLL(); /// /// 获取图纸目录信息 /// /// 项目ID /// 图纸目录ID /// [HttpGet] [ResponseType(typeof(ec_drawing_catalogueEntity))] public IHttpActionResult GetEntity(string projectId, string drawingCatalogueID) { try { var entity = ec_drawing_catalogueIBLL.GetEntity(drawingCatalogueID, projectId); return Success(entity); } catch (Exception ex) { return Fail(ex.Message); } } /// /// 新增图纸目录 /// /// 项目ID /// json格式的字符串,转为json对象即可 /// [HttpPost] public IHttpActionResult AddDrawingCatalogue(string projectId) { try { var httpContent = Request.Content; var strEntity = httpContent.ReadAsStringAsync().Result; ec_drawing_catalogueEntity entity = strEntity.ToObject(); //判断同一目录是否存在目录 var data = ec_drawing_catalogueIBLL.GetList("{UpDrawingCatalogueID:\"" + entity.UpDrawingCatalogueID + "\",\"ProjectId\":\"" + projectId + "\"}").ToList(); data = data.FindAll(x => x.DrawingCatalogueName == entity.DrawingCatalogueName); if (data != null && data.Count > 0) { entity = data[0]; } else { entity.Create(); ec_drawing_catalogueIBLL.InertEntity(entity, projectId); } return Success(entity); } catch (Exception ex) { return Fail(ex.Message); } } /// /// 编辑图纸目录 /// /// 项目ID /// [HttpPost] public IHttpActionResult EditDrawingCatalogue(string projectId) { try { var httpContent = Request.Content; var asyncContent = httpContent.ReadAsStringAsync().Result; ec_drawing_catalogueEntity entity = asyncContent.ToObject(); //判断同一目录是否存在目录 var data = ec_drawing_catalogueIBLL.GetList("{UpDrawingCatalogueID:\"" + entity.UpDrawingCatalogueID + "\",\"ProjectId\":\"" + projectId + "\"}").ToList(); data = data.FindAll(x => x.DrawingCatalogueName == entity.DrawingCatalogueName); if (data != null && data.Count > 0) { data = data.FindAll(x => x.DrawingCatalogueID != entity.DrawingCatalogueID); if (data != null && data.Count > 0) { return Fail("该图纸目录名称已经存在!"); } } ec_drawing_catalogueIBLL.EditEntity(entity, projectId); return Success("保存成功!"); } catch (Exception ex) { return Fail(ex.Message); } } } }