예제 #1
0
        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();
            }
        }
예제 #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     context  = new AdContext();
     EditedAd = context.Ads.Find(Int32.Parse(Request.QueryString["id"]));
     if (!IsPostBack)
     {
         DataBind();
     }
 }
예제 #3
0
 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();
     }
 }
예제 #4
0
        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);
                }
            }
        }
예제 #5
0
 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();
 }
예제 #6
0
 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();
 }
예제 #7
0
 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();
 }
예제 #8
0
        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!";
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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");
                }
            }
        }
예제 #11
0
        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));
        }
예제 #13
0
 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));
         }
     }
 }
예제 #14
0
파일: Startup.cs 프로젝트: blomma/rest
        // 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();
        }
예제 #15
0
        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();
            }
        }
예제 #16
0
        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" }));
            }
        }
예제 #17
0
 public AdController()
 {
     _adContext = new AdContext();
     InitializeStorage();
 }
예제 #18
0
파일: AdService.cs 프로젝트: DCOSMINC/AdApp
 public AdService(AdContext context)
 {
     _context = context;
 }
예제 #19
0
 public HomeController(AdContext context, IHttpContextAccessor httpContextAccessor)
 {
     _context  = context;
     _userName = httpContextAccessor.HttpContext.User.Identity.Name;
 }
예제 #20
0
 public CategoriesController(AdContext context)
 {
     _context = context;
 }
예제 #21
0
파일: AdRepository.cs 프로젝트: Szune/Adlib
 public AdRepository(AdContext context)
 {
     _context = context;
 }
예제 #22
0
 public PutAdViewModelsController(AdContext context)
 {
     _context = context;
 }
예제 #23
0
 public TController(AdContext context)
 {
     _context = context;
 }
예제 #24
0
 public AdvertisementsController(AdContext context)
 {
     _context = context;
 }
예제 #25
0
 public HomeController(AdContext context)
 {
     _context = context;
 }