/// <summary>
 /// Seed the initial sample tenants
 /// </summary>
 private void SeedTenants()
 {
     if (!_context.Tenants.Any())
     {
         Tenant sampleTenantA = new Tenant
         {
             Name = "Orbital"
         };
         Tenant sampleTenantB = new Tenant
         {
             Name = "Polar"
         };
         _context.Tenants.Add(sampleTenantA);
         _context.Tenants.Add(sampleTenantB);
         _context.SaveChanges();
     }
 }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            string gCaptcha = HttpContext.Request.Params["g-recaptcha-response"];
            string userIpAddress = Request.ServerVariables["REMOTE_ADDR"];
            if (!string.IsNullOrWhiteSpace(gCaptcha) && UtilityHelper.IsGoogleReCaptchaValid(gCaptcha, userIpAddress))
            {
                if (ModelState.IsValid)
                {
                    Tenant tenant = new Tenant
                    {
                        Name = model.OrganisationName
                    };
                    IList<Tenant> tenants = new List<Tenant>();
                    tenants.Add(tenant);

                    var user = new ApplicationUser() { 
                        UserName = model.Email, 
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        OrganisationalRole = model.OrganisationalRole,
                        PhoneNumber = model.TelephoneNumber,
                        Email = model.Email, 
                        UserTenants = tenants };
                    IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                    result = await UserManager.AddToRoleAsync(user.Id, EnumHelper.Roles.Author.ToString());

                    SeedUserSettings seedUserSettings = new SeedUserSettings(user.Id);

                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);

                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }
            Alert(EnumHelper.Alerts.Error, HIResources.Strings.Change_Error);
            // If we got this far, something failed, redisplay form
            return View(model);
        }