Exemplo n.º 1
0
        public JsonResult Delete(int id, FormCollection collection)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                //存在员工时不可删除
                IStaffService shfSi = new StaffService(Settings.Default.db);
                List <Staff>  shf   = shfSi.FindByDegreeType(id);

                if (null != shf && shf.Count() > 0)
                {
                    msg.Success = false;
                    msg.Content = "学历信息正在使用,不能删除!";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IDegreeTypeService cs = new DegreeTypeService(Settings.Default.db);
                    bool isSucceed        = cs.DeleteById(id);

                    msg.Success = isSucceed;
                    msg.Content = isSucceed ? "" : "删除失败";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ResultMessage()
                {
                    Success = false, Content = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }