123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Data.Entity.Infrastructure;
- using System.Linq;
- using System.Net;
- using System.Web;
- using System.Web.Http;
- using System.Web.Http.Description;
- using DevExpress.Office.Utils;
- using iBemsDataService.Model;
- using iBemsDataService.Util;
- namespace iBemsDataService.Controllers
- {
- public class FmsWorkResultCheckItemController : ApiController
- {
- private iBemsEntities db = new iBemsEntities();
- [Queryable]
- public IQueryable<WorkResultCheckItemForSelect> GetFmsWorkResultCheckItem()
- {
- //Uri uri = Request.RequestUri;
- //var uriQuery = HttpUtility.ParseQueryString( uri.Query );
- //int siteId, orderId, workTypeId;
- //string facilityCode = uriQuery.Get( "FacilityCode" );
- //if( int.TryParse( uriQuery.Get( "SiteId" ) , out siteId ) == false ||
- // int.TryParse( uriQuery.Get( "OrderId" ) , out orderId ) == false ||
- // int.TryParse( uriQuery.Get( "WorkTypeId" ) , out workTypeId ) == false ||
- // string.IsNullOrEmpty(facilityCode) )
- //{
- // throw new Exception("Not Found Parameters.");
- //}
- // 2019.07.12
- Uri uri = Request.RequestUri;
- var uriQuery = HttpUtility.ParseQueryString(uri.Query);
- int siteId;
- if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false)
- {
- throw new Exception("Not Found Parameters.");
- }
- var query = from f in db.FmsFacilityCheckItem.Where(x => x.SiteId == siteId) // 2019.07.12
- join w in db.FmsWorkResultCheckItem on f.SiteId equals w.SiteId into wg
- from item in wg.Where( x => x.FacilityCode == f.FacilityCode &&
- x.CheckItemId == f.CheckItemId ).DefaultIfEmpty()
- // x.CheckItemId == f.CheckItemId && x.OrderId == orderId ).DefaultIfEmpty()
- //where f.SiteId == siteId && f.FacilityCode == facilityCode && f.WorkTypeId == workTypeId
- select new WorkResultCheckItemForSelect
- {
- SiteId = f.SiteId,
- FacilityCode = f.FacilityCode,
- CheckItemId = f.CheckItemId,
- WorkTypeId = f.WorkTypeId,
- IsYesNoResult = f.IsYesNoResult,
- Name = f.Name,
- // hcLee 2018 01 29
- FileId1 = item.FileId1 == null ? null : item.FileId1,
- FileId2 = item.FileId2 == null ? null : item.FileId2,
- // <-- hcLee 2018 01 29
- WorkRequestId = item == null ? null : (Nullable<int>)item.WorkRequestId ,
- TextResult = item.TextResult == null ? null : item.TextResult ,
- BoolResult = item.BoolResult == null ? null : item.BoolResult
- };
- return query;
- }
- // POST: api/FmsWorkResultCheckItem
- [ResponseType( typeof ( void ) )]
- public IHttpActionResult PostFmsWorkResultCheckItem( List<WorkResultCheckItem> checkItems )
- {
- if ( !ModelState.IsValid )
- {
- return BadRequest( ModelState );
- }
- Uri uri = Request.RequestUri;
- var uriQuery = HttpUtility.ParseQueryString( uri.Query );
- int siteId, workRequestId, facilityCode;
- string uriFacilityCode = uriQuery.Get( "FacilityCode" );
- if( int.TryParse( uriQuery.Get( "SiteId" ) , out siteId ) == false ||
- int.TryParse( uriQuery.Get( "WorkRequestId" ) , out workRequestId ) == false ||
- int.TryParse( uriFacilityCode, out facilityCode ) == false )
- {
- return BadRequest("Not Found Parameters.");
- }
- var query = from d in db.FmsWorkResultCheckItem
- where d.SiteId == siteId &&
- d.WorkRequestId == workRequestId &&
- d.FacilityCode == facilityCode
- select d;
- var qm = new QueryManager<FmsWorkResultCheckItem>( db );
- try
- {
- qm.DeleteAndInsert( db.FmsWorkResultCheckItem , checkItems , query );
- }
- catch ( Exception )
- {
- throw;
- }
- return StatusCode( HttpStatusCode.NoContent );
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- private bool FmsWorkOrderToFacilityExists( int id )
- {
- return db.FmsWorkOrderToFacility.Count( e => e.SiteId == id ) > 0;
- }
- }
- public class WorkResultCheckItemForSelect
- {
- public int SiteId { get; set; }
- public Nullable<int> WorkRequestId { get; set; }
- public int FacilityCode { get; set; }
- public int CheckItemId { get; set; }
- public int WorkTypeId { get; set; }
- public string Name { get; set; }
- public bool IsYesNoResult { get; set; }
- public Nullable<bool> BoolResult { get; set; }
- public string TextResult { get; set; }
- public Nullable<int> FileId1 { get; set; }
- public Nullable<int> FileId2 { get; set; }
- };
- public class WorkResultCheckItem
- {
- public int SiteId { get; set; }
- public int WorkOrderId { get; set; }
- public int FacilityCode { get; set; }
- public int CheckItemId { get; set; }
- public bool BoolResult { get; set; }
- public string TextResult { get; set; }
- public int FileId1 { get; set; }
- public int FileId2 { get; set; }
- };
- }
|