/// <summary>
        /// Called by the ASP.NET MVC framework before the action method executes.
        /// Used to ensure that there is a record created in the database for the current day.
        /// If there isn't a new day is created.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            using (var db = new LunchVoteContext())
            {
                if (!db.Days.Where(d => d.Date == DateTime.Today).Any())
                {
                    db.Days.Add(new Day
                                    {
                                        Date = DateTime.Today,
                                        Id = Guid.NewGuid()
                                    });

                    db.SaveChanges();
                }
            }
            base.OnActionExecuting(filterContext);
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, LunchVoteContext context, IDBInitializer dbInitializer)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            Mapper.Initialize(cfg => cfg.AddProfiles(typeof(Program).Assembly.GetName().Name));

            context.Database.EnsureCreated();
            dbInitializer.Initialize();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "LunchVote API V1");
                c.RoutePrefix = string.Empty;
            });

            app.UseCors(
                options => options.WithOrigins("https://localhost:44313", "http://localhost:4200").AllowAnyMethod().AllowAnyHeader()
                );

            app.UseMvc();
        }
Exemplo n.º 3
0
 public DBInitializer(LunchVoteContext context)
 {
     _context = context;
 }
Exemplo n.º 4
0
 public ProfessionalRepository(LunchVoteContext context)
 {
     _context = context;
 }
Exemplo n.º 5
0
 public VoteRepository(LunchVoteContext context)
 {
     _context = context;
 }
Exemplo n.º 6
0
 public RestaurantRepository(LunchVoteContext context)
 {
     _context = context;
 }