Esempio n. 1
0
        public ActionResult AssignProfile(UserProfile profile)
        {
            profile.TenantId = "Test id";

            db.UserProfiles.AddObject(profile);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult CreateLogin(FormCollection form, TenantLoginViewModel model)
        {
            //todo: implement role for users!  Please design the architecture first!!!
            var tenantDb = new TenantRegistryEntities();
            var tenant   = new Tenant
            {
                id   = System.Guid.NewGuid().ToString(),
                Name = model.Tenant.Name,
                db   = System.Web.Configuration.WebConfigurationManager.AppSettings["NewTenantDatabaseName"],                    // todo: Default Tenant db must be get from a separate class
                ConnectionStringName = System.Web.Configuration.WebConfigurationManager.AppSettings["NewTenantConnectionString"] // todo: Tenant connection string must be get from a separate class
            };

            var userprofile = new UserProfile
            {
                Username  = model.UserProfile.Username,
                FirstName = model.UserProfile.FirstName,
                LastName  = model.UserProfile.LastName
            };


            // Save tenant
            tenant.UserProfiles.Add(userprofile);
            tenantDb.Tenants.AddObject(tenant);
            tenantDb.SaveChanges();


            // Create asp.net login
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                var pw    = form["Password"].ToString();
                var email = form["Email"].ToString();
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserProfile.Username, pw, email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //FormsService.SignIn(model.UserProfile.Username, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            return(View("Index"));
        }