private async Task CreateRoles(CodeRedContext context, IServiceProvider serviceProvider) { var RoleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var UserManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); IList <IdentityRole> roles = new List <IdentityRole>(); foreach (var role in Enum.GetValues(typeof(UserRoles))) { roles.Add(new IdentityRole { Name = role.ToString(), NormalizedName = role.ToString().Normalize() }); } foreach (var role in roles) { var exists = await RoleManager.RoleExistsAsync(role.Name); if (!exists) { context.Roles.Add(role); } } await context.SaveChangesAsync(); }
public NavbarViewComponent( CodeRedContext context, IMemoryCache cache) { _context = context; _cache = cache; }
public HomeController(CodeRedContext context, UserManager <ApplicationUser> userManager, IEmailSender emailSender) { _context = context; _userManager = userManager; _emailSender = emailSender; }
public ShoppingCartController( CodeRedContext context, IOptions <AppSettings> settings, UserManager <ApplicationUser> userManager) { _context = context; _settings = settings.Value; _userManager = userManager; }
public AdminController( UserManager <ApplicationUser> userManager, ILoggerFactory loggerFactory, CodeRedContext context, IEmailSender emailSender, IMemoryCache cache) { _userManager = userManager; _logger = loggerFactory.CreateLogger <AccountController>(); _context = context; _emailSender = emailSender; _common = new Common(cache, context); }
public PartsController( CodeRedContext context, IOptions <AppSettings> settings, UserManager <ApplicationUser> userManager, IEmailSender emailSender, IMemoryCache cache) { _context = context; _settings = settings.Value; _userManager = userManager; _emailSender = emailSender; _cache = cache; _common = new Common(cache, context); }
public AccountController( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, IEmailSender emailSender, ISmsSender smsSender, ILoggerFactory loggerFactory, CodeRedContext context) { _userManager = userManager; _signInManager = signInManager; _emailSender = emailSender; _smsSender = smsSender; _logger = loggerFactory.CreateLogger <AccountController>(); _context = context; }
public static async Task <string> GetImageSrcAsync(int productId, CodeRedContext _context) { string imgSrc = "/images/Photo-Not-Available.png"; var product = await _context.Products.Include(x => x.Images).FirstOrDefaultAsync(x => x.PartId == productId); if (product.Images.Count > 0) { await Task.Run(() => { var image = product.Images.FirstOrDefault(); var base64 = Convert.ToBase64String(image.Bytes); imgSrc = $"data:image/gif;base64, {base64}"; }); } return(imgSrc); }
public AuthMessageSender(IOptions <AppSettings> settings, CodeRedContext context) { _settings = settings.Value; _context = context; }
public Common(IMemoryCache cache, CodeRedContext context) { _cache = cache; _context = context; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider, CodeRedContext context) { app.UseSession(); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //app.Use(async (ctx, next) => //{ // if (!ctx.Request.IsHttps) // { // await next(); // } // else // { // var withHttps = $"https://{ctx.Request.Host}{ctx.Request.Path}{ctx.Request.QueryString}"; // ctx.Response.Redirect(withHttps); // } //}); app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => { ctx.Context.Response.Headers.Add("Cache-Control", "public, max-age=3600"); } }); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 app.UseFacebookAuthentication(new FacebookOptions() { AppId = Configuration["Authentication:Facebook:AppId"], AppSecret = Configuration["Authentication:Facebook:AppSecret"] }); app.UseGoogleAuthentication(new GoogleOptions() { ClientId = Configuration["Authentication:Google:ClientId"], ClientSecret = Configuration["Authentication:Google:AppSecret"] }); app.UseMvc(routes => { //routes.MapRoute( // name: "referral", // template: "Referral/{referrer}", // defaults: new { controller = "Home" }); routes.MapRoute( name: "parts", template: "Parts/{action=Index}/{part=All}/{brand=All}/{car=All}/{search?}", defaults: new { controller = "Parts" }); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); await CreateRoles(context, serviceProvider); }