Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.4 kB
1
Indexable
Never
using JoelsFilmer.Common.DTOs;
using JoelsFilmer.Membership.Database.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JoelsFilmer.Membership.Database.Extensions
{
    public static class JFContextExtensions
    {
        public static async Task SeedMembershipData(this IDbService service)
        {
            //string description = "Filmen handlar om superhjältar";
            try
            {
                //await service.AddAsync<Director, DirectorDTO>(new DirectorDTO
                //{
                //    Name = "George Lucas"
                //});

                //await service.AddAsync<Director, DirectorDTO>(new DirectorDTO
                //{
                //    Name = "Quentin Tarantino"
                //});
                //await service.AddAsync<Director, DirectorDTO>(new DirectorDTO
                //{
                //    Name = "Martin Scoresese"

                //});
                //await service.SaveChangesAsync();
                var director1 = await service.SingleAsync<Director, DirectorDTO>(d => d.Name.Equals("George Lucas"));
                var director2 = await service.SingleAsync<Director, DirectorDTO>(d => d.Name.Equals("Quentin Tarantino"));
                var director3 = await service.SingleAsync<Director, DirectorDTO>(d => d.Name.Equals("Martin SCoresese"));

                //await service.AddAsync<Film, FilmDTO>(new FilmDTO
                //{
                //    Title = "Superheroes",
                //    Released = new DateTime(2022, 1, 1),
                //    DirectorId = director1.Id,
                //    Free = true,
                //    Description = "Filmen handlar om superhjältar",
                //    FilmUrl = "https://www.youtube.com/watch?v=zjZ5z8I7lWU"
                //});
                //await service.AddAsync<Film, FilmDTO>(new FilmDTO
                //{
                //    Title = "ProgrammerNewbie",
                //    Released = new DateTime(2021, 11, 2),
                //    DirectorId = director2.Id,
                //    Free = false,
                //    Description = "Filme handlar om en programmera som inte förstår någonting",
                //    FilmUrl = "https://www.youtube.com/watch?v=06YWGaCpky8"
                //});
                //await service.AddAsync<Film, FilmDTO>(new FilmDTO
                //{
                //    Title = "ProProgrammer",
                //    Released = new DateTime(2011, 1, 2),
                //    DirectorId = director2.Id,
                //    Free = true,
                //    Description = "Filme handlar om en programmera som förstår allt",
                //    FilmUrl = "https://www.youtube.com/watch?v=2-VKC8g2u1Y"
                //});

                //await service.AddAsync<Film, FilmDTO>(new FilmDTO
                //{
                //    Title = "MrDeeds",
                //    Released = new DateTime(2003, 5, 2),
                //    DirectorId = director3.Id,
                //    Free = false,
                //    Description = "Filmen handlar om en kille som ärver och blir rik",
                //    FilmUrl = "https://www.youtube.com/watch?v=DYerEhQMFuc"

                //});

                //await service.SaveChangesAsync();

                var film1 = await service.SingleAsync<Film, FilmDTO>(f => f.Title.Equals("Superheroes"));
                var film2 = await service.SingleAsync<Film, FilmDTO>(f => f.Title.Equals("ProgrammerNewbie"));
                var film3 = await service.SingleAsync<Film, FilmDTO>(f => f.Title.Equals("ProProgrammer"));
                var film4 = await service.SingleAsync<Film, FilmDTO>(f => f.Title.Equals("MrDeeds"));


                //await service.AddAsync<Genre, GenreDTO>(new GenreDTO
                //{
                //    Name = "Action"
                //});

                //await service.AddAsync<Genre, GenreDTO>(new GenreDTO
                //{
                //    Name = "Comedy"
                //});

                //await service.SaveChangesAsync();
                var genre1 = await service.SingleAsync<Genre, GenreDTO>(g => g.Name.Equals("Action"));
                var genre2 = await service.SingleAsync<Genre, GenreDTO>(g => g.Name.Equals("Comedy"));

                //await service.AddAsync<FilmGenre, FilmGenreDTO>(new FilmGenreDTO
                //{
                //    FilmId = 1,
                //    GenreId = 1,
                //});
                //await service.AddAsync<FilmGenre, FilmGenreDTO>(new FilmGenreDTO
                //{
                //    FilmId = 2,
                //    GenreId = 2,
                //});
                //await service.AddAsync<FilmGenre, FilmGenreDTO>(new FilmGenreDTO
                //{
                //    FilmId = 3,
                //    GenreId = 1,
                //});
                //await service.AddAsync<FilmGenre, FilmGenreDTO>(new FilmGenreDTO
                //{
                //    FilmId = 4,
                //    GenreId = 1,
                //});
                //await service.SaveChangesAsync();
            }
            catch
            {
            }

        }
    }
}