public static IRatingsContext SetupContext()
        {
            //var options = new DbContextOptionsBuilder<RatingsContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            var options   = new DbContextOptionsBuilder <RatingsContext>().UseSqlite("Data Source=ratings.db").Options;
            var dbContext = new RatingsContext(options);

            dbContext.Database.EnsureCreated();

            return(dbContext);
        }
예제 #2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var ctx = new RatingsContext(serviceProvider.GetRequiredService<DbContextOptions<RatingsContext>>()))
            {
                //Check if the Types are setup

                if (ctx.RatingType.Any())
                {
                    return; // DB has already been seeded
                }

                // Fill the base list of the Rating Types
                var lstRatingTypes = new List<RatingType>();
                lstRatingTypes.Add(new RatingType
                {
                    //Id = 1,
                    Name = "Excellent"
                });

                lstRatingTypes.Add(new RatingType
                {
                    //Id = 2,
                    Name = "Moderate"
                });

                lstRatingTypes.Add(new RatingType
                {
                    //Id = 3,
                    Name = "Needs Improvement"
                });

                ctx.RatingType.AddRange(lstRatingTypes);

                // Fill some sample ratings to prove it worked in the UI. 
                ctx.Rating.AddRange(
                    new Rating
                    {

                        Comments = "This was made on seeding of the database.",
                        CreatedDate = DateTime.Now,
                        RatingTypeId = 1
                    },
                    new Rating
                    {
                        Comments = "This was made as well on the seeding of the database.",
                        CreatedDate = DateTime.Now,
                        RatingTypeId = 3
                    }
                    );
                ctx.SaveChanges();
            }
        }
예제 #3
0
 public RatingsController(RatingsContext dbContext)
 {
     _dbContext = dbContext;
 }
예제 #4
0
 public RatingsController(RatingsContext context)
 {
     _context = context;
 }
 public DepartmentsController(RatingsContext context)
 {
     _context = context;
 }
예제 #6
0
 public HomeController(RatingsContext context, ILogger <HomeController> logger)
 {
     _context = context;
     _logger  = logger;
 }
 public ArchiveController(RatingsContext context)
 {
     _context = context;
 }