Ejemplo n.º 1
0
        public async Task <User> Create(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required!");
            }

            if (await _context.Users.AnyAsync(_user => _user.Email == user.Email))
            {
                throw new AppException("Email already exists!");
            }

            byte[] passwordHash, passwordSalt;
            GeneralHelpers.CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.Salt         = passwordSalt;

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Ejemplo n.º 2
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            byte[] passwordHash, passwordSalt;
            GeneralHelpers.CreatePasswordHash("password", out passwordHash, out passwordSalt);

            builder.Entity <User> ().HasData(
                new User {
                Id = 1, Email = "*****@*****.**", Salt = passwordSalt, PasswordHash = passwordHash
            }
                );

            var listNames = new List <string> {
                "Horror",
                "Sci Fi",
                "2018",
                "2017",
                "Action",
                "Drama",
                "The Best",
                "Movie Ever",
                "Comedy",
                "Romance"
            };
            var movieLists = listNames.Select((name, index) =>
                                              new {
                Id      = index + 1,
                Name    = name,
                Slug    = GeneralHelpers.Slugify(name, index + 1),
                UserId  = 1,
                Privacy = (index % 2 == 0),
                Created = DateTime.Now,
            });

            builder.Entity <MovieList> ().HasData(
                movieLists
                );

            builder.Entity <Movie> ().HasData(
                new {
                Id          = 1,
                MoviesDbId  = 443055,
                Title       = "Love of My Life",
                PosterPath  = "/7b19Sh0Aef5vGa0OFtvJxLe2SK9.jpg",
                ReleaseDate = "2017-02-17",
                Rating      = 5,
                Created     = DateTime.Now,
                MovieListId = 1,
                UserId      = 1
            },
                new {
                Id          = 2,
                MoviesDbId  = 454294,
                Title       = "The Kid Who Would Be King",
                PosterPath  = "/kBuvLX6zynQP0sjyqbXV4jNaZ4E.jpg",
                ReleaseDate = "2019-01-16",
                Rating      = 3,
                Created     = DateTime.Now,
                MovieListId = 1,
                UserId      = 1
            },
                new {
                Id          = 3,
                MoviesDbId  = 33125,
                Title       = "Border",
                PosterPath  = "/mmGwawOiUaP4Nkr2b1k0xsVhuY5.jpg",
                ReleaseDate = "1997-07-13",
                Rating      = 2,
                Created     = DateTime.Now,
                MovieListId = 1,
                UserId      = 1
            },
                new {
                Id          = 4,
                MoviesDbId  = 424783,
                Title       = "Bumblebee",
                PosterPath  = "/fw02ONlDhrYjTSZV8XO6hhU3ds3.jpg",
                ReleaseDate = "2018-12-15",
                Rating      = 0,
                Created     = DateTime.Now,
                MovieListId = 1,
                UserId      = 1
            },
                new {
                Id          = 5,
                MoviesDbId  = 543103,
                Title       = "Kamen Rider Heisei Generations FOREVER",
                PosterPath  = "/6sOFQDlkY6El1B2P5gklzJfVdsT.jpg",
                ReleaseDate = "2018-12-22",
                Rating      = 0,
                Created     = DateTime.Now,
                MovieListId = 1,
                UserId      = 1
            }
                );
        }