Example #1
0
 public ApplicationUser(RegisterBindingModel model)
 {
     UserName = model.Email;
     Email = model.Email;
     FirstName = model.FirstName;
     LastName = model.LastName;
     DateCreated = DateTime.UtcNow;
     LastUpdated = DateTime.UtcNow;
 }
Example #2
0
 public UserAddress(RegisterBindingModel model, string userId)
 {
     Address = model.Address;
     City = model.City;
     State = model.State;
     ZipCode = model.ZipCode;
     UserId = userId;
     DateCreated = DateTime.UtcNow;
     LastUpdated = DateTime.UtcNow;
 }
Example #3
0
        /// <summary>
        /// Registers a new user and also ensures that address is added into the db properly
        /// </summary>
        /// <param name="model">The RegisterBindingModel with appropriate data</param>
        /// <param name="userManager">The UserManager context to perform the add</param>
        /// <returns>StatusResult</returns>
        public static StatusResult<UserInfoViewModel> RegisterUser(RegisterBindingModel model, ApplicationUserManager userManager)
        {
            UserInfoViewModel obj = null;
            try
            {
                var user = ApplicationUser.CreateUser(model);
                IdentityResult userResult = userManager.Create(user, model.Password);

                if (!userResult.Succeeded)
                {
                    return StatusResult<UserInfoViewModel>.Error();
                }

                model.Address = null;
                // add the address
                var addressResult = UserAddressManager.InsertUserAddress(model, user.Id);

                if (addressResult.Code != StatusCode.OK)
                {
                    //TODO:: Need to handle error where the address was not added successfully, can't find anything to rollback CreateAsync,
                    // it seems like CreateAsync is set to autocommit or something. 
                    // This is a little quick and dirty and hacky, but here i am just going to delete the user if we dont succeed with adding the address
                    userManager.Delete(user);
                    return StatusResult<UserInfoViewModel>.Error(addressResult.Message);
                }
                obj = new UserInfoViewModel()
                {
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Email = model.Email,
                    Id = user.Id
                };
            }
            catch (Exception ex)
            {
                return StatusResult<UserInfoViewModel>.Error(ex.Message);
            }
            return StatusResult<UserInfoViewModel>.Success(obj);
        }
        public void TestRegistration()
        {
            /*
             * {
                   "Email":"*****@*****.**",
                   "Password":"******",
                   "ConfirmPassword":"******",
                   "FirstName":"Dinh",
                   "LastName":"Ho",
                   "Address":"8303 Holly Jill Way",
                   "City":"Sacramento",
                   "State":"CA",
                   "ZipCode":"95823"
                }
             */
            AccountController controller = new AccountController();

            RegisterBindingModel model = new RegisterBindingModel()
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******",
                FirstName = "Dinh",
                LastName = "Ho",
                Address = "8303 Holly Jill Way",
                City = "Sacramento",
                State = "CA",
                ZipCode = "95823"
            };

            var result = controller.Register(model);

            // create model

            //            Assert.IsNotNull(result);
            //            Assert.AreEqual(2, result.Count());
            //            Assert.AreEqual("value1", result.ElementAt(0));
            //            Assert.AreEqual("value2", result.ElementAt(1));
        }
 public async Task<IHttpActionResult> Register(RegisterBindingModel model)
 {
     if (!ModelState.IsValid)
     {
         return Ok(StatusResult<RegisterBindingModel>.Error("There is an Error in the Model"));
     }
     var result = await BRUserManager.RegisterUserAsync(model, UserManager);
     return Ok(result);
 }
 /// <summary>
 /// Add a user address non-asyncronously
 /// </summary>
 /// <param name="model">The RegisterBindingModel with appropriate data</param>
 /// <param name="userId">The user's id</param>
 /// <returns>StatusResult</returns>
 public static StatusResult<UserAddress> InsertUserAddress(RegisterBindingModel model, string userId)
 {
     return InsertUserAddress(UserAddress.CreateAddress(model, userId));
 }
 /// <summary>
 /// Add a user address asyncronously
 /// </summary>
 /// <param name="model">The RegisterBindingModel with appropriate data</param>
 /// <param name="userId">The user's id</param>
 /// <returns>StatusResult</returns>
 public static async Task<StatusResult<UserAddress>> InsertUserAddressAsync(RegisterBindingModel model, string userId)
 {
     return await InsertUserAddressAsync(UserAddress.CreateAddress(model, userId));
 }
Example #8
0
 /// <summary>
 /// Create a UserAddress Object
 /// </summary>
 /// <param name="model">The RegisterBindingModel with appropriate data</param>
 /// <param name="userId">The user's id</param>
 /// <returns>UserAddress</returns>
 public static UserAddress CreateAddress(RegisterBindingModel model, string userId)
 {
     return new UserAddress(model, userId);
 }
Example #9
0
 public static ApplicationUser CreateUser(RegisterBindingModel model)
 {
     var user = new ApplicationUser(model);
     return user;
 }