public override string GetUserNameByEmail(string email)
        {
            using (OeContext dbContext = new OeContext())
            {
                string username = (from u in dbContext.Users
                                   where string.Compare(email, u.Email) == 0
                                   select u.Username).FirstOrDefault();

                return(!string.IsNullOrEmpty(username) ? username : string.Empty);
            }
        }
        public ActionResult Registration(RegistrationView registrationView)
        {
            bool   statusRegistration  = false;
            string messageRegistration = string.Empty;
            string activationCode      = null;

            if (ModelState.IsValid)
            {
                // Email Verification
                string userName = Membership.GetUserNameByEmail(registrationView.Email);
                if (!string.IsNullOrEmpty(userName))
                {
                    ModelState.AddModelError("Warning Email", "Sorry: Email already Exists");
                    return(View(registrationView));
                }

                //Save User Data
                using (OeContext dbContext = new OeContext())
                {
                    var user = new User()
                    {
                        Username       = registrationView.Username,
                        FirstName      = registrationView.FirstName,
                        LastName       = registrationView.LastName,
                        Email          = registrationView.Email,
                        Password       = registrationView.Password,
                        ActivationCode = Guid.NewGuid().ToString(),
                    };

                    activationCode = user.ActivationCode.ToString();
                    dbContext.Users.Add(user);
                    dbContext.SaveChanges();
                }

                //Verification Email
                VerificationEmail(registrationView.Email, activationCode);
                messageRegistration = "Your account has been created successfully. ^_^";
                statusRegistration  = true;
            }
            else
            {
                messageRegistration = "Something Wrong!";
            }
            ViewBag.Message = messageRegistration;
            ViewBag.Status  = statusRegistration;

            return(View(registrationView));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            using (OeContext dbContext = new OeContext())
            {
                var user = (from us in dbContext.Users
                            where string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0
                            select us).FirstOrDefault();

                if (user == null)
                {
                    return(null);
                }
                var selectedUser = new CustomMembershipUser(user);

                return(selectedUser);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public override bool ValidateUser(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(false);
            }

            using (OeContext dbContext = new OeContext())
            {
                var user = (from us in dbContext.Users
                            where string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(password, us.Password, StringComparison.OrdinalIgnoreCase) == 0 &&
                            us.IsActive == true
                            select us).FirstOrDefault();

                return((user != null) ? true : false);
            }
        }
        public ActionResult ActivationAccount(string id)
        {
            bool statusAccount = false;

            using (OeContext dbContext = new OeContext())
            {
                //var usrAcc = dbContext.Users.FirstOrDefault(u => u.ActivationCode == "ecd089bc-edd3-40a7-8b73-d708be9267fb");
                var userAccount = dbContext.Users.FirstOrDefault(u => u.ActivationCode.Equals(id));

                if (userAccount != null)
                {
                    userAccount.IsActive = true;
                    dbContext.SaveChanges();
                    statusAccount = true;
                }
                else
                {
                    ViewBag.Message = "Something Wrong !!";
                }
            }
            ViewBag.Status = statusAccount;
            return(View());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public override string[] GetRolesForUser(string username)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }

            var userRoles = new string[] { };

            using (OeContext dbContext = new OeContext())
            {
                var selectedUser = (from us in dbContext.Users.Include("Roles")
                                    where string.Compare(us.Username, username, StringComparison.OrdinalIgnoreCase) == 0
                                    select us).FirstOrDefault();


                if (selectedUser != null)
                {
                    userRoles = new[] { selectedUser.Roles.Select(r => r.RoleName).ToString() };
                }

                return(userRoles.ToArray());
            }
        }