a989588b462b35ebb672958a6d4056d648764742.svn-base 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data.Entity;
  5. using System.Data.Entity.Infrastructure;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Web;
  9. using System.Web.Http;
  10. using System.Web.Http.Description;
  11. using DevExpress.Office.Utils;
  12. using iBemsDataService.Model;
  13. using iBemsDataService.Util;
  14. using System.Transactions;
  15. using System.Diagnostics;
  16. namespace iBemsDataService.Controllers
  17. {
  18. public class BemsPriceFormulaController : ApiController
  19. {
  20. private iBemsEntities db = new iBemsEntities();
  21. [ResponseType(typeof(void))]
  22. [ActionName("Insert")]
  23. public IHttpActionResult PostBemsPriceFormulaInsert(PriceFormula PriceFormula)
  24. {
  25. if (!ModelState.IsValid)
  26. {
  27. return BadRequest(ModelState);
  28. }
  29. try
  30. {
  31. // 그룹을 추가하면서 메뉴들을 그룹에 맞는 권한 테이블로 모두 옮겨 놓는다.
  32. using (var transaction = new TransactionScope())
  33. {
  34. var newPriceFormula = db.BemsPriceFormula.Add(new BemsPriceFormula
  35. {
  36. SiteId = PriceFormula.SiteId,
  37. PriceTypeId = PriceFormula.PriceTypeId,
  38. FacilityTypeId = PriceFormula.FacilityTypeId,
  39. FormulaId = PriceFormula.FormulaId,
  40. FacilityCode = PriceFormula.FacilityCode
  41. });
  42. db.SaveChanges();
  43. //foreach (var user in Menu.MenuUsers)
  44. //{
  45. // //menu.SiteId = newUserGroup.SiteId;
  46. // //menu.UserGroupId = newUserGroup.UserGroupId;
  47. // //db.CmUserGroupPermission.Add( menu );
  48. // //Trace.WriteLine( string.Format( "{0}-{1}" , newUserGroup.UserGroupId , menu.MenuId ) );
  49. // db.CmMenuUser.Add( new CmMenuUser
  50. // {
  51. // SiteId = newPriceFormula.SiteId,
  52. // MenuId = newPriceFormula.MenuId,
  53. // UserId = user.UserId,
  54. // } );
  55. // db.SaveChanges();
  56. transaction.Complete();
  57. }
  58. }
  59. catch (Exception)
  60. {
  61. throw;
  62. }
  63. return StatusCode(HttpStatusCode.NoContent);
  64. }
  65. [ResponseType(typeof(void))]
  66. [ActionName("InsertAll")]
  67. public IHttpActionResult PostBemsPriceFormulaInsertAll(List<PriceFormula> PriceFormula)
  68. {
  69. if (!ModelState.IsValid)
  70. {
  71. return BadRequest(ModelState);
  72. }
  73. try
  74. {
  75. using (var transaction = new TransactionScope())
  76. {
  77. foreach (var m in PriceFormula)
  78. {
  79. var foundQuery = db.BemsPriceFormula.Where(
  80. x =>
  81. x.SiteId == m.SiteId &&
  82. x.PriceTypeId == m.PriceTypeId);
  83. if (foundQuery.Any() == false)
  84. {
  85. var newM = db.BemsPriceFormula.Add(new BemsPriceFormula
  86. {
  87. SiteId = m.SiteId,
  88. PriceTypeId = m.PriceTypeId,
  89. FacilityTypeId = m.FacilityTypeId,
  90. FormulaId = m.FormulaId,
  91. FacilityCode = m.FacilityCode,
  92. });
  93. }
  94. }
  95. db.SaveChanges();
  96. transaction.Complete();
  97. }
  98. }
  99. catch (Exception)
  100. {
  101. throw;
  102. }
  103. return StatusCode(HttpStatusCode.NoContent);
  104. }
  105. [ResponseType(typeof(void))]
  106. [ActionName("DeleteAll")]
  107. public IHttpActionResult PostBemsPriceFormulaDeleteAll(PriceFormula PriceFormula)
  108. {
  109. if (!ModelState.IsValid)
  110. {
  111. return BadRequest(ModelState);
  112. }
  113. try
  114. {
  115. using (var transaction = new TransactionScope())
  116. {
  117. var foundQuery = db.BemsPriceFormula.Where(x =>
  118. x.SiteId == PriceFormula.SiteId);
  119. //db.BemsPriceFormula.Remove(foundQuery.FirstOrDefault()); 한개만 지운다
  120. new QueryManager<BemsPriceFormula>(db).Delete(db.BemsPriceFormula, foundQuery);
  121. db.SaveChanges();
  122. transaction.Complete();
  123. }
  124. }
  125. catch (Exception)
  126. {
  127. throw;
  128. }
  129. return StatusCode(HttpStatusCode.NoContent);
  130. }
  131. [ResponseType(typeof(void))]
  132. [ActionName("Update")]
  133. public IHttpActionResult PostBemsPriceFormulaUpdate(PriceFormula PriceFormula)
  134. {
  135. if (!ModelState.IsValid)
  136. {
  137. return BadRequest(ModelState);
  138. }
  139. try
  140. {
  141. using (var transaction = new TransactionScope())
  142. {
  143. var foundQuery = db.BemsPriceFormula.Where(x =>
  144. x.SiteId == PriceFormula.SiteId &&
  145. x.PriceTypeId == PriceFormula.PriceTypeId);
  146. new QueryManager<BemsPriceFormula>(db).Delete(db.BemsPriceFormula, foundQuery);
  147. var newPriceFormula = db.BemsPriceFormula.Add(new BemsPriceFormula
  148. {
  149. SiteId = PriceFormula.SiteId,
  150. PriceTypeId = PriceFormula.PriceTypeId,
  151. FacilityTypeId = PriceFormula.FacilityTypeId,
  152. FormulaId = PriceFormula.FormulaId,
  153. FacilityCode = PriceFormula.FacilityCode,
  154. UseYN = PriceFormula.UseYN
  155. });
  156. db.SaveChanges();
  157. transaction.Complete();
  158. }
  159. }
  160. catch (Exception)
  161. {
  162. throw;
  163. }
  164. return StatusCode(HttpStatusCode.NoContent);
  165. }
  166. protected override void Dispose(bool disposing)
  167. {
  168. if (disposing)
  169. {
  170. db.Dispose();
  171. }
  172. base.Dispose(disposing);
  173. }
  174. //private bool CmMenuExists(int id)
  175. //{
  176. // return db.BemsPriceFormula.Count(e => e.SiteId == id) > 0;
  177. //}
  178. public class PriceFormula
  179. {
  180. public int SiteId { get; set; }
  181. public int PriceTypeId { get; set; }
  182. public int FacilityTypeId { get; set; }
  183. public int FormulaId { get; set; }
  184. public int FacilityCode { get; set; }
  185. public string UseYN { get; set; }
  186. };
  187. }
  188. }