| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | 
							- 
 
- using System;
 
- using System.Collections.Generic;
 
- using System.ComponentModel.DataAnnotations;
 
- using System.Data;
 
- using System.Data.Entity;
 
- using System.Data.Entity.Infrastructure;
 
- using System.Linq;
 
- using System.Net;
 
- using System.Net.Http;
 
- using System.Web;
 
- using System.Web.Http;
 
- using System.Web.Http.Description;
 
- using System.Web.Http.OData;
 
- using iBemsDataService;
 
- using iBemsDataService.Model;
 
- namespace iBemsDataService.Controllers
 
- {
 
-     public class FmsBudgetCodeClassExController : ODataController
 
-     {
 
-         private iBemsEntities db = new iBemsEntities();
 
-         // GET: odata/FmsBudgetCodeClassEx
 
-         [Queryable]
 
-         public List<FmsBudgetCodeClassEx> GetFmsBudgetCodeClassEx()
 
-         {
 
-             List<FmsBudgetCodeClassEx> flatList = null;
 
-             // 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 codeList = db.FmsBudgetCodeClass.ToList();
 
-             flatList = (
 
-                 from c in codeList
 
-                 where c.SiteId == siteId &&
 
-                       c.Depth == 2
 
-                 select new FmsBudgetCodeClassEx
 
-                 {
 
-                     SiteId = c.SiteId,
 
-                     ThirdBudgetClassId = c.BudgetClassId,
 
-                     ThirdBudgetName = c.Name,
 
-                     YearlyBudget = 0,
 
-                     MonthlyBudget = 0,
 
-                     //Depth = c.Depth,
 
-                     //ParentBudgetClassId = c.ParentBudgetClassId
 
-                 }).ToList();
 
-             foreach (var item in flatList)
 
-             {
 
-                 // Todo : 방어코드 혹은 exception 필요
 
-                 //catch (DbUpdateException e) { throw e; }
 
-                 KeyValuePair<int, string> secondBudgetValue = GetParent(item.ThirdBudgetClassId, codeList);
 
-                 KeyValuePair<int, string> firstBudgetValue = GetParent(secondBudgetValue.Key, codeList);
 
-                 if (secondBudgetValue.Key == 0 || firstBudgetValue.Key == 0)
 
-                 {
 
-                     throw new Exception("Budget Code 가 잘못설정되었습니다.");
 
-                 }
 
-                 item.SecondBudgetClassId = secondBudgetValue.Key;
 
-                 item.SecondBudgetName = secondBudgetValue.Value;
 
-                 item.SecondBudgetNameWithSum = secondBudgetValue.Value; ;
 
-                 item.FirstBudgetClassId = firstBudgetValue.Key;
 
-                 item.FirstBudgetName = firstBudgetValue.Value;
 
-                 item.FirstBudgetNameWithSum = firstBudgetValue.Value; ;
 
-             }
 
-             return flatList;
 
-         }
 
-         private KeyValuePair<int, string> GetParent(int budgetId, List<FmsBudgetCodeClass> codeList)
 
-         {
 
-             // 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 tempCodeClass = codeList.Where(c => c.SiteId == siteId && c.BudgetClassId == budgetId).FirstOrDefault();
 
-             var tempParent = codeList.Where(c => c.SiteId == siteId && c.BudgetClassId == tempCodeClass.ParentBudgetClassId).FirstOrDefault();
 
-             if (tempParent == null) { return new KeyValuePair<int, string>(0, ""); }
 
-             return new KeyValuePair<int, string>(tempParent.BudgetClassId, tempParent.Name);
 
-         }
 
-         protected override void Dispose(bool disposing)
 
-         {
 
-             if (disposing)
 
-             {
 
-                 db.Dispose();
 
-             }
 
-             base.Dispose(disposing);
 
-         }
 
-     }
 
- }
 
 
  |