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();
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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);
-
- 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);
- }
-
-
-
-
- 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; }
- };
- }
- }
|