public ActionResult AddActionRule(string controller, string action, int aType, string allowRoles) { IEnumerable <ActionRule> ARules = MyRedisDB.GetSet <ActionRule>(MyRedisKeys.ActionRules); ActionRule rule = ARules.Where(a => a.Controller == controller && a.Action == action).FirstOrDefault(); if (rule != null) { MyRedisDB.SetRemove(MyRedisKeys.ActionRules, rule); rule.ActionType = aType; if (!string.IsNullOrEmpty(allowRoles)) { rule.AllowRoles = allowRoles.Split(',').Select(r => int.Parse(r)).ToArray(); } else { rule.AllowRoles = null; } } else { rule = new ActionRule(); rule.Controller = controller; rule.Action = action; rule.ActionType = aType; if (!string.IsNullOrEmpty(allowRoles)) { rule.AllowRoles = allowRoles.Split(',').Select(r => int.Parse(r)).ToArray(); } } MyRedisDB.SetAdd(MyRedisKeys.ActionRules, rule); return(RedirectToAction("Manage")); }
public ActionResult AddManager(string key, string value, int role) { Manager manager = new Manager(); manager.Key = key; manager.Value = value; manager.Role = role; MyRedisDB.SetAdd(MyRedisKeys.Managers, manager); return(RedirectToAction("Manage")); }
//一键生成ActionRule public ActionResult OnkeyRules() { IEnumerable <ActionRule> ARules = MyRedisDB.GetSet <ActionRule>(MyRedisKeys.ActionRules); Dictionary <string, List <string> > actionDic = new Dictionary <string, List <string> >();//当前的所有action Assembly mvcweb = Assembly.GetExecutingAssembly(); foreach (Type type in mvcweb.GetTypes()) { if (type.Name.EndsWith("Controller")) { string controller = type.Name.Replace("Controller", ""); actionDic.Add(controller, new List <string>()); int actionType = (int)EnumActionType.前台; if (controller == "Manager") { actionType = (int)EnumActionType.Manager; } foreach (MethodInfo method in type.GetMethods()) { if (method.ReturnType == typeof(ActionResult)) { string action = method.Name; actionDic[controller].Add(action); ActionRule rule = ARules.Where(a => a.Controller == controller && a.Action == action).FirstOrDefault(); if (rule == null)//没有添加 { rule = new ActionRule(); rule.Controller = controller; rule.Action = action; rule.ActionType = actionType; MyRedisDB.SetAdd(MyRedisKeys.ActionRules, rule); } } } } } foreach (ActionRule rule in ARules)//多余删除 { if (!actionDic.Keys.Contains(rule.Controller) || !actionDic[rule.Controller].Contains(rule.Action)) { MyRedisDB.SetRemove(MyRedisKeys.ActionRules, rule); } } return(RedirectToAction("Manage")); }
public ActionResult NewBeeDelete(Guid id) { NewBee newBee = NewBeeDataSvc.GetByID(id); NewBeeDataSvc.DeleteByID(id); SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "你的" + Enum.GetName(typeof(EnumObjectType), 2) + "被删除"; msg.Msg = newBee.Title.MaxByteLength(30); string key = MyRedisKeys.Pre_SysMsg + newBee.OwnerID; MyRedisDB.SetAdd(key, msg); return(Json(new { msg = "done" })); }
public ActionResult UserOperate(string type, Guid uid, int objectType, int days = 0) { if (type == "启") { DisabledUser du = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == uid && d.ObjectType == objectType).FirstOrDefault(); MyRedisDB.SetRemove(MyRedisKeys.DisabledUsers, du); SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "你的账号已解封"; msg.Msg = "你的账号在" + Enum.GetName(typeof(EnumObjectType), objectType) + "版块中已解封"; string key = MyRedisKeys.Pre_SysMsg + uid; MyRedisDB.SetAdd(key, msg); } else { DisabledUser du = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == uid && d.ObjectType == objectType).FirstOrDefault(); if (du == null) { du = new DisabledUser(); du.UserID = uid; du.ObjectType = objectType; du.AbleDate = DateTime.Now.AddDays(days); MyRedisDB.SetAdd(MyRedisKeys.DisabledUsers, du); } else { MyRedisDB.SetRemove(MyRedisKeys.DisabledUsers, du); du.AbleDate = DateTime.Now.AddDays(days); MyRedisDB.SetAdd(MyRedisKeys.DisabledUsers, du); } SysMsg msg = new SysMsg(); msg.Date = DateTime.Now; msg.Title = "你的账号被封禁"; msg.Msg = "你在" + Enum.GetName(typeof(EnumObjectType), objectType) + "版块被封禁至" + du.AbleDate.ToString("yyyy-MM-dd HH:mm"); string key = MyRedisKeys.Pre_SysMsg + uid; MyRedisDB.SetAdd(key, msg); } return(Json(new { msg = "done" })); }