コード例 #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
ファイル: FileModels.cs プロジェクト: luke-pearson/foobox
 public static bool IsFooBoxSetUp()
 {
     using (var context = new FooBoxContext())
         return context.Files.Any();
 }
コード例 #3
0
ファイル: FileModels.cs プロジェクト: luke-pearson/foobox
 public FileManager(FooBoxContext context)
     : this(context, false)
 {
 }
コード例 #4
0
ファイル: FileModels.cs プロジェクト: luke-pearson/foobox
 public FileManager(FooBoxContext context, bool contextOwned)
 {
     _context = context;
     _contextOwned = contextOwned;
 }
コード例 #5
0
ファイル: IdentityModels.cs プロジェクト: luke-pearson/foobox
 public UserManager(FooBoxContext context)
     : this(context, false)
 {
 }