Exemplo n.º 1
0
        public IHttpActionResult RoleInfo(RoleInfoModel model)
        {
            try
            {
                var SysRole = dbContext.AC_SysRoles.FirstOrDefault(p => p.Id == model.Id);
                if (SysRole != null)
                {
                    var SysRoleCode = dbContext.AC_SysRoles.Where(p => p.Code == model.Code).ToList();
                    if (SysRoleCode.Count() > 0)
                    {
                        return(JsonResultHelper.JsonResult(1000, "角色编码已存在,请重新输入!"));
                    }
                    SysRole.Name = model.RoleName;
                }
                else
                {
                    AC_SysRoles Role = new AC_SysRoles();
                    Role.Code = model.Code;
                    Role.Name = model.RoleName;
                    dbContext.AC_SysRoles.Add(Role);
                }
                dbContext.Configuration.ValidateOnSaveEnabled = false;
                dbContext.SaveChanges();
                dbContext.Configuration.ValidateOnSaveEnabled = true;

                return(JsonResultHelper.JsonResult(0, "操作成功"));
            }
            catch (Exception ex)
            {
                return(JsonResultHelper.JsonResult(1000, ex.Message));
            }
        }
Exemplo n.º 2
0
        public object RoleInfo(RoleInfoModel model)
        {
            Result rs = new Result();

            try
            {
                var SysRole = dbContext.AC_SysRoles.FirstOrDefault(p => p.Id == model.Id);
                if (SysRole != null)
                {
                    var SysRoleCode = dbContext.AC_SysRoles.Where(p => p.Code == model.Code && p.Id != model.Id).ToList();
                    if (SysRoleCode.Count() > 0)
                    {
                        rs.strResult = "角色编码已存在,请重新输入!";
                        rs.Code      = 1001;
                        return(Json(rs));
                    }
                    SysRole.Name = model.RoleName;
                    rs.strResult = "编辑成功";
                }
                else
                {
                    AC_SysRoles Role = new AC_SysRoles();
                    Role.Code = model.Code;
                    Role.Name = model.RoleName;
                    dbContext.AC_SysRoles.Add(Role);
                    rs.strResult = "添加成功";
                }
                dbContext.Configuration.ValidateOnSaveEnabled = false;
                dbContext.SaveChanges();
                dbContext.Configuration.ValidateOnSaveEnabled = true;
                rs.Code = 0;
                return(Json(rs));
            }
            catch (Exception ex)
            {
                rs.Code      = 1001;
                rs.strResult = ex.Message;
                return(Json(rs));
            }
        }