123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- 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 BemsSitePriceController : ApiController
- {
- private iBemsEntities db = new iBemsEntities();
- [ResponseType(typeof(void))]
- [ActionName("Insert")]
- public IHttpActionResult PostBemsSitePriceInsert(SitePrice SitePrice)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- // 그룹을 추가하면서 메뉴들을 그룹에 맞는 권한 테이블로 모두 옮겨 놓는다.
- using (var transaction = new TransactionScope())
- {
- var newBemsSitePrice = db.BemsSitePrice.Add(new BemsSitePrice
- {
- SiteID = SitePrice.SiteId,
- FuelTypeId = SitePrice.FuelTypeId,
- PriceTypeId = SitePrice.PriceTypeId,
- PriceCode = SitePrice.PriceCode,
- UseYN = SitePrice.UseYN
- });
- db.SaveChanges();
- /*
- foreach (var user in Menu.MenuUsers)
- {
- //menu.SiteId = newUserGroup.SiteId;
- //menu.UserGroupId = newUserGroup.UserGroupId;
- //db.CmUserGroupPermission.Add( menu );
- //Trace.WriteLine( string.Format( "{0}-{1}" , newUserGroup.UserGroupId , menu.MenuId ) );
- db.BemsSitePriceUser.Add( new BemsSitePriceUser
- {
- SiteId = newMenu.SiteId,
- MenuId = newMenu.MenuId,
- UserId = user.UserId,
- } );
- db.SaveChanges();
- }*/
- transaction.Complete();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- [ResponseType(typeof(void))]
- [ActionName("InsertAll")]
- public IHttpActionResult PostBemsSitePriceInsertAll(List<SitePrice> SitePrice)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- using (var transaction = new TransactionScope())
- {
- foreach (var m in SitePrice)
- {
- var newM = db.BemsSitePrice.Add(new BemsSitePrice
- {
- SiteID = m.SiteId,
- FuelTypeId = m.FuelTypeId,
- PriceTypeId = m.PriceTypeId,
- PriceCode = m.PriceCode,
- UseYN = m.UseYN
- });
- }
- db.SaveChanges();
- transaction.Complete();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- [ResponseType(typeof(void))]
- [ActionName("Delete")]
- public IHttpActionResult PostBemsSitePriceDelete(SitePrice SitePrice)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- using (var transaction = new TransactionScope())
- {
- var foundQuery = db.BemsSitePrice.Where(x =>
- x.SiteID == SitePrice.SiteId &&
- x.FuelTypeId == SitePrice.FuelTypeId &&
- x.PriceTypeId == SitePrice.PriceTypeId &&
- x.PriceCode == SitePrice.PriceCode);
- db.BemsSitePrice.Remove(foundQuery.FirstOrDefault()); //한개만 지운다
- //new QueryManager<BemsSitePrice>(db).Delete(db.BemsSitePrice, foundQuery);//여러개
- db.SaveChanges();
- transaction.Complete();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- [ResponseType(typeof(void))]
- [ActionName("DeleteAll")]
- public IHttpActionResult PostBemsSitePriceDeleteAll(SitePrice SitePrice)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- using (var transaction = new TransactionScope())
- {
- var foundQuery = db.BemsSitePrice.Where(x =>
- x.SiteID == SitePrice.SiteId &&
- x.PriceTypeId == SitePrice.PriceTypeId);
- //db.BemsSitePrice.Remove(foundQuery.FirstOrDefault()); 한개만 지운다
- new QueryManager<BemsSitePrice>(db).Delete(db.BemsSitePrice, foundQuery);
- db.SaveChanges();
- transaction.Complete();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- private bool BemsSitePriceExists(int id)
- {
- return db.BemsSitePrice.Count(e => e.SiteID == id) > 0;
- }
- public class SitePrice
- {
- public int SiteId { get; set; }
- public Int16 FuelTypeId { get; set; }
- public int PriceTypeId { get; set; }
- public string PriceCode { get; set; }
- public string UseYN { get; set; }
- };
- }
- }
|