public ActionResult Create([Bind(Include = "JokeId,Opener,Punchline")] Joke joke)
        {
            if (ModelState.IsValid)
            {
                db.Joke.Add(joke);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(joke));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var path      = @"C:/workspace/NetCoreWebApi/ConsoleAuroraMySQLEF/wocka.json";
            var jsonJokes = File.ReadAllText(path);
            var jokes     = JsonConvert.DeserializeObject <IEnumerable <Joke> >(jsonJokes);

            JokeContext context = GetContext();

            context.Database.EnsureCreated();

            var jokeCount = context.Jokes.Count();

            if (jokeCount == 0)
            {
                foreach (var batch in jokes.Batch(5000))
                {
                    context.Set <Joke>().AddRange(batch);
                    context.ChangeTracker.DetectChanges();
                    context.SaveChanges();
                    context?.Dispose();
                    context = GetContext();

                    Console.WriteLine("Writing to serverless database");
                }
            }


            //
            var oneLiners      = context.Jokes.Where(joke => joke.Category == "One Liners").ToList();
            var randomOneLiner = oneLiners.OrderBy(x => Guid.NewGuid()).First();

            Console.WriteLine($"There are {oneLiners.Count} one liners!");
            Console.WriteLine(randomOneLiner.Body);

            Console.WriteLine("Hello World!");
        }