public ActionResult DeleteExpn(int DropShipID) { if (DropShipID != 0) { System.Web.HttpContext.Current.Application.Lock(); DAL.MDReceivePlace delete = _db.MDReceivePlace.Where(p => p.DropShipID == DropShipID).FirstOrDefault(); _db.MDReceivePlace.Remove(delete); _db.SaveChanges(); System.Web.HttpContext.Current.Application.UnLock(); return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveExpn(Models.ReceivePlaceModel data) { if (!ModelState.IsValid) { if (data.DropShipID == 0) { _db = new QSoft_WUEntities(); DAL.MDReceivePlace code = _db.MDReceivePlace.Where(p => p.DropShipCode == data.DropShipCode).FirstOrDefault(); if (code != null) { return(Json(false, JsonRequestBehavior.AllowGet)); } else { System.Web.HttpContext.Current.Application.Lock(); _db = new QSoft_WUEntities(); _db.MDReceivePlace.Add(new DAL.MDReceivePlace { DropShipID = data.DropShipID, DropShipCode = data.DropShipCode, DropShipName = data.DropShipName, Remark = data.Remark, Addr = data.Addr, District = data.District, Amphur = data.Amphur, Province = data.Province, PostCode = data.PostCode, Tel = data.Tel, Fax = data.Fax, Contact = data.Contact, ccode = data.ccode }); _db.SaveChanges(); System.Web.HttpContext.Current.Application.UnLock(); return(Json(true, JsonRequestBehavior.AllowGet)); } } } if (ModelState.IsValid) { if (data.DropShipID != 0) { _db = new QSoft_WUEntities(); DAL.MDReceivePlace code = _db.MDReceivePlace.Where(p => p.DropShipCode == data.DropShipCode && p.DropShipID != data.DropShipID).FirstOrDefault(); if (code != null) { return(Json(false, JsonRequestBehavior.AllowGet)); } else { DAL.MDReceivePlace edit = _db.MDReceivePlace.Where(p => p.DropShipID == data.DropShipID).FirstOrDefault(); edit.DropShipID = data.DropShipID; edit.DropShipCode = data.DropShipCode; edit.DropShipName = data.DropShipName; edit.Remark = data.Remark; edit.Addr = data.Addr; edit.District = data.District; edit.Amphur = data.Amphur; edit.Province = data.Province; edit.PostCode = data.PostCode; edit.Tel = data.Tel; edit.Fax = data.Fax; edit.Contact = data.Contact; edit.ccode = data.ccode; _db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); } } } return(View(data)); }