Exemple #1
0
        public static bool AllowApplications(this IPrincipal user, ClimbingContext db, long compID)
        {
            if (!user.Identity.IsAuthenticated)
            {
                return(false);
            }
            if (user.IsInRoleComp(db, RoleEnum.Admin, compID))
            {
                return(true);
            }
            if (user.IsInRoleComp(db, RoleEnum.User, compID, false))
            {
                return(true);
            }
            var comp = db.Competitions.Find(compID);

            if (comp == null)
            {
                return(false);
            }
            var dbUser = user.GetDbUser(db, false);

            if (dbUser == null)
            {
                return(false);
            }
            if (dbUser.RegionId == null)
            {
                return(false);
            }
            return((dbUser.Region.IidParent ?? 0) == (comp.Region.IidParent ?? 0));
        }
Exemple #2
0
 public static IEnumerable <RegionModel> AdminRegions(this IPrincipal user, ClimbingContext db)
 {
     if (!user.Identity.IsAuthenticated)
     {
         return(new RegionModel[0]);
     }
     return(user.GetDbUser(db).AdminRegions());
 }
Exemple #3
0
        //private static ClimbingContext db = new ClimbingContext();

        private static bool IsInRole(IPrincipal user, ClimbingContext db,
                                     Func <UserRoleModel, bool> roleSelector)
        {
            if (!user.Identity.IsAuthenticated)
            {
                return(false);
            }
            return(IsInRole(user.GetDbUser(db, false), roleSelector));
        }
Exemple #4
0
        public static bool AllowRegistration(this IPrincipal user, ClimbingContext db)
        {
            if (!user.Identity.IsAuthenticated)
            {
                return(false);
            }
            var dbUser = user.GetDbUser(db, false);

            if (dbUser == null)
            {
                return(false);
            }
            return(dbUser.Roles.Where(r => r.CompID == null).Count(r => r.RoleId >= (int)RoleEnum.Admin) > 0);
        }
Exemple #5
0
        public static bool IsInRoleComp(this IPrincipal user, ClimbingContext db, RoleEnum role, long CompId, bool checkRegion = true)
        {
            if (IsInRole(user, db, (ur => ur.RegionID == null && ur.CompID == CompId && ur.RoleId >= (int)role)))
            {
                return(true);
            }
            if (!checkRegion)
            {
                return(false);
            }
            var comp = db.Competitions.Find(CompId);

            if (comp == null)
            {
                return(false);
            }
            return(user.IsInRole(db, role, comp.Region.IidParent));
        }
        protected override void Seed(ClimbingContext context)
        {
            //RoleModel admRole = null, compAdmRole = null;
            Dictionary<RoleEnum, RoleModel> roles = new Dictionary<RoleEnum, RoleModel>();
            foreach (var e in Enum.GetValues(typeof(RoleEnum)).Cast<RoleEnum>())
            {
                var tmp = context.Roles.Add(new RoleModel
                {
                    Name = e.GetFriendlyValue(),
                    RoleCode = e
                });
                roles.Add(e, tmp);
            }
           

            var usr = context.UserProfiles.Add(new UserProfileModel
            {
                Name = "admin",
                Inactive = false,
                Email = "*****@*****.**",
                Roles = new List<UserRoleModel>{
                    new UserRoleModel{Role = roles[RoleEnum.Admin]}}
            });
            usr.SetPassword("0");

            #region AgeGroups
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Мужчины",
                SecretaryName = "Мужчины",
                GenderProperty = Gender.Male
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Женщины",
                SecretaryName = "Женщины",
                GenderProperty = Gender.Female
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Юниоры (18-19 лет)",
                SecretaryName = "Юниоры",
                GenderProperty = Gender.Male,
                MinAge = 18,
                MaxAge = 19
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Юниорки (18-19 лет)",
                SecretaryName = "Юниорки",
                GenderProperty = Gender.Female,
                MinAge = 18,
                MaxAge = 19
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Старшие юноши (16-17 лет)",
                SecretaryName = "Старшие юноши",
                GenderProperty = Gender.Male,
                MinAge = 16,
                MaxAge = 17
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Старшие девушки (16-17 лет)",
                SecretaryName = "Старшие девушки",
                GenderProperty = Gender.Female,
                MinAge = 16,
                MaxAge = 17
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Младшие юноши (14-15 лет)",
                SecretaryName = "Младшие юноши",
                GenderProperty = Gender.Male,
                MinAge = 14,
                MaxAge = 15
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Младшие девушки (14-15 лет)",
                SecretaryName = "Младшие девушки",
                GenderProperty = Gender.Female,
                MinAge = 14,
                MaxAge = 15
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Подростки мальчики (10-13 лет)",
                SecretaryName = "Подростки мальчики",
                GenderProperty = Gender.Male,
                MinAge = 10,
                MaxAge = 13
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Подростки девочки (10-13 лет)",
                SecretaryName = "Подростки девочки",
                GenderProperty = Gender.Female,
                MinAge = 10,
                MaxAge = 13
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Подростки мальчики (9-13 лет)",
                SecretaryName = "Подростки мальчики",
                GenderProperty = Gender.Male,
                MinAge = 9,
                MaxAge = 13
            });
            context.AgeGroups.Add(new AgeGroupModel
            {
                FullName = "Подростки девочки (9-13 лет)",
                SecretaryName = "Подростки девочки",
                GenderProperty = Gender.Female,
                MinAge = 9,
                MaxAge = 13
            });
            #endregion

            base.Seed(context);
        }
Exemple #7
0
 public static bool IsInRole(this IPrincipal user, ClimbingContext db, RoleEnum role, long?RegionId)
 {
     return(IsInRole(user, db, (ur => ur.CompID == null && ((ur.RegionID ?? 0) == (RegionId ?? 0)) && ur.RoleId >= (int)role)));
 }
Exemple #8
0
        public static UserProfileModel GetDbUser(this System.Security.Principal.IPrincipal user, ClimbingContext db, bool selectAlways = true)
        {
            if (!selectAlways && !user.Identity.IsAuthenticated)
            {
                return(null);
            }
            var users = db.UserProfiles.Where(u => u.Name.Equals(user.Identity.Name, StringComparison.OrdinalIgnoreCase));

            if (selectAlways)
            {
                return(users.First());
            }
            else
            {
                return(users.FirstOrDefault());
            }
        }