public ActionResult DeleteSupplierType(int SupplierTypeID)
        {
            if (SupplierTypeID != 0)
            {
                System.Web.HttpContext.Current.Application.Lock();

                DAL.MDSupplierType delete = _db.MDSupplierType.Where(p => p.SupplierTypeID == SupplierTypeID).FirstOrDefault();

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

                //_db.Entry(edit).State = EntityState.Modified;
                //_db.SaveChanges();

                System.Web.HttpContext.Current.Application.UnLock();
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SaveSupplierType(Models.SupplierTypeModel data)
        {
            if (!ModelState.IsValid)
            {
                if (data.SupplierTypeID == 0)
                {
                    _db = new QSoft_WUEntities();
                    DAL.MDSupplierType code = _db.MDSupplierType.Where(p => p.SupplierTypeCode == data.SupplierTypeCode && p.SupplierTypeID != data.SupplierTypeID).FirstOrDefault();
                    if (code != null)
                    {
                        return(Json(false, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        System.Web.HttpContext.Current.Application.Lock();
                        _db = new QSoft_WUEntities();
                        _db.MDSupplierType.Add(new DAL.MDSupplierType
                        {
                            SupplierTypeID   = data.SupplierTypeID,
                            SupplierTypeCode = data.SupplierTypeCode,
                            SupplierTypeName = data.SupplierTypeName,
                            SupplierTypeENG  = data.SupplierTypeENG,
                            ccode            = data.ccode
                        });
                        _db.SaveChanges();
                        System.Web.HttpContext.Current.Application.UnLock();
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            if (ModelState.IsValid)
            {
                if (data.SupplierTypeID != 0)
                {
                    _db = new QSoft_WUEntities();
                    DAL.MDSupplierType code = _db.MDSupplierType.Where(p => p.SupplierTypeCode == data.SupplierTypeCode && p.SupplierTypeID != data.SupplierTypeID).FirstOrDefault();
                    if (code != null)
                    {
                        return(Json(false, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        //System.Web.HttpContext.Current.Application.Lock();

                        DAL.MDSupplierType edit = _db.MDSupplierType.Where(p => p.SupplierTypeID == data.SupplierTypeID).FirstOrDefault();

                        edit.SupplierTypeID   = data.SupplierTypeID;
                        edit.SupplierTypeCode = data.SupplierTypeCode;
                        edit.SupplierTypeName = data.SupplierTypeName;
                        edit.SupplierTypeENG  = data.SupplierTypeENG;
                        edit.ccode            = data.ccode;
                        //edit.Remark = data.Remark;

                        _db.SaveChanges();

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

            return(View(data));
        }