コード例 #1
0
        public async Task <ActionResult> CreateDemoUser()
        {
            //Create new demo account for user
            var newUser = new User
            {
                FirstName     = "Guest",
                LastName      = "User",
                DisplayPeriod = "Wages",
                IsDemoAccount = true,
            };

            //Increment User Name so that all demo accounts have a unique User Name
            var demoUserID = 1;

            while (_context.Users.Any(user => user.UserName == "demo-user-" + demoUserID.ToString()))
            {
                demoUserID++;
            }

            //Assign unique User Name
            newUser.UserName = "******" + demoUserID.ToString();

            //Hash standard password, could be updated to be a config var
            newUser.HashedPassword = new PasswordHasher <User>().HashPassword(newUser, "Welcome");

            //Save Demo User
            _context.Users.Add(newUser);
            await _context.SaveChangesAsync();

            //Generate demo data for demo user
            DemoDataManager.CreateDemoData(newUser.ID);

            //Generate and return JWT Token
            return(Ok(new { Token = CreateJWT(newUser), UserInfo = newUser }));
        }
コード例 #2
0
 public ActionResult RemoveDemoData()
 {
     using (var ctx = new TicketDeskContext(null))
     {
         DemoDataManager.RemoveAllData(ctx);
     }
     DemoIdentityDataManager.RemoveAllIdentity(IdentityContext);
     ViewBag.DemoDataRemoved = true;
     return(View("Demo"));
 }
コード例 #3
0
        public ActionResult CreateDemoData()
        {
            using (var ctx = new TicketDeskContext(null))
            {
                DemoDataManager.SetupDemoData(ctx);
            }
            DemoIdentityDataManager.SetupDemoIdentityData(IdentityContext);

            ViewBag.DemoDataCreated = true;
            return(View("Demo"));
        }
コード例 #4
0
 public ActionResult CreateDemoData()
 {
     using (var ctx = new TdDomainContext(null))
     {
         DemoDataManager.SetupDemoData(ctx);
     }
     DemoIdentityDataManager.SetupDemoIdentityData(IdentityContext, User.Identity.GetUserId());
     DemoPushNotificationDataManager.SetupDemoPushNotificationData(PushNotificationContext);
     ViewBag.DemoDataCreated = true;
     return(View("Demo"));
 }
コード例 #5
0
 public ActionResult RemoveDemoData()
 {
     using (var ctx = new TdDomainContext(null))
     {
         DemoDataManager.RemoveAllData(ctx);
     }
     DemoIdentityDataManager.RemoveAllIdentity(IdentityContext);
     DemoPushNotificationDataManager.RemoveAllPushNotificationData(PushNotificationContext);
     ViewBag.DemoDataRemoved = true;
     return(View("Demo"));
 }
コード例 #6
0
        public ActionResult CreateDemoData()
        {
            using (var ctx = new TdDomainContext(null))
            {
                DemoDataManager.SetupDemoData(ctx);
            }
            DemoIdentityDataManager.SetupDemoIdentityData(IdentityContext, User.Identity.GetUserId());
            DemoPushNotificationDataManager.SetupDemoPushNotificationData(PushNotificationContext);
            ViewBag.DemoDataCreated = true;
            Task.Delay(500).ContinueWith(t => System.Web.HttpRuntime.UnloadAppDomain()).ConfigureAwait(false);

            return(View("Demo"));
        }
コード例 #7
0
        public static void RegisterDatabase()
        {
            var setupEnabled    = ConfigurationManager.AppSettings["ticketdesk:SetupEnabled"];
            var firstRunEnabled = !string.IsNullOrEmpty(setupEnabled) &&
                                  setupEnabled.Equals("true", StringComparison.InvariantCultureIgnoreCase);


            if (firstRunEnabled && !IsDatabaseReady)
            {
                //add a global filter to send requests to the database managment first run functions
                GlobalFilters.Filters.Add(new DbSetupFilter());
            }
            else
            {
                //run any pending migrations automatically to bring the DB up to date
                Database.SetInitializer(
                    new MigrateDatabaseToLatestVersion <TdDomainContext, Configuration>(true));
                using (var ctx = new TdDomainContext(null))
                {
                    try
                    {
                        ctx.Database.Initialize(!ctx.Database.CompatibleWithModel(true));
                    }
                    catch (Exception)//no metadata in DB, force run initializer anyway
                    {
                        ctx.Database.Initialize(true);
                    }
                    if (IsFirstRunDemoRefreshEnabled())
                    {
                        DemoDataManager.SetupDemoData(ctx);

                        //TODO: duplicated in FirstRunSetup controller, should refactor extension method or something... just not sure what the most appropriate place is
                        HostingEnvironment.QueueBackgroundWorkItem(async(ct) =>
                        {
                            using (var dctx = new TdDomainContext(null))
                            {
                                await TdSearchContext.Current.IndexManager.RunIndexMaintenanceAsync();
                                var searchItems = dctx.Tickets.Include("TicketEvents").ToSeachIndexItems();
                                await TdSearchContext.Current.IndexManager.AddItemsToIndexAsync(searchItems);
                            }
                        });
                    }
                }
            }
        }
コード例 #8
0
        public static void RegisterDatabase()
        {
            var setupEnabled    = ConfigurationManager.AppSettings["ticketdesk:SetupEnabled"];
            var firstRunEnabled = !string.IsNullOrEmpty(setupEnabled) &&
                                  setupEnabled.Equals("true", StringComparison.InvariantCultureIgnoreCase);


            if (firstRunEnabled && !IsDatabaseReady)
            {
                //add a global filter to send requests to the database managment first run functions
                GlobalFilters.Filters.Add(new DbSetupFilter());
            }
            else
            {
                var demoRefresh         = ConfigurationManager.AppSettings["ticketdesk:ResetDemoDataOnStartup"];
                var firstRunDemoRefresh = !string.IsNullOrEmpty(demoRefresh) &&
                                          demoRefresh.Equals("true", StringComparison.InvariantCultureIgnoreCase) &&
                                          IsDatabaseReady;//only do this if database was ready on startup, otherwise migrator will take care of it

                //run any pending migrations automatically to bring the DB up to date
                Database.SetInitializer(
                    new MigrateDatabaseToLatestVersion <TicketDeskContext, Configuration>(true));
                using (var ctx = new TicketDeskContext(null))
                {
                    try
                    {
                        ctx.Database.Initialize(!ctx.Database.CompatibleWithModel(true));
                    }
                    catch (Exception)//no metadata in DB, force run initializer anyway
                    {
                        ctx.Database.Initialize(true);
                    }
                    if (firstRunDemoRefresh)
                    {
                        DemoDataManager.SetupDemoData(ctx);
                    }
                }
            }
        }