Пример #1
0
 public override void CreateRole(string roleName)
 {
     Role newRole = new Role() { Name = roleName };
     EnterpriseContext db = new EnterpriseContext();
     db.Roles.Add(newRole);
     db.SaveChanges();
 }
        public MembershipUser CreateUser(string email, string password)
        {
            MembershipUser membershipUser = GetUser(email, false);

            if (membershipUser == null)
            {
                try
                {
                    using (EnterpriseContext _db = new EnterpriseContext())
                    {
                        User user = new User();
                        user.Email = email;
                        user.Password = Crypto.HashPassword(password);
                        user.CreationDate = DateTime.Now;

                        if (_db.Roles.Find(2) != null)
                        {
                            user.RoleId = 2;
                        }

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