コード例 #1
0
        public ActionResult DeleteExpn(int ExpnID)
        {
            if (ExpnID != 0)
            {
                System.Web.HttpContext.Current.Application.Lock();

                DAL.MDExpn delete = _db.MDExpn.Where(p => p.ExpnID == ExpnID).FirstOrDefault();

                _db.MDExpn.Remove(delete);
                _db.SaveChanges();

                System.Web.HttpContext.Current.Application.UnLock();

                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult SaveExpn(Models.ExpnModel data)
        {
            if (!ModelState.IsValid)
            {
                if (data.ExpnID == 0)
                {
                    _db = new QSoft_WUEntities();
                    DAL.MDExpn code = _db.MDExpn.Where(p => p.ExpnCode == data.ExpnCode).FirstOrDefault();
                    if (code != null)
                    {
                        return(Json(false, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        System.Web.HttpContext.Current.Application.Lock();
                        _db = new QSoft_WUEntities();
                        _db.MDExpn.Add(new DAL.MDExpn
                        {
                            ExpnCode    = data.ExpnCode,
                            ExpnName    = data.ExpnName,
                            ExpnNameEng = data.ExpnNameEng,
                            Remark      = data.Remark,
                            ExpnType    = data.ExpnType,
                            AccID       = data.AccID,
                            ccode       = data.ccode
                        });
                        _db.SaveChanges();
                        System.Web.HttpContext.Current.Application.UnLock();
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            if (ModelState.IsValid)
            {
                if (data.ExpnID != 0)
                {
                    _db = new QSoft_WUEntities();
                    DAL.MDExpn code = _db.MDExpn.Where(p => p.ExpnCode == data.ExpnCode && p.ExpnID != data.ExpnID).FirstOrDefault();
                    if (code != null)
                    {
                        return(Json(false, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        DAL.MDExpn edit = _db.MDExpn.Where(p => p.ExpnID == data.ExpnID).FirstOrDefault();
                        edit.ExpnCode    = data.ExpnCode;
                        edit.ExpnName    = data.ExpnName;
                        edit.ExpnNameEng = data.ExpnNameEng;
                        edit.ccode       = data.ccode;
                        edit.ExpnType    = data.ExpnType;
                        edit.AccID       = data.AccID;
                        edit.Remark      = data.Remark;


                        _db.SaveChanges();

                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
            }

            return(View(data));
        }