示例#1
0
        public static void AddSampleData(this IServiceProvider services)
        {
            ISyncLocalStorageService localStorage = services.GetService <ISyncLocalStorageService>();

            if (localStorage.HasDemoDataKey())
            {
                return;
            }

            ServiceProvider = services;
            ShowAlert();

            ConsoleLog("- Starting to generate demo data! -");

            List <Theatre>      theatres = createTheaters();
            List <Hall>         halls    = new List <Hall>();
            List <Play>         plays    = new List <Play>();
            List <PlayDateTime> playDateTimes;
            List <Ticket>       tickets;
            List <User>         users = new List <User>();

            ConsoleLog("Generated Theatres:", theatres);

            foreach (var theatre in theatres)
            {
                halls.AddRange(createHalls(theatre, 4));
                plays.AddRange(createPlays(theatre, 4));
            }
            ConsoleLog("Generated Halls:", halls);
            ConsoleLog("Generated Plays:", plays);

            playDateTimes = createPlayDateTimes(halls, plays);
            ConsoleLog("Generated PlayDateTimes:", playDateTimes);

            tickets = createTickets(playDateTimes, halls);
            ConsoleLog("Generated Tickets:", tickets);

            users.Add(createUser(Lorem.Words(2), Lorem.Email(), UserType.user));
            ConsoleLog("Generated Users:", users);

            ConsoleLog("Writting to DB!");

            WriteToDb(theatres, halls, plays, playDateTimes, tickets, users);
            localStorage.AddDemoDataKey();

            ConsoleLog("- Finished!! -");
        }