public ActionResult SaveTranspArea(Models.TransportasionAreaModel data) { if (!ModelState.IsValid) { if (data.TranspAreaID == 0) { _db = new QSoft_WUEntities(); DAL.MDTranspArea code = _db.MDTranspArea.Where(p => p.TranspAreaCode == data.TranspAreaCode).FirstOrDefault(); if (code != null) { return(Json(false, JsonRequestBehavior.AllowGet)); } else { System.Web.HttpContext.Current.Application.Lock(); _db = new QSoft_WUEntities(); _db.MDTranspArea.Add(new DAL.MDTranspArea { TranspAreaCode = data.TranspAreaCode, TranspAreaName = data.TranspAreaName, TranspAreaNameEng = data.TranspAreaNameEng, Remark = data.Remark, ccode = data.ccode }); _db.SaveChanges(); System.Web.HttpContext.Current.Application.UnLock(); return(Json(true, JsonRequestBehavior.AllowGet)); } } } if (ModelState.IsValid) { if (data.TranspAreaID != 0) { _db = new QSoft_WUEntities(); DAL.MDTranspArea code = _db.MDTranspArea.Where(p => p.TranspAreaCode == data.TranspAreaCode && p.TranspAreaID != data.TranspAreaID).FirstOrDefault(); if (code != null) { return(Json(false, JsonRequestBehavior.AllowGet)); } else { DAL.MDTranspArea edit = _db.MDTranspArea.Where(p => p.TranspAreaID == data.TranspAreaID).FirstOrDefault(); edit.TranspAreaCode = data.TranspAreaCode; edit.TranspAreaName = data.TranspAreaName; edit.TranspAreaNameEng = data.TranspAreaNameEng; edit.Remark = data.Remark; edit.ccode = data.ccode; _db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); } } } return(View(data)); }
public ActionResult DeleteTranspArea(int TranspAreaID) { if (TranspAreaID != 0) { System.Web.HttpContext.Current.Application.Lock(); DAL.MDTranspArea delete = _db.MDTranspArea.Where(p => p.TranspAreaID == TranspAreaID).FirstOrDefault(); _db.MDTranspArea.Remove(delete); _db.SaveChanges(); System.Web.HttpContext.Current.Application.UnLock(); return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); }