Exemplo n.º 1
0
 /// <summary>
 /// Creates a new instance of <see cref="OrderController"/>
 /// </summary>
 /// <param name="blazorRestaurantDbContext"></param>
 /// <param name="mapper"></param>
 /// <param name="httpContextAccessor"></param>
 public OrderController(BlazorRestaurantDbContext blazorRestaurantDbContext, IMapper mapper,
                        IHttpContextAccessor httpContextAccessor)
 {
     this.BlazorRestaurantDbContext = blazorRestaurantDbContext;
     this.Mapper = mapper;
     this.HttpContextAccessor = httpContextAccessor;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of <see cref="ImageController"/>
 /// </summary>
 /// <param name="azureBlobStorageService"></param>
 /// <param name="dataStorageConfiguration"></param>
 /// <param name="blazorRestaurantDbContext"></param>
 public ImageController(AzureBlobStorageService azureBlobStorageService,
                        DataStorageConfiguration dataStorageConfiguration, BlazorRestaurantDbContext blazorRestaurantDbContext)
 {
     this.AzureBlobStorageService   = azureBlobStorageService;
     this.DataStorageConfiguration  = dataStorageConfiguration;
     this.BlazorRestaurantDbContext = blazorRestaurantDbContext;
 }
Exemplo n.º 3
0
        public static async Task CleanTests()
        {
            using BlazorRestaurantDbContext blazorRestaurantDbContext = TestsBase.CreateDbContext();
            var testEntity = await blazorRestaurantDbContext.Location.Where(p => p.Name == TestLocation.Name).SingleAsync();

            blazorRestaurantDbContext.Location.Remove(testEntity);
            await blazorRestaurantDbContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new instance of <see cref="UserController"/>
 /// </summary>
 /// <param name="blazorRestaurantDbContext">Database context</param>
 /// <param name="mapper"></param>
 public UserController(BlazorRestaurantDbContext blazorRestaurantDbContext, IMapper mapper)
 {
     this.BlazorRestaurantDbContext = blazorRestaurantDbContext;
     this.Mapper = mapper;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Configured application services
        /// </summary>
        /// <param name="services"></param>

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            GlobalPackageConfiguration.RapidApiKey = Configuration["PTIMicroservicesLibraryConfiguration:RapidApiKey"];

            var azureAdB2CSection = Configuration.GetSection("AzureAdB2C");

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddMicrosoftIdentityWebApi(azureAdB2CSection);
            services.Configure <JwtBearerOptions>(
                JwtBearerDefaults.AuthenticationScheme, options =>
            {
                options.TokenValidationParameters.NameClaimType = "name";
                options.TokenValidationParameters.RoleClaimType = "Role";
                options.Events.OnTokenValidated = async(context) =>
                {
                    BlazorRestaurantDbContext blazorRestaurantDbContext = CreateBlazorRestaurantDbContext(services);
                    ClaimsIdentity claimsIdentity = context.Principal.Identity as ClaimsIdentity;
                    var userObjectIdClaim         = claimsIdentity.Claims.Single(p => p.Type == Shared.Global.Constants.Claims.ObjectIdentifier);
                    var user = await blazorRestaurantDbContext.ApplicationUser
                               .Include(p => p.ApplicationUserRole)
                               .ThenInclude(p => p.ApplicationRole)
                               .Where(p => p.AzureAdB2cobjectId.ToString() == userObjectIdClaim.Value)
                               .SingleOrDefaultAsync();
                    if (user != null && user.ApplicationUserRole != null)
                    {
                        claimsIdentity.AddClaim(new Claim("Role", user.ApplicationUserRole.ApplicationRole.Name));
                    }
                };
                options.SaveToken = true;
            });

            services.AddTransient <ILogger <CustomHttpClientHandler>, CustomHttpClientHandlerLogger>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <ICurrentUserProvider, CurrentUserProvider>();
            services.AddScoped(serviceProvide =>
            {
                BlazorRestaurantDbContext blazorRestaurantDbContext = CreateBlazorRestaurantDbContext(serviceProvide);
                return(blazorRestaurantDbContext);
            });

            services.AddAutoMapper(configAction =>
            {
                configAction.AddMaps(new[] { typeof(Startup).Assembly });
            });

            SystemConfigurationModel systemConfiguration =
                Configuration.GetSection("SystemConfiguration").Get <SystemConfigurationModel>();

            services.AddSingleton(systemConfiguration);
            ConfigureDataStorage(services);
            ConfigurePTIMicroservicesLibraryDefaults(services);
            ConfigureAzureBlobStorage(services);

            AzureConfiguration azureConfiguration = Configuration.GetSection("AzureConfiguration").Get <AzureConfiguration>();

            services.AddSingleton(azureConfiguration);

            ConfigureAzureMaps(services, azureConfiguration);

            services.AddControllersWithViews();
            services.AddRazorPages();

            services.AddSwaggerGen(c =>
            {
                c.UseInlineDefinitionsForEnums();
                var filePath = Path.Combine(System.AppContext.BaseDirectory, "BlazorRestaurant.Server.xml");
                if (System.IO.File.Exists(filePath))
                {
                    c.IncludeXmlComments(filePath);
                }
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Configures Application
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Blazor Restaurant API");
            });
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // 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.UseExceptionHandler(cfg =>
            {
                cfg.Run(async context =>
                {
                    var exceptionHandlerPathFeature =
                        context.Features.Get <IExceptionHandlerPathFeature>();
                    var error = exceptionHandlerPathFeature.Error;
                    if (error != null)
                    {
                        try
                        {
                            BlazorRestaurantDbContext blazorRestaurantDbContext =
                                this.CreateBlazorRestaurantDbContext(context.RequestServices);
                            await blazorRestaurantDbContext.ErrorLog.AddAsync(new BlazorRestaurant.DataAccess.Models.ErrorLog()
                            {
                                FullException = error.ToString(),
                                StackTrace    = error.StackTrace,
                                Message       = error.Message
                            });
                            await blazorRestaurantDbContext.SaveChangesAsync();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    ProblemHttpResponse problemHttpResponse = new()
                    {
                        Detail = error.Message,
                    };
                    await context.Response.WriteAsJsonAsync <ProblemHttpResponse>(problemHttpResponse);
                });
            });

            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapFallbackToFile("index.html");
            });
        }