Example #1
0
        public void UpdateUser(LaughUser user)
        {
            var theUser = _context.Users.Where(u => u.Id == user.Id).FirstOrDefault();

            theUser = user;
        }
Example #2
0
        public async Task EnsureSeeded() //initial seed for LaughDb
        {
            if (await _userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                var newUser = new LaughUser()
                {
                    UserName = "******",
                    Email    = "*****@*****.**",
                    Jokes    = new List <Joke>()
                    {
                        new Joke()
                        {
                            JokeText    = "Why did the chicken cross the road?",
                            Punchline   = "To get to the other side.",
                            DateCreated = DateTime.UtcNow,
                            Uploader    = "admin"
                        },
                        new Joke()
                        {
                            JokeText    = "What do you call two Mexicans playing basketball?",
                            Punchline   = "Juan on Juan.",
                            DateCreated = DateTime.UtcNow,
                            Uploader    = "admin"
                        }
                    }
                };

                //create the default admin user with two default jokes in the jokes collection
                var userResult = await _userManager.CreateAsync(newUser, "passw0rd");

                if (!userResult.Succeeded)
                {
                    Console.WriteLine("ERRORS CREATING USER: "******"Test" };
            //_context.Users.Include(p => p.Jokes).Where(u => u.UserName == "admin").FirstOrDefault().Jokes.Add(testJoke);
            //await _context.SaveChangesAsync();

            //create default ratings
            if (!_context.Ratings.Any())
            {
                var defaultRating = new Rating()
                {
                    HotRating       = 5,
                    OffensiveRating = 5,
                    Joke            = _context.Jokes.First(),
                    User            = _context.Users.First()
                };

                _context.Ratings.Add(defaultRating);
                await _context.SaveChangesAsync();
            }
        }