123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- 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 System.Web.Http.OData;
- using DevExpress.Office.Utils;
- using iBemsDataService.Model;
- using iBemsDataService.Util;
- namespace iBemsDataService.Controllers
- {
- public class FmsBudgetDetailExecution2Controller : ODataController
- {
- private iBemsEntities db2 = new iBemsEntities();
- // GET: odata/FmsBudgetCodeClassEx
- [Queryable]
- public List<FmsBudgetDetailExecution2> GetFmsBudgetDetailExecution2()
- {
- var codeList = db2.FmsBudgetCodeClass.ToList();
- // 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 list = (
- from e in db2.FmsBudgetDetailExecution.Where(x => x.SiteId == siteId)
- //join cc in db2.FmsBudgetCodeClass on e.BudgetClassId equals cc.BudgetClassId
- select new FmsBudgetDetailExecution2
- {
- BudgetClassId = e.BudgetClassId,
- BudgetSeq =e.FmsBudgetDetail.FmsBudgetCodeClass.BudgetSeq,
- Depth = 2,
- Month = e.Month,
- Name = e.FmsBudgetDetail.FmsBudgetCodeClass.Name,
- ParentBudgetClassId = e.ParentBudgetClassId,
-
- //ParentBudgetName = e.FmsBudgetDetail.FmsBudgetCodeClass.Name
- //RootBudgetName = codeList.Where(a => a.BudgetClassId == e.RootBudgetClassId).FirstOrDefault().Name,
- RootBudgetClassId = e.RootBudgetClassId,
- SiteId = e.SiteId,
- Year = e.Year,
- YearlyBudget = e.YearlyBudget,
- YearlyExecution = e.YearlyExecution,
- MonthlyBudget = e.MonthlyBudget,
- MonthlyExecution = e.MonthlyExecution
- }).ToList();
- foreach (var item in list)
- {
- if(item.RootBudgetClassId != null)
- {
- item.RootBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.RootBudgetClassId).FirstOrDefault().Name;
- }
-
- if(item.ParentBudgetClassId > 0)
- {
- item.ParentBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.ParentBudgetClassId).FirstOrDefault().Name;
- }
- }
- return list;
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db2.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- public class FmsBudgetDetailExecutionController : ApiController
- {
- private iBemsEntities db = new iBemsEntities();
- // GET: odata/FmsBudgetCodeClassEx
- [Queryable]
- public List<FmsBudgetDetailExecution> GetFmsBudgetDetailExecution()
- {
- var list = db.FmsBudgetDetailExecution.ToList() ;
- // 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();
- foreach (var item in list)
- {
- item.RootBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.RootBudgetClassId).FirstOrDefault().Name;
- item.ParentBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.ParentBudgetClassId).FirstOrDefault().Name;
- item.Name = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.BudgetClassId).FirstOrDefault().Name;
- item.BudgetSeq = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.BudgetClassId).FirstOrDefault().BudgetSeq;
- item.Depth = 2;
- }
- return list;
- }
- // POST: api/FmsFmsBudgetDetail
- [ResponseType(typeof(void))]
- [ActionName("Save")]
- public IHttpActionResult PostFmsBudgetDetailExecution(List<FmsBudgetDetailExecution> budgetList)
- {
- Uri uri = Request.RequestUri;
- var uriQuery = HttpUtility.ParseQueryString(uri.Query);
- int siteId, year, month;
- if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
- int.TryParse(uriQuery.Get("Year"), out year) == false ||
- int.TryParse(uriQuery.Get("Month"), out month) == false
- )
- {
- return BadRequest("Not Found Parameters.");
- }
- try
- {
- foreach (var item in budgetList)
- {
- db.FmsBudgetDetailExecution.Attach(item);
- var entry = db.Entry(item);
- entry.State = System.Data.EntityState.Modified;
- }
- db.SaveChanges();
- }
- catch (Exception) { throw; }
- return StatusCode(HttpStatusCode.NoContent);
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
- namespace iBemsDataService.Model
- {
- public partial class FmsBudgetDetailExecution
- {
- public string RootBudgetName { get; set; }
- public string ParentBudgetName { get; set; }
- public string Name { get; set; }
- public string BudgetSeq { get; set; }
- public int Depth { get; set; }
- }
- public partial class FmsBudgetDetailExecution2 : FmsBudgetDetailExecution
- {
- }
- }
|