Esempio n. 1
0
 /// <summary>
 /// 返回0修改成功,1部门名已存在,不能修改
 /// </summary>
 public static int 修改部门(部门 部门)
 {
     异常处理.删除修改权限判断();
     LoveKaoExamEntities db = new LoveKaoExamEntities();
     if (db.部门表.Any(a => a.名称 == 部门.名称) == true)
     {
         return 1;
     }
     部门表 department = db.部门表.FirstOrDefault(a=>a.ID==部门.ID);
     department.名称 = 部门.名称;
     department.上级部门ID = 部门.上级部门ID;
     department.添加时间 = DateTime.Now;
     db.SaveChanges();
     return 0;
 }
        /// <summary>
        /// 编辑部门
        /// </summary>
        /// <param name="id">部门ID</param>
        /// <returns></returns>
        public ActionResult UCEditor(string id)
        {
            /* 禁止页面被缓存 */
            BasePage.PageNoCache();

            /* 部门Model */
            部门 部门Model = new 部门();

            #region try/catch(){}
            try
            {
                /* 字符串转Guid */
                Guid 部门ID = LKExamURLQueryKey.SToGuid(id);

                /* 如果部门ID不为空,表示获取该部门信息 */
                if (部门ID != Guid.Empty)
                {
                    部门Model = 部门.得到某部门根据部门ID(部门ID);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("返回部门信息出现异常,路径为:DepartmentController>UCEditor");
            }
            #endregion
            /* 返回编辑部门信息用户控件视图 */
            return View("~/Views/Admin/Department/UCEditor.ascx", 部门Model);
        }
Esempio n. 3
0
 /// <summary>
 /// 返回0成功,1部门名已存在
 /// </summary>
 public static int 添加部门(部门 部门)
 {
     LoveKaoExamEntities db = new LoveKaoExamEntities();
     if (db.部门表.Any(a => a.名称 == 部门.名称) == true)
     {
         return 1;
     }
     部门表 department = new 部门表();
     department.ID = 部门.ID;
     department.名称 = 部门.名称;
     department.上级部门ID = 部门.上级部门ID;
     department.添加人ID = 部门.创建人ID;
     department.添加时间 = DateTime.Now;
     db.部门表.AddObject(department);
     db.SaveChanges();
     return 0;
 }
        public JsonResult UCEditor(部门 model)
        {
            #region try/catch(){}
            try
            {
                /* 创建人ID */
                model.创建人ID = UserInfo.CurrentUser.用户ID;

                /* 编辑部门返回值 */
                int returnValue;

                #region 创建/修改部门Model
                /* 部门ID为空时表示添加 */
                if (model.ID == Guid.Empty)
                {
                    model.ID = Guid.NewGuid();
                    returnValue = 部门.添加部门(model);
                }
                /* 编辑部门 */
                else
                {
                    returnValue = 部门.修改部门(model);
                }
                #endregion

                #region 处理返回值
                /* 如果返回值为1表示 部门已存在 */
                if (returnValue == 1)
                {
                    return LKPageJsonResult.Exists("部门名称", model.名称);
                }

                /* 部门添加/修改成功 */
                else
                {
                    return new JsonResult
                    {
                        Data = new { result = true, info = model }
                    };
                }
                #endregion
            }
            catch (Exception ex)
            {
                /* 返回异常后Json格式字符串 */
                return LKPageJsonResult.Exception(ex);
            }
            #endregion
        }