コード例 #1
0
 public override void CreateRole(string roleName)
 {
     Role newRole = new Role() { Name = roleName };
     FSContext db = new FSContext();
     db.Roles.Add(newRole);
     db.SaveChanges();
 }
コード例 #2
0
        public MembershipUser CreateUser(string login, string password)
        {
            MembershipUser membershipUser = GetUser(login, false);

            if (membershipUser == null)
            {
                try
                {
                    using (FSContext _db = new FSContext())
                    {
                        User user = new User();
                        user.Login = login;
                        user.Password = password;/*Crypto.HashPassword(password);*/

                        if (_db.Roles.Find(1) != null)
                        {
                            user.RoleId = 1; //Присваиваем по умолчанию роль Usera
                        }

                        _db.Users.Add(user);
                        _db.SaveChanges();
                        membershipUser = GetUser(login, false);
                        return membershipUser;
                    }
                }
                catch
                {
                    return null;
                }
            }
            return null;
        }