// GET: Roles public ActionResult Index(RolesModel model) { DateTime startDate = model.StartDate > DateTime.MinValue ? new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day, 0, 0, 0) : DateTime.MinValue; DateTime endDate = model.EndDate > DateTime.MinValue ? new DateTime(model.EndDate.Year, model.EndDate.Month, model.EndDate.Day, 23, 59, 59) : DateTime.MinValue; var data = _sysRoles.DbQuery.Where(!string.IsNullOrEmpty(model.SearchText), o => o.Name.Contains(model.SearchText) || o.Code.Contains(model.SearchText)) .Where(model.ID > 0, o => o.ID == model.ID) .Where(startDate > DateTime.MinValue, o => o.Created >= startDate) .Where(endDate > DateTime.MinValue, o => o.Created <= endDate) .OrderByDescending(o => o.ID) .ToList(); ViewBag.Data = data.Skip(model.PageSize * model.PageIndex).Take(model.PageSize).ToList(); model.TotalRecord = data.Count; ViewBag.Model = model; var message = CacheExtends.GetDataFromCache <Message>(_keyCache + "delete"); if (message != null) { ViewBag.Message = message.Content + " (" + message.Number + " đối tượng)"; ViewBag.TypeMsg = message.Type; CacheExtends.ClearCache(_keyCache + "delete"); } return(View()); }
public async Task <IActionResult> Permission(RolesModel model, SysRole role) { var arr = model.ArrID.Split(',').ToList(); int count = arr.Count; List <SysAccess> data = new List <SysAccess>(); for (int i = 0; i < count; i++) { var iview = arr[i].Split('|'); string cname = iview[0]; string aname = iview[1]; bool isTrue = iview[2] == "true"; SysAccess item = new SysAccess() { ControlName = cname, ActionName = aname, Activity = isTrue, RoleID = model.ID }; await _sysAccess.InsertItemAsync(item); } CacheExtends.ClearCache(AuthenticationExtends.CurrentUser.RoleID.ToString() + CacheExtends.CacheAccessDefault); return(View()); }
protected List <MenuControlAttribute> GetMenuForUser(ClaimsPrincipal user, List <MenuControlAttribute> data) { try { var current = user; if (current == null || !current.Identity.IsAuthenticated) { return(null); } else { List <MenuControlAttribute> cache = CacheExtends.GetDataFromCache <List <MenuControlAttribute> >(User.Claims.FirstOrDefault(o => o.Type == ClaimTypes.Email).Value + "menmu"); if (cache != null) { return(cache); } if (current.IsInRole("administrator")) { CacheExtends.SetObjectFromCache(User.Claims.FirstOrDefault(o => o.Type == ClaimTypes.Email).Value + "menmu", Cookies.ExpiresLogin, data); return(data); } else { List <MenuControlAttribute> menuControls = new List <MenuControlAttribute>(); var access = new CPAccessService(); int count = data.Count; var cl = User.Claims.FirstOrDefault(o => o.Type == "RoleID"); if (cl == null) { return(null); } int RoleID = cl != null?int.Parse(cl.Value) : 0; for (int i = 0; i < count; i++) { var item = data[i]; if (access.GetPermission(RoleID, item.CModule, "index")) { menuControls.Add(item); } } if (menuControls != null) { CacheExtends.SetObjectFromCache(User.Claims.FirstOrDefault(o => o.Type == ClaimTypes.Email).Value + "menmu", Cookies.ExpiresLogin, menuControls); return(menuControls); } else { return(null); } } } } catch { return(null); } }
// GET: System public ActionResult Index() { var cache = CacheExtends.GetDataFromCache <List <CusMenuAttribute> >(_keyCache); var data = cache ?? GetMenuFromList(); if (cache == null) { CacheExtends.SetObjectFromCache(_keyCache, 400, data); } ViewBag.Data = data; return(View()); }
public async Task <IActionResult> Delete(RolesModel model) { Message messageSuccess = new Message(); Message messageError = new Message(); Message messageWarning = new Message(); string msg = ""; string type = "success"; int delete = 0; if (string.IsNullOrEmpty(model.ArrID)) { msg = "Dữ liệu trống"; type = "danger"; } else { var arr = model.ArrID.Split(',').Select(int.Parse).ToList(); int arrCount = arr != null ? arr.Count : 0; for (int i = 0; i < arrCount; i++) { int id = arr[i]; var item = _sysRoles.GetItemByID(id); if (item != null && item.Lock == false) { var Accs = _sysAccess.GetPermisstion(item.ID); for (int x = 0; Accs != null && x < Accs.Count; x++) { await _sysAccess.RemoveItemAsync(Accs[x]); } await _sysRoles.RemoveItemAsync(item); delete++; msg = "đã xóa"; } else { msg += "đối tượng không thuộc quyền hạn của bạn"; type = "warning"; } } } Message message = new Message() { Content = msg, Number = delete, Type = type }; CacheExtends.SetObjectFromCache(_keyCache + "delete", 240, message); return(RedirectToAction("Index", "Roles")); }
public dynamic OnLoad() { string keyCache = "_CAdv_" + MenuID + "_"; var cachevalue = CacheExtends.GetDataFromCache <dynamic>(keyCache); if (cachevalue != null && cachevalue.Data != null) { return(cachevalue); } else { ViewBag.Title = Title; var data = ChildNodes.GetChildMenuByRoot(MenuID); var cache = _advService.CreateQuery().Find(o => o.Activity == true && data.IndexOf(o.MenuID) > -1).ToList(); ViewBag.Data = cache; CacheExtends.SetObjectFromCache(keyCache, 120, ViewBag); return(ViewBag); } }