| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 | 
							- 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;
 
- using System.Transactions;
 
- using System.Diagnostics;
 
- namespace iBemsDataService.Controllers
 
- {
 
-     public class BemsEnergyConfigPercentMonthController : ApiController
 
-     {
 
-         private iBemsEntities db = new iBemsEntities();
 
-         [ResponseType(typeof(void))]
 
-         [ActionName("Insert")]
 
-         public IHttpActionResult PostBemsEnergyConfigPercentMonthInsert(EnergyConfigPercentMonth EnergyConfigPercentMonth)
 
-         {
 
-             if (!ModelState.IsValid)
 
-             {
 
-                 return BadRequest(ModelState);
 
-             }
 
-             try
 
-             {
 
-                 // 그룹을 추가하면서 메뉴들을 그룹에 맞는 권한 테이블로 모두 옮겨 놓는다.
 
-                 using (var transaction = new TransactionScope())
 
-                 {
 
-                     var newPriceFormula = db.BemsEnergyConfigPercentMonth.Add(new BemsEnergyConfigPercentMonth
 
-                     {
 
-                         SiteId = EnergyConfigPercentMonth.SiteId,
 
-                         Year = EnergyConfigPercentMonth.Year,
 
-                         Month = EnergyConfigPercentMonth.Month,
 
-                         Electricity = Math.Round(EnergyConfigPercentMonth.Electricity * 100) / 100.0,
 
-                         Gas = Math.Round(EnergyConfigPercentMonth.Gas * 100) / 100.0,
 
-                         Water = Math.Round(EnergyConfigPercentMonth.Water * 100) / 100.0
 
-                     });
 
-                     db.SaveChanges();
 
-                     transaction.Complete();
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 throw;
 
-             }
 
-             return StatusCode(HttpStatusCode.NoContent);
 
-         }
 
-         [ResponseType(typeof(void))]
 
-         [ActionName("InsertAll")]
 
-         public IHttpActionResult PostBemsPriceFormulaInsertAll(List<EnergyConfigPercentMonth> EnergyConfigPercentMonth)
 
-         {
 
-             if (!ModelState.IsValid)
 
-             {
 
-                 return BadRequest(ModelState);
 
-             }
 
-             try
 
-             {
 
-                 using (var transaction = new TransactionScope())
 
-                 {
 
-                     foreach (var m in EnergyConfigPercentMonth)
 
-                     {
 
-                         var foundQuery = db.BemsEnergyConfigPercentMonth.Where(
 
-                             x =>
 
-                                 x.SiteId == m.SiteId &&
 
-                                 x.Year == m.Year &&
 
-                                 x.Month == m.Month);
 
-                         if (foundQuery.Any() == false)
 
-                         {
 
-                             var newM = db.BemsEnergyConfigPercentMonth.Add(new BemsEnergyConfigPercentMonth
 
-                             {
 
-                                 SiteId = m.SiteId,
 
-                                 Year = m.Year,
 
-                                 Month = m.Month,
 
-                                 Electricity = m.Electricity,
 
-                                 Gas = m.Gas,
 
-                                 Water = m.Water
 
-                             });
 
-                         }
 
-                     }
 
-                     db.SaveChanges();
 
-                     transaction.Complete();
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 throw;
 
-             }
 
-             return StatusCode(HttpStatusCode.NoContent);
 
-         }
 
-         [ResponseType(typeof(void))]
 
-         [ActionName("DeleteAll")]
 
-         public IHttpActionResult PostBemsPriceFormulaDeleteAll(EnergyConfigPercentMonth EnergyConfigPercentMonth)
 
-         {
 
-             if (!ModelState.IsValid)
 
-             {
 
-                 return BadRequest(ModelState);
 
-             }
 
-             try
 
-             {
 
-                 using (var transaction = new TransactionScope())
 
-                 {
 
-                     var foundQuery = db.BemsEnergyConfigPercentMonth.Where(
 
-                         x =>
 
-                             x.SiteId == EnergyConfigPercentMonth.SiteId &&
 
-                             x.Year == EnergyConfigPercentMonth.Year &&
 
-                             x.Month == EnergyConfigPercentMonth.Month);
 
-                     //db.BemsPriceFormula.Remove(foundQuery.FirstOrDefault()); 한개만 지운다
 
-                     new QueryManager<BemsEnergyConfigPercentMonth>(db).Delete(db.BemsEnergyConfigPercentMonth, foundQuery);
 
-                     db.SaveChanges();
 
-                     transaction.Complete();
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 throw;
 
-             }
 
-             return StatusCode(HttpStatusCode.NoContent);
 
-         }
 
-         [ResponseType(typeof(void))]
 
-         [ActionName("Update")]
 
-         public IHttpActionResult PostBemsPriceFormulaUpdate(EnergyConfigPercentMonth EnergyConfigPercentMonth)
 
-         {
 
-             if (!ModelState.IsValid)
 
-             {
 
-                 return BadRequest(ModelState);
 
-             }
 
-             try
 
-             {
 
-                 using (var transaction = new TransactionScope())
 
-                 {
 
-                     var foundQuery = db.BemsEnergyConfigPercentMonth.Where(
 
-                         x =>
 
-                         x.SiteId == EnergyConfigPercentMonth.SiteId &&
 
-                         x.Year == EnergyConfigPercentMonth.Year &&
 
-                         x.Month == EnergyConfigPercentMonth.Month
 
-                         );
 
-                     new QueryManager<BemsEnergyConfigPercentMonth>(db).Delete(db.BemsEnergyConfigPercentMonth, foundQuery);
 
-                     var newPriceFormula = db.BemsEnergyConfigPercentMonth.Add(new BemsEnergyConfigPercentMonth
 
-                     {
 
-                         SiteId = EnergyConfigPercentMonth.SiteId,
 
-                         Year = EnergyConfigPercentMonth.Year,
 
-                         Month = EnergyConfigPercentMonth.Month,
 
-                         Electricity = Math.Round(EnergyConfigPercentMonth.Electricity * 100) / 100.0,
 
-                         Gas = Math.Round(EnergyConfigPercentMonth.Gas * 100) / 100.0,
 
-                         Water = Math.Round(EnergyConfigPercentMonth.Water * 100) / 100.0
 
-                     });
 
-                     db.SaveChanges();
 
-                     transaction.Complete();
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 throw;
 
-             }
 
-             return StatusCode(HttpStatusCode.NoContent);
 
-         }
 
-         protected override void Dispose(bool disposing)
 
-         {
 
-             if (disposing)
 
-             {
 
-                 db.Dispose();
 
-             }
 
-             base.Dispose(disposing);
 
-         }
 
-         public class EnergyConfigPercentMonth
 
-         {
 
-             public int SiteId { get; set; }
 
-             public int Year { get; set; }
 
-             public int Month { get; set; }
 
-             public float Electricity { get; set; }
 
-             public float Gas { get; set; }
 
-             public float Water { get; set; }
 
-         };
 
-     }
 
- }
 
 
  |