74554095fe7b5e8879444f68586fb137ad8a2684.svn-base 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data.Entity;
  5. using System.Data.Entity.Infrastructure;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Web;
  9. using System.Web.Http;
  10. using System.Web.Http.Description;
  11. using DevExpress.Office.Utils;
  12. using iBemsDataService.Model;
  13. using iBemsDataService.Util;
  14. namespace iBemsDataService.Controllers
  15. {
  16. public class FmsWorkResultCheckItemController : ApiController
  17. {
  18. private iBemsEntities db = new iBemsEntities();
  19. [Queryable]
  20. public IQueryable<WorkResultCheckItemForSelect> GetFmsWorkResultCheckItem()
  21. {
  22. //Uri uri = Request.RequestUri;
  23. //var uriQuery = HttpUtility.ParseQueryString( uri.Query );
  24. //int siteId, orderId, workTypeId;
  25. //string facilityCode = uriQuery.Get( "FacilityCode" );
  26. //if( int.TryParse( uriQuery.Get( "SiteId" ) , out siteId ) == false ||
  27. // int.TryParse( uriQuery.Get( "OrderId" ) , out orderId ) == false ||
  28. // int.TryParse( uriQuery.Get( "WorkTypeId" ) , out workTypeId ) == false ||
  29. // string.IsNullOrEmpty(facilityCode) )
  30. //{
  31. // throw new Exception("Not Found Parameters.");
  32. //}
  33. // 2019.07.12
  34. Uri uri = Request.RequestUri;
  35. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  36. int siteId;
  37. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false)
  38. {
  39. throw new Exception("Not Found Parameters.");
  40. }
  41. var query = from f in db.FmsFacilityCheckItem.Where(x => x.SiteId == siteId) // 2019.07.12
  42. join w in db.FmsWorkResultCheckItem on f.SiteId equals w.SiteId into wg
  43. from item in wg.Where( x => x.FacilityCode == f.FacilityCode &&
  44. x.CheckItemId == f.CheckItemId ).DefaultIfEmpty()
  45. // x.CheckItemId == f.CheckItemId && x.OrderId == orderId ).DefaultIfEmpty()
  46. //where f.SiteId == siteId && f.FacilityCode == facilityCode && f.WorkTypeId == workTypeId
  47. select new WorkResultCheckItemForSelect
  48. {
  49. SiteId = f.SiteId,
  50. FacilityCode = f.FacilityCode,
  51. CheckItemId = f.CheckItemId,
  52. WorkTypeId = f.WorkTypeId,
  53. IsYesNoResult = f.IsYesNoResult,
  54. Name = f.Name,
  55. // hcLee 2018 01 29
  56. FileId1 = item.FileId1 == null ? null : item.FileId1,
  57. FileId2 = item.FileId2 == null ? null : item.FileId2,
  58. // <-- hcLee 2018 01 29
  59. WorkRequestId = item == null ? null : (Nullable<int>)item.WorkRequestId ,
  60. TextResult = item.TextResult == null ? null : item.TextResult ,
  61. BoolResult = item.BoolResult == null ? null : item.BoolResult
  62. };
  63. return query;
  64. }
  65. // POST: api/FmsWorkResultCheckItem
  66. [ResponseType( typeof ( void ) )]
  67. public IHttpActionResult PostFmsWorkResultCheckItem( List<WorkResultCheckItem> checkItems )
  68. {
  69. if ( !ModelState.IsValid )
  70. {
  71. return BadRequest( ModelState );
  72. }
  73. Uri uri = Request.RequestUri;
  74. var uriQuery = HttpUtility.ParseQueryString( uri.Query );
  75. int siteId, workRequestId, facilityCode;
  76. string uriFacilityCode = uriQuery.Get( "FacilityCode" );
  77. if( int.TryParse( uriQuery.Get( "SiteId" ) , out siteId ) == false ||
  78. int.TryParse( uriQuery.Get( "WorkRequestId" ) , out workRequestId ) == false ||
  79. int.TryParse( uriFacilityCode, out facilityCode ) == false )
  80. {
  81. return BadRequest("Not Found Parameters.");
  82. }
  83. var query = from d in db.FmsWorkResultCheckItem
  84. where d.SiteId == siteId &&
  85. d.WorkRequestId == workRequestId &&
  86. d.FacilityCode == facilityCode
  87. select d;
  88. var qm = new QueryManager<FmsWorkResultCheckItem>( db );
  89. try
  90. {
  91. qm.DeleteAndInsert( db.FmsWorkResultCheckItem , checkItems , query );
  92. }
  93. catch ( Exception )
  94. {
  95. throw;
  96. }
  97. return StatusCode( HttpStatusCode.NoContent );
  98. }
  99. protected override void Dispose(bool disposing)
  100. {
  101. if (disposing)
  102. {
  103. db.Dispose();
  104. }
  105. base.Dispose(disposing);
  106. }
  107. private bool FmsWorkOrderToFacilityExists( int id )
  108. {
  109. return db.FmsWorkOrderToFacility.Count( e => e.SiteId == id ) > 0;
  110. }
  111. }
  112. public class WorkResultCheckItemForSelect
  113. {
  114. public int SiteId { get; set; }
  115. public Nullable<int> WorkRequestId { get; set; }
  116. public int FacilityCode { get; set; }
  117. public int CheckItemId { get; set; }
  118. public int WorkTypeId { get; set; }
  119. public string Name { get; set; }
  120. public bool IsYesNoResult { get; set; }
  121. public Nullable<bool> BoolResult { get; set; }
  122. public string TextResult { get; set; }
  123. public Nullable<int> FileId1 { get; set; }
  124. public Nullable<int> FileId2 { get; set; }
  125. };
  126. public class WorkResultCheckItem
  127. {
  128. public int SiteId { get; set; }
  129. public int WorkOrderId { get; set; }
  130. public int FacilityCode { get; set; }
  131. public int CheckItemId { get; set; }
  132. public bool BoolResult { get; set; }
  133. public string TextResult { get; set; }
  134. public int FileId1 { get; set; }
  135. public int FileId2 { get; set; }
  136. };
  137. }