public AbstractApiService(HappeningsContext hc, ILoginService loginServ)
 {
     // There is no gaurantee or check that HappeningsContext.Set<TEnt> will actually work
     // later revisions may change this (or even go back to the respository pattern kicking and screaming, if need be)
     happeningsContext = hc;
     loginService      = loginServ;
     currentUserId     = loginService.GetCurrentUserId();
 }
Ejemplo 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)
        {
            app.UseCors(builder => builder
                        .AllowAnyOrigin()             // in production this should be configured to only target the intended frontend site
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());
            app.UseMiddleware <MaintainCorsHeadersMiddleware>();

            // interpret requests to react as going to the proper place
            app.UseRewriter(new RewriteOptions().AddRewrite(@"^react/$", "/react/index.html", true));

            app.UseWhen(x => x.Request.Path.Value.StartsWith("/api"), builder =>
            {
                builder.UseExceptionHandler(new ExceptionHandlerOptions()
                {
                    ExceptionHandler = async(context) =>
                    {
                        context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                        context.Response.ContentType = "application/json";
                        var ex = context.Features.Get <IExceptionHandlerFeature>();
                        if (ex != null)
                        {
                            context.Response.StatusCode = ErrorPackager.GetHttpCode(ex.Error);
                            var err = new JObject();
                            err.Add("message", JToken.FromObject(ex.Error.Message));
                            await context.Response.WriteAsync(err.ToString()).ConfigureAwait(false);
                        }
                    }
                });
            });
            app.UseWhen(x => !x.Request.Path.Value.StartsWith("/api"), builder =>
            {
                if (env.IsDevelopment())
                {
                    builder.UseDeveloperExceptionPage();
                }
                else
                {
                    builder.UseExceptionHandler("/Home/Error");
                    builder.UseHsts();
                }
            });


            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseAuthentication();
            app.UseCookiePolicy();
            app.UseSession();

            app.UseMiddleware <LoginVerificationMiddleware>(); // needs to be run after authentication

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            using (var db = new HappeningsContext())
            {
                db.Database.EnsureCreated();
                //db.Database.Migrate();  // this line is in a lot of the guides but running it will make it try and double migrate, confusing matters severely

                // This is definetely hackish but most of the other solutions for database seeding are overkill for ensuring single row in a single table exists
                if (db.SystemData == null)
                {
                    db.SystemData = new Models.SystemData(Guid.NewGuid(), true);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 3
0
 // should not have other ApiServices as members since this service is itself sometimes a ApiService member
 public ReminderService(HappeningsContext hc, ILoginService loginServ) : base(hc, loginServ)
 {
 }
Ejemplo n.º 4
0
 // doesn't extend ApiService (and can't contain UserService) since it's a member of all other ApiService
 public LoginService(HappeningsContext hc, IHttpContextAccessor httpAccessor)
 {
     happeningsContext = hc;
     httpAccess        = httpAccessor;
 }
 // should not have other ApiServices as members since this service is itself sometimes a ApiService member
 public SystemDataService(HappeningsContext hc, ILoginService loginServ) : base(hc, loginServ)
 {
 }
 public InvitationService(HappeningsContext hc, ILoginService loginServ, IApiEntityService <Reminder, ReminderDto> reminderServ) : base(hc, loginServ)
 {
     reminderService = reminderServ;
 }
 public HappeningService(HappeningsContext hc, ILoginService loginServ, IInvitationEntityService invitationService, IApiEntityService <User, UserDto> userServ) : base(hc, loginServ)
 {
     joinService = invitationService;
     userService = userServ;
 }