public User MapToUser(RegisterModel viewModel, User user)
 {
     user.UserId = Guid.NewGuid();
     user.CreateDate = DateTime.Now;
     user.Password = viewModel.Password;
     user.UserName = viewModel.UserName;
     return user;
 }
        public ActionResult RegisterGmailData(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Update user with Gmail Data
                try
                {
                    var user = UserRepository.GetByUserName(User.Identity.Name);
                    user.GmailUser = model.UserName;
                    user.GmailPassword = model.Password;
                    try
                    {
                        UserRepository.Update(user);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", "Couldn't Save the user");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 private bool UserExits(RegisterModel model)
 {
     return UserRepository.GetByUserName(model.UserName) != null;
 }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (!UserExits(model))
                {
                    // Attempt to register the user
                    try
                    {
                        model.Password = PasswordHash.CreateHash(model.Password);
                        var user = UserMapper.MapToUser(model, new User());
                        try
                        {
                            var userEntity = UserRepository.Create(user);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        FormsAuthentication.SetAuthCookie(user.UserName, false);
                        return RedirectToAction("Index", "Home");
                    }
                    catch (MembershipCreateUserException e)
                    {
                        ModelState.AddModelError("", "Couldn't Register the user");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Username is already registered");
                }

            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }