Ejemplo n.º 1
0
        public static IList <int?> GetUserGroupRegions(this IPrincipal user, string groupNameOrId)
        => Cacher.FindOrCreateValWithSimpleKey(
            Cache.CreateKey(nameof(GetReassignmentGroupRegions), user.Identity.Name, groupNameOrId),
            () =>
        {
            using (var db = UloDbCreator())
            {
                var groupId = PortalHelpers.GetUserId(groupNameOrId);

                var userId = GetUserId(user?.Identity?.Name);

                return(db.UserUsers
                       .Where(uu => (uu.ParentUserId == groupId || uu.ParentUserId == groupNameOrId) && uu.ChildUserId == userId)
                       .Select(uu => uu.RegionId)
                       .Distinct()
                       .ToList()
                       .AsReadOnly());
            }
        },
            UloHelpers.MediumCacheTimeout
            );
Ejemplo n.º 2
0
 public UserHelpers(IOptions <Config> configOptions, UloDbContext db, ICacher cacher, IHttpContextAccessor acc, PortalHelpers portalHelpers)
 {
     Requires.NonNull(db, nameof(db));
     Requires.NonNull(acc, nameof(acc));
     Requires.NonNull(cacher, nameof(cacher));
     Requires.NonNull(portalHelpers, nameof(portalHelpers));
     ConfigOptions = configOptions;
     DB            = db;
     Cacher        = cacher;
     Acc           = acc;
     PortalHelpers = portalHelpers;
 }