Exemple #1
0
        public static User GetUser(FixedRoles role, string AgencyName = "")
        {
            var    context = new ccEntities();
            User   newUser;
            string userName = "******" + role.ToString();

            try
            {
                newUser = context.Users.First(c => c.UserName == userName);
            }
            catch
            {
                newUser = User.CreateUser(userName, userName);
                if (AgencyName == "")
                {
                    AgencyName = "Agency1_FirstTest";
                }
                Agency a1 = context.Agencies.First(c => c.Name == AgencyName);
                newUser.AgencyId = a1.Id;
                newUser.RoleId   = (int)role;
                newUser.Email    = userName;
                //   newUser.RegionId = a1.RegionId;
                newUser.AgencyGroupId = a1.AgencyGroup.Id;
                newUser.MembershipUser.SetPassword(userName);
                context.Users.AddObject(newUser);
                context.MembershipUsers.AddObject(newUser.MembershipUser);

                context.SaveChanges();
            }

            return(newUser);
        }
 public bool IsInRole(string _role)
 {
     return(role.ToString().Equals(_role));
 }