Exemplo n.º 1
0
        public static List <Item> GetItems(CtsDbContext cdb, IIdentity user)
        {
            var userLogin = user.Name.Split(new char[] { '\\' }).Last();
            var domain    = user.Name.Split(new char[] { '\\' }).First();

            if (!(Cacher.Instance.TryRead(domain + userLogin + "Items") is List <Item> items))
            {
                items = new List <Item>();
                var groups = CtsAuthorizeProvider.GetUserRolesFromDb(user).Select(x => x.RoleName).ToArray();
                items.AddRange(cdb.Items.Where(n => groups.Contains(n.Location.DomainName)).ToList());

                if (items.Count > 0)
                {
                    Cacher.Instance.Write(domain + userLogin + "Items", items);
                }
            }

            return(items);
        }
Exemplo n.º 2
0
        public static List <Location> GetUserLocations(CtsDbContext cdb, IIdentity user)
        {
            var userLogin = user.Name.Split(new char[] { '\\' }).Last();
            var domain    = user.Name.Split(new char[] { '\\' }).First();

            if (!(Cacher.Instance.TryRead(domain + userLogin + "Locations") is List <Location> locations))
            {
                locations = new List <Location>();
#if DEBUG
                return(cdb.Locations.ToList());
#endif
                var groups = CtsAuthorizeProvider.GetUserRolesFromDb(user).Select(x => x.RoleName).ToArray();
                locations.AddRange(cdb.Locations.Where(n => groups.Contains(n.LocationName)).ToList());
                if (locations.Count > 0)
                {
                    Cacher.Instance.Write(domain + userLogin + "Locations", locations);
                }
            }

            return(locations);
        }