public static void Initialize(IServiceProvider serviceProvider) { using (var context = new AdContext( serviceProvider.GetRequiredService <DbContextOptions <AdContext> >())) { // Look for any advertisement if (context.Categories.Any()) { return; // DB has been seeded } context.Categories.AddRange( new Category { Name = "Consumering" }, new Category { Name = "Dienst" }, new Category { Name = "Product" }, new Category { Name = "Politiek" } ); context.SaveChanges(); } }
protected void Page_Load(object sender, EventArgs e) { context = new AdContext(); EditedAd = context.Ads.Find(Int32.Parse(Request.QueryString["id"])); if (!IsPostBack) { DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { context = new AdContext(); EditedAd = context.Ads.Find(Int32.Parse(Request.QueryString["id"])); if (!IsPostBack) { EditedAd.Status = ReviewStatus.InReview; context.SaveChanges(); DataBind(); } }
public AccountController() { using (var context = new AdContext()) { var config = context.DirectorySetups.AsNoTracking().FirstOrDefault(); var domain = config?.DomainName.Split('.'); if (domain != null) { _userManager = new ActiveDirectoryManager(config.IpAddress, $"DC={domain[0]},DC={domain[1]}", config.ServiceUserName, config.ServicePassword); } } }
private void SeedAdCategory(AdContext context) { for (int i = 1; i <= 10; i++) { var adcat = new AdCategory() { Id = i, AdId = i / 2 + 1, CategoryId = i / 2 + 2 }; context.Set <AdCategory>().AddOrUpdate(adcat); } context.SaveChanges(); }
private void SeedCategories(AdContext context) { for (int i = 1; i <= 10; i++) { var category = new Category() { Id = i, CategoryName = " Category Name" + i.ToString(), ParentId = i }; context.Set <Category>().AddOrUpdate(category); } context.SaveChanges(); }
protected void Page_Load(object sender, EventArgs e) { context = new AdContext(); try { DisplayedAd = context.Ads.Find(Int32.Parse(Request.QueryString["id"])); if (!TokenService.CheckToken(Request.QueryString["token"], DisplayedAd)) { Response.Redirect("/"); } } catch (Exception) { } DataBind(); }
protected void PostAd(object sender, EventArgs e) { AdContext context = new AdContext(); Ad ad = new Ad { Id = 1, Text = Neutralize(AdText.Text), CreatorUser = User.Identity.Name, Status = ReviewStatus.WaitingForReview, Approved = AutoApprove.Checked }; context.Ads.Add(ad); context.SaveChanges(); AdText.Text = ""; Message = "Ad Posted. An Approver will check and approve it soon!"; }
private void SeedRoles(AdContext context) { var roleManager = new RoleManager <Microsoft.AspNet.Identity.EntityFramework.IdentityRole> (new RoleStore <IdentityRole>()); if (!roleManager.RoleExists("Admin")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Admin"; roleManager.Create(role); } if (!roleManager.RoleExists("Employee")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Employee"; roleManager.Create(role); } }
private void SeedUsers(AdContext context) { var store = new UserStore <User>(context); var manager = new UserManager <User>(store); if (!context.Users.Any(u => u.UserName == "Admin")) { var user = new User { UserName = "******" }; var adminresult = manager.Create(user, "12345678"); if (adminresult.Succeeded) { manager.AddToRole(user.Id, "Admin"); } } if (!context.Users.Any(u => u.UserName == "Bartek")) { var user = new User { UserName = "******" }; var adminresult = manager.Create(user, "12345678"); if (adminresult.Succeeded) { manager.AddToRole(user.Id, "Employee"); } } if (!context.Users.Any(u => u.UserName == "ceo")) { var user = new User { UserName = "******" }; var adminresult = manager.Create(user, "12345678"); if (adminresult.Succeeded) { manager.AddToRole(user.Id, "Admin"); } } }
private void SeedAdvertisements(AdContext context) { var idUser = context.Set <User>().Where(u => u.UserName == "Admin").FirstOrDefault().Id; for (int i = 1; i <= 10; i++) { var ad = new Advertisement() { Id = i, UserID = idUser, Content = "Ad Content" + i.ToString(), Title = "Ad Title" + i.ToString(), DateOfAdd = DateTime.Now.AddDays(-i) }; context.Set <Advertisement>().AddOrUpdate(ad); } context.SaveChanges(); }
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new [] { "*" }); using (var dbcontext = new AdContext()) { var config = dbcontext.DirectorySetups.FirstOrDefault(); var domain = config?.DomainName.Split('.'); if (domain != null) { var principalContext = new ActiveDirectoryManager(config.IpAddress, $"DC={domain[0]},DC={domain[1]}", config.ServiceUserName, config.ServicePassword).GetPrincipalContext(); using (principalContext) { var isValid = principalContext.ValidateCredentials(context.UserName, context.Password); if (!isValid) { context.SetError("invalid_grant", "The username or password is incorrect"); return(Task.FromResult <object>(null)); } } } } var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); identity.AddClaim(new Claim(ClaimTypes.Role, "user")); context.Validated(identity); var props = new AuthenticationProperties(new Dictionary <string, string> { { "userName", context.UserName } }); var ticket = new AuthenticationTicket(identity, props); context.Validated(ticket); return(Task.FromResult <object>(null)); }
public static USerPsk GetPsk(string employeeId) { using (var context = new AdContext()) { var psk = context.USerPsks.FirstOrDefault(o => o.EmployeeId == employeeId); if (psk != null) { return(context.USerPsks.FirstOrDefault(o => o.EmployeeId == employeeId)); } { context.USerPsks.Add(new USerPsk { EmployeeId = employeeId, Psk = TimeSensitivePassCode.GeneratePresharedKey() }); context.SaveChanges(); return(context.USerPsks.FirstOrDefault(o => o.EmployeeId == employeeId)); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AdContext adContext) { adContext.Database.Migrate(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); // Swagger app.UseOpenApi(); app.UseSwaggerUi3(); }
public static void GenerateThumbnail( [QueueTrigger("thumbnailrequest")] BlobInformation blobInfo, [Blob("images/{BlobName}", FileAccess.Read)] Stream input, [Blob("images/{BlobNameWithoutExtension}_thumbnail.jpg")] CloudBlockBlob outputBlob) { using (Stream output = outputBlob.OpenWrite()) { ConvertImageToThumbnailJpg(input, output); outputBlob.Properties.ContentType = "image/jpeg"; } using (AdContext adContext = new AdContext()) { var ad = adContext.Ads.Find(blobInfo.AdId); if (ad == null) { throw new Exception(String.Format("Cannot create thumbnail for AdId {0}", blobInfo.AdId)); } ad.ThumbnailUrl = outputBlob.Uri.ToString(); adContext.SaveChanges(); } }
public async Task <IHttpActionResult> Config(DirectorySetup setup) { using (var context = new AdContext()) { if (setup.Id == default(int)) { context.DirectorySetups.Add(setup); } else { var data = context.DirectorySetups.Find(setup.Id); if (data != null) { data.DomainName = setup.DomainName; data.IpAddress = setup.IpAddress; data.ServiceUserName = setup.ServiceUserName; data.ServicePassword = setup.ServicePassword; } } await context.SaveChangesAsync(); return(Ok(new { state = true, message = "setup successful" })); } }
public AdController() { _adContext = new AdContext(); InitializeStorage(); }
public AdService(AdContext context) { _context = context; }
public HomeController(AdContext context, IHttpContextAccessor httpContextAccessor) { _context = context; _userName = httpContextAccessor.HttpContext.User.Identity.Name; }
public CategoriesController(AdContext context) { _context = context; }
public AdRepository(AdContext context) { _context = context; }
public PutAdViewModelsController(AdContext context) { _context = context; }
public TController(AdContext context) { _context = context; }
public AdvertisementsController(AdContext context) { _context = context; }
public HomeController(AdContext context) { _context = context; }