CreateWeb([Bind(webProperties)] WebPageAddressView c)
        {
            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            c.ID = c.ID ?? Guid.NewGuid().ToString();
            var o = AddressFactory.CreateWeb(c.ID, c.Url, c.ValidFrom, c.ValidTo);
            await addresses.AddObject(o);

            return(RedirectToAction("Index"));
        }
        Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var addressId = Guid.NewGuid().ToString();
                var address   = new GeographicAddressData {
                    Address   = model.AddressLine, CityOrAreaCode = model.City,
                    CountryID = getCountryCodesDictionary()[model.Country], ID = addressId,
                    ZipOrPostCodeOrExtension   = model.ZipCode,
                    RegionOrStateOrCountryCode = model.County
                };
                var user = new ApplicationUser {
                    UserName  = model.Email, Email = model.Email,
                    FirstName = model.FirstName, LastName = model.LastName, Address = address, AddressID = addressId, DateOfBirth = model.DateOfBirth
                };
                await addresses.AddObject(AddressFactory.Create(address));

                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    logger.LogInformation("User created a new account with password.");
                    var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await signInManager.SignInAsync(user, isPersistent : false);

                    logger.LogInformation("User created a new account with password.");
                    return(redirectToLocal(returnUrl));
                }

                addErrors(result);
            }

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