public void Edits_users_profile()
        {
            var user = _authenticationService.User;
            var newProfile = new UserProfile
                                 {
                                     Address = "newAddress",
                                     City = "newCity",
                                     Country = "newCountry",
                                     FirstName = "newFirstName",
                                     LastName = "newLastName",
                                     PostalCode = "newPostalCode"
                                 };

            Assert.AreNotEqual(user.UserProfile.Address, newProfile.Address);
            Assert.AreNotEqual(user.UserProfile.City, newProfile.City);
            Assert.AreNotEqual(user.UserProfile.Country, newProfile.Country);
            Assert.AreNotEqual(user.UserProfile.FirstName, newProfile.FirstName);
            Assert.AreNotEqual(user.UserProfile.LastName, newProfile.LastName);
            Assert.AreNotEqual(user.UserProfile.PostalCode, newProfile.PostalCode);

            var viewModel = new AccountEditViewModel
                                {
                                    UserProfile = newProfile
                                };

            _accountController.Edit(viewModel);

            AssertEx.PropertyValuesAreEquals(newProfile, _authenticationService.User.UserProfile);
        }
        public void UpdateProfile(string email, UserProfile userProfile)
        {
            var user = FakeAuthenticationService.Users.SingleOrDefault(x => x.Email == email);

            if (user == null)
                throw new ArgumentNullException();
            if (user.UserProfile == null)
                throw new ArgumentNullException();

            user.UserProfile = userProfile;
        }
        public Order CreateOrder(string email, UserProfile userProfile)
        {
            var user = new User
                           {
                               Email = email,
                               UserProfile = userProfile
                           };

            var order = new Order { User = user };
            Orders.Add(order);

            return order;
        }
        public void UpdateProfile(string email, UserProfile userProfile)
        {
            Check.Require(!string.IsNullOrEmpty(email), "Email is null or empty");
            Check.Require(userProfile != null, "UserProfile is null");

            var user = Session.CreateCriteria<User>()
                .Add(Restrictions.Eq(User.PropertyNames.Email, email))
                .FutureValue<User>().Value;

            user.UserProfile.FirstName = userProfile.FirstName;
            user.UserProfile.LastName = userProfile.LastName;
            user.UserProfile.Country = userProfile.Country;
            user.UserProfile.City = userProfile.City;
            user.UserProfile.Address = userProfile.Address;
            user.UserProfile.PostalCode = userProfile.PostalCode;

            Session.SaveOrUpdate(user);
        }
        public Order CreateOrder(string email, UserProfile userProfile)
        {
            Check.Require(!string.IsNullOrEmpty(email));
            Check.Require(null != userProfile);
            var order = new Order();

            order.OrderDate = DateTime.Now;

            var user = _userRepository.GetUserByEmail(email);
            if (!user.UserProfile.Equals(userProfile)) {
                var id = user.UserProfile.Id;
                user.UserProfile = userProfile;
                user.UserProfile.Id = id;
                _userRepository.SaveOrUpdate(user);
            }

            order.User = user;

            order.TotalValue = ComputeTotalValue(user.ShoppingCart);

            foreach (var cartItem in user.ShoppingCart.CartItems) {
                var orderItem = new OrderItem
                                    {
                                        Movie = cartItem.Movie,
                                        Quantity = cartItem.Quantity
                                    };

                order.OrderItems.Add(orderItem);

                _orderItemRepository.SaveOrUpdate(orderItem);
            }

            _orderRepository.SaveOrUpdate(order);

            var cart = user.ShoppingCart;
            EmptyCart(ref cart);

            return order;
        }
        public override MembershipUser CreateUser(string username, string password,
                                                  string email, string passwordQuestion,
                                                  string passwordAnswer, bool isApproved,
                                                  object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel) {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != string.Empty) {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var user = GetUser(email, true);

            if (user == null) {
                var shoppingCart = new ShoppingCart();
                _shoppingCartRepository.SaveOrUpdate(shoppingCart);

                var userProfile = new UserProfile();
                _userProfileRepository.SaveOrUpdate(userProfile);

                var userObj = new User
                                  {
                                      Email = email,
                                      Password = _hashProvider.ComputeHash(password),
                                      ShoppingCart = shoppingCart,
                                      UserProfile = userProfile
                                  };

                _userRepository.SaveOrUpdate(userObj);

                status = MembershipCreateStatus.Success;

                return GetUser(userObj.Email, true);
            }

            status = MembershipCreateStatus.DuplicateEmail;

            return user;
        }
        public ActionResult Register(AccountRegisterViewModel model)
        {
            if (ModelState.IsValid) {
                var createStatus = _authenticationService.RegisterUser(model.Email, model.Password);

                if (createStatus == MembershipCreateStatus.Success) {
                    var profile = new UserProfile
                                      {
                                          FirstName = model.UserProfile.FirstName,
                                          LastName = model.UserProfile.LastName,
                                          Country = model.UserProfile.Country,
                                          Address = model.UserProfile.Address,
                                          City = model.UserProfile.City,
                                          PostalCode = model.UserProfile.PostalCode
                                      };

                    _personalizationService.UpdateProfile(model.Email, profile);
                    _authorizationService.AddUserToRole(model.Email, CustomRoleProvider.Roles.Customer);

                    _authenticationService.SignIn(model.Email, false /* createPersistentCookie */);

                    var shoppingCart = GetShoppingCart();
                    if (shoppingCart != null) {
                        _shoppingCartService.MigrateShoppingCart(model.Email, shoppingCart);

                        HttpContext.Session.Remove(ShoppingCartService.CartSessionKey);
                    }

                    return RedirectToAction("List", "Movies");
                }

                ModelState.AddModelError("", AuthenticationService.AccountValidation.ErrorCodeToString(createStatus));
            }

            return View(model);
        }
        public void SaveOrUpdate(UserProfile userProfile)
        {
            Check.Require(userProfile != null, "UserProfile is null");

            Session.SaveOrUpdate(userProfile);
        }
        public void Registers_user_when_provided_correct_parameters()
        {
            const string email = "Email1!2";
            const string password = "******";
            var profile = new UserProfile
                              {
                                  Address = "address",
                                  City = "city",
                                  Country = "Country",
                                  FirstName = "FirstName",
                                  LastName = "LastName",
                                  PostalCode = "12345"
                              };

            var viewModel = new AccountRegisterViewModel
                                {
                                    Email = email,
                                    Password = password,
                                    ConfirmPassword = password,
                                    UserProfile = profile
                                };

            var user = FakeAuthenticationService.Users.SingleOrDefault(x => x.Email == email);
            Assert.IsNull(user);

            _accountController.Register(viewModel);

            user = FakeAuthenticationService.Users.SingleOrDefault(x => x.Email == email);
            Assert.IsNotNull(user);
        }
 public void UpdateProfile(string email, UserProfile userProfile)
 {
     _userProfileRepository.UpdateProfile(email, userProfile);
 }