コード例 #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MvcTitleContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <MvcTitleContext> >()))
            {
                if (context.User.Any())
                {
                    return;
                }

                var user = new User
                {
                    Name  = "Ryan",
                    Email = "*****@*****.**"
                };

                context.User.Add(user);

                context.SaveChanges();

                if (context.Title.Any())
                {
                    return;
                }

                var csvImporter = new CsvImporter();

                csvImporter.ImportTitles(context);
            }
        }
コード例 #2
0
 public TitlesController(MvcTitleContext context, ITitleRepository titleRepository,
                         WebClient webClient)
 {
     _context         = context;
     _titleRepository = titleRepository;
     _webClient       = webClient;
 }
コード例 #3
0
        public void ImportTitles(MvcTitleContext context)
        {
            using (var reader = new StreamReader(@"C:\Users\Ryan\source\repos\MvcTitle\Models\netflix_titles.csv"))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    csv.Configuration.RegisterClassMap <TitleMap>();

                    var titles = csv.GetRecords <Title>();

                    foreach (var title in titles)
                    {
                        context.Title.Add(title);
                    }

                    context.SaveChanges();
                }
        }
コード例 #4
0
 public TokensController(IConfiguration config, MvcTitleContext context)
 {
     _config  = config;
     _context = context;
 }
コード例 #5
0
 public UserRepository(MvcTitleContext context, IHttpContextAccessor httpContextAccessor)
 {
     _context             = context;
     _httpContextAccessor = httpContextAccessor;
 }
コード例 #6
0
 public UsersController(MvcTitleContext context, IUserRepository userRepository)
 {
     _context        = context;
     _userRepository = userRepository;
 }
コード例 #7
0
 public TitlesMvcController(MvcTitleContext context, ITitleRepository titleRepository)
 {
     _context         = context;
     _titleRepository = titleRepository;
 }
コード例 #8
0
 public TitleRepository(MvcTitleContext context)
 {
     _context = context;
 }