public ActionResult Create(CreateOrganisationViewModel covm) { ViewBag.Modules = Modules; ModelState.Remove("Id"); if (ModelState.IsValid) { DocumentStore ds; //check orgkey is ok. if (MvcApplication.DataBase.GetOrgStore(covm.OrgKey)!=null) { throw new Exception(String.Format("Organisation key {0} already exists", covm.OrgKey)); } var org = Mapper.Map<OrganisationViewModel, Organisation>(covm); org.OrgKey = org.OrgKey.ToLower(); AuthUser authuser; IDocumentStore newOrgStore; //create new org record in master store using (var session = MasterStore.OpenSession()) { org.CreatedOn = DateTime.Now; org.IsLive = true; session.Store(org); session.SaveChanges(); newOrgStore =CreateOrgDatabase(org,session); //create administrator and email authuser = new AuthUser { ActivationCode = Guid.NewGuid().ToString(), Id = IlluminateDatabase.GenerateId<User>(), OrgKey = org.OrgKey }; session.Store(authuser); session.SaveChanges(); } var orgUser = new User { CreatedDate = DateTime.Now, EmailAddress = covm.AdministratorEmail, Id = authuser.Id, FirstName = covm.AdministratorName.Split(' ')[0], LastName = covm.AdministratorName.Split(' ')[1], Roles = { Role.GetRole(Role.BuiltInRole.Administrator), Role.GetRole(Role.BuiltInRole.Manager), Role.GetRole(Role.BuiltInRole.Analytics) }, OrgKey = org.OrgKey }; using (var orgSession = newOrgStore.OpenSession()) { orgSession.Store(orgUser); orgSession.SaveChanges(); } ProvisionNewDatabase(newOrgStore); EmailActivation(authuser, orgUser,newOrgStore); covm = Mapper.Map<Organisation, CreateOrganisationViewModel>(org); } return View("Edit", covm); }
public ActionResult Create() { ViewBag.Modules = Modules; var org = new CreateOrganisationViewModel(); return View(org); }