Пример #1
0
        public async Task<ActionResult> SetUp(SetupViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new FooBoxContext())
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        using (var fileManager = new FileManager(db))
                        using (var userManager = new UserManager(db))
                        {
                            userManager.InitialSetup();
                            fileManager.InitialSetup();

                            // Create the admin user.
                            userManager.CreateUser(new User { Name = model.AdminUserName, QuotaLimit = long.MaxValue }, model.AdminPassword);
                            userManager.FindUser(model.AdminUserName).Groups.Add(userManager.FindGroup(UserManager.AdministratorsGroupName));
                            await db.SaveChangesAsync();
                        }

                        transaction.Commit();

                        return RedirectToAction("Index", "Home");
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", "Error setting up the database: " + ex.Message);
                    }
                }
            }

            // Error
            return View(model);
        }
Пример #2
0
 public Folder GetUserRootFolder(long userId)
 {
     using (var userManager = new UserManager(_context))
         return userManager.FindUser(userId).RootFolder;
 }