public ActionResult SignUp(SignUpModel signUpModel)
        {
            if (ModelState.IsValid)
            {
                ValidateSignUpModel(signUpModel);
            }

            if (ModelState.IsValid)
            {
                User user = new User
                {
                    Email = signUpModel.Email,
                    First_Name = signUpModel.FirstName,
                    Last_Name = signUpModel.LastName,
                    Username = signUpModel.Username,
                    Password = BCrypt.Net.BCrypt.HashString(signUpModel.Password),
                    CreationDate = DateTime.Now
                };

                user.Role.Add(GetContext().Role.FirstOrDefault(r => r.Name == "User"));

                if (signUpModel.Username == ConfigurationManager.AppSettings["AdminName"])
                {
                    user.Role.Add(GetContext().Role.FirstOrDefault(r => r.Name == "Admin"));
                }

                GetContext().User.Add(user);
                GetContext().SaveChanges();

                user = GetContext().User
                    .FirstOrDefault(u => u.Username == signUpModel.Username);
                Authorize(user);
            }

            if (Request.IsAjaxRequest()) return PartialView("_SignUp");

            if (ModelState.IsValid)
            {
                return RedirectToAction(HomeController.IndexAction, HomeController.ControllerName,
                    new { pageNumber = signUpModel.ReturnPageNumber });
            }

            SaveModelState(ModelState);
            return RedirectToAction(SignUpAction, new { returnPageNumber = signUpModel.ReturnPageNumber });
        }
 private void ValidateSignUpModel(SignUpModel signUpModel)
 {
     User dbUser = GetContext().User
             .FirstOrDefault(u => u.Username == signUpModel.Username);
     if (dbUser != null)
     {
         ModelState.AddModelError("Username", "Sorry! This username already exists");
     }
 }