/// <summary>
        /// Create a new user in the database.
        /// </summary>
        /// <param name="user">Object representing the registering user.</param>
        private static void CreateNewUser(RegisterUser user, bool isFacebookUser)
        {
            TenantOrganiserDbContext ctx = new TenantOrganiserDbContext();

            // If the email already exists
            if (ctx.Users.Any(u => u.Email == user.Email))
            {
                throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateEmail);
            }

            User newUser = new User
            {
                Email = user.Email,
                Password = user.Password,
                FirstName = user.FirstName,
                LastName = user.LastName,
                UserSettings = new UserSettings(),
                IsFacebookUser = isFacebookUser,
                EmailNotifications = true
            };

            ctx.Users.Add(newUser);
            ctx.SaveChanges();
        }
        public ActionResult Register(RegisterUser user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    CreateNewUser(user, false);

                    WebSecurity.Login(user.Email, user.Password);

                    FormsAuthentication.SetAuthCookie(user.Email, createPersistentCookie: false);

                    return Json(true);
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }