123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- 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 BemsPriceFormulaController : ApiController
- {
- private iBemsEntities db = new iBemsEntities();
- [ResponseType(typeof(void))]
- [ActionName("Insert")]
- public IHttpActionResult PostBemsPriceFormulaInsert(PriceFormula PriceFormula)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- // 그룹을 추가하면서 메뉴들을 그룹에 맞는 권한 테이블로 모두 옮겨 놓는다.
- using (var transaction = new TransactionScope())
- {
- var newPriceFormula = db.BemsPriceFormula.Add(new BemsPriceFormula
- {
- SiteId = PriceFormula.SiteId,
- PriceTypeId = PriceFormula.PriceTypeId,
- FacilityTypeId = PriceFormula.FacilityTypeId,
- FormulaId = PriceFormula.FormulaId,
- FacilityCode = PriceFormula.FacilityCode
- });
- 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.CmMenuUser.Add( new CmMenuUser
- // {
- // SiteId = newPriceFormula.SiteId,
- // MenuId = newPriceFormula.MenuId,
- // UserId = user.UserId,
- // } );
- // db.SaveChanges();
- transaction.Complete();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- [ResponseType(typeof(void))]
- [ActionName("InsertAll")]
- public IHttpActionResult PostBemsPriceFormulaInsertAll(List<PriceFormula> PriceFormula)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- using (var transaction = new TransactionScope())
- {
- foreach (var m in PriceFormula)
- {
- var foundQuery = db.BemsPriceFormula.Where(
- x =>
- x.SiteId == m.SiteId &&
- x.PriceTypeId == m.PriceTypeId);
- if (foundQuery.Any() == false)
- {
- var newM = db.BemsPriceFormula.Add(new BemsPriceFormula
- {
- SiteId = m.SiteId,
- PriceTypeId = m.PriceTypeId,
- FacilityTypeId = m.FacilityTypeId,
- FormulaId = m.FormulaId,
- FacilityCode = m.FacilityCode,
- });
- }
- }
- db.SaveChanges();
- transaction.Complete();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- [ResponseType(typeof(void))]
- [ActionName("DeleteAll")]
- public IHttpActionResult PostBemsPriceFormulaDeleteAll(PriceFormula PriceFormula)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- using (var transaction = new TransactionScope())
- {
- var foundQuery = db.BemsPriceFormula.Where(x =>
- x.SiteId == PriceFormula.SiteId);
- //db.BemsPriceFormula.Remove(foundQuery.FirstOrDefault()); 한개만 지운다
- new QueryManager<BemsPriceFormula>(db).Delete(db.BemsPriceFormula, foundQuery);
- db.SaveChanges();
- transaction.Complete();
- }
- }
- catch (Exception)
- {
- throw;
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- [ResponseType(typeof(void))]
- [ActionName("Update")]
- public IHttpActionResult PostBemsPriceFormulaUpdate(PriceFormula PriceFormula)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try
- {
- using (var transaction = new TransactionScope())
- {
- var foundQuery = db.BemsPriceFormula.Where(x =>
- x.SiteId == PriceFormula.SiteId &&
- x.PriceTypeId == PriceFormula.PriceTypeId);
- new QueryManager<BemsPriceFormula>(db).Delete(db.BemsPriceFormula, foundQuery);
- var newPriceFormula = db.BemsPriceFormula.Add(new BemsPriceFormula
- {
- SiteId = PriceFormula.SiteId,
- PriceTypeId = PriceFormula.PriceTypeId,
- FacilityTypeId = PriceFormula.FacilityTypeId,
- FormulaId = PriceFormula.FormulaId,
- FacilityCode = PriceFormula.FacilityCode,
- UseYN = PriceFormula.UseYN
- });
- 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 CmMenuExists(int id)
- //{
- // return db.BemsPriceFormula.Count(e => e.SiteId == id) > 0;
- //}
- public class PriceFormula
- {
- public int SiteId { get; set; }
- public int PriceTypeId { get; set; }
- public int FacilityTypeId { get; set; }
- public int FormulaId { get; set; }
- public int FacilityCode { get; set; }
- public string UseYN { get; set; }
- };
- }
- }
|