Example #1
0
 public PageContent(int[] photoList, int[] textList, WebsiteContext context)
 {
     _context = context;
     //this.Photos = _context.Photos.Where(i => photoList.Contains(i.PhotoID)).Select(s => s.PhotoPath).ToList();
     //this.Texts = _context.Text.Where(i => textList.Contains(i.TextID)).Select(s =>s.Content).ToList();
     foreach (int i in photoList)
     {
         if (context.Photos.Count() >= i)
         {
             this.Photos.Add(_context.Photos.ToList()[i - 1].PhotoPath);
         }
         else
         {
             this.Photos.Add("Photo not found");
         }
     }
     foreach (int i in textList)
     {
         if (context.Text.Count() >= i)
         {
             this.Texts.Add(_context.Text.ToList()[i - 1].Content);
         }
         else
         {
             this.Texts.Add("Text not found");
         }
     }
 }
        public virtual ActionResult Edit(int id = -1)
        {
            var model = new EditViewModel();

            using (var context = new WebsiteContext())
            {
                if (!context.BlogPosts.Any(x => x.BlogPostId == id))
                {
                    RedirectToAction("Manage", "Blog");
                }

                // eagerly load the tags/comments etc as the context will be disposed
                var posts = (from t in context.BlogPosts.Include("Tags")
                             where t.BlogPostId == id
                             select t);

                if (posts.Count() > 0)
                {
                    var post = posts.First();

                    model.BlogPostId  = post.BlogPostId;
                    model.BlogTitle   = post.BlogTitle;
                    model.BlogContent = post.BlogContent;
                    ViewBag.Tags      = TagHelper.GetTagArray(post.Tags);
                }
                else
                {
                    return(RedirectToAction("Manage", "Blog"));
                }
            }

            return(View(model));
        }
        public virtual ActionResult Login(LoginViewModel model, string returnUrl)
        {
            // textboxes filled in & user is valid
            if (ModelState.IsValid && Authentication.Login(model.Username, model.Password))
            {
                return(RedirectToLocal(returnUrl));
            }

            // textboxes filled in but user is not valid
            if (ModelState.IsValid)
            {
                ModelState.AddModelError("", "Invalid user credentials.");
                using (var context = new WebsiteContext())
                {
                    context.FailedAttempts.Add(
                        new FailedAttempt {
                        DateAttempted = DateTime.Now,
                        UsernameGiven = model.Username,
                        IPAddress     = HttpContext.Request.UserHostAddress
                    }
                        );
                    context.SaveChanges();
                }
            }

            return(View(model));
        }
 public CharacterController(UserManager <ApplicationUser> userManager, IContextService contextService, WebsiteContext websiteContext, IItemMapperService itemMapperService)
 {
     _websiteContext    = websiteContext;
     _itemMapperService = itemMapperService;
     _userManager       = userManager;
     _contextService    = contextService;
 }
Example #5
0
 public ArmoryController(IContextService contextService, IItemMapperService itemMapperService, WebsiteContext websiteContext, UserManager <ApplicationUser> userManager)
 {
     _contextService    = contextService;
     _itemMapperService = itemMapperService;
     _websiteContext    = websiteContext;
     _userManager       = userManager;
 }
Example #6
0
        public static List <Tag> GetRandomTags(int limit = 0)
        {
            var tags = new List <Tag>();

            using (var context = new WebsiteContext())
            {
                var query = (from t in context.Tags
                             where t.BlogPosts.Count() > 0
                             select t).Include("BlogPosts");

                if (limit == 0)
                {
                    tags = query.ToList();
                }
                else
                {
                    tags = query.Take(limit).ToList();
                }

                // // not to be confused with the Harlem Shake
                // (https://www.youtube.com/watch?v=4hpEnLtqUDg)
                tags.Shuffle();
            }

            return(tags);
        }
        private WebsiteContext GetInMemoryDBWithSeeder()
        {
            WebsiteContext C = GetInMemoryDB();

            SeederInMemoryDB.Seed(C);
            return(C);
        }
Example #8
0
 public AdminController(WebsiteContext websiteContext, AuthContext authContext, UserManager <ApplicationUser> userManager,
                        IHubContext <SignalRHub, ISignalRHub> signalRHub)
 {
     _userManager = userManager;
     _signalRHub  = signalRHub;
     _authContext = authContext;
 }
        private WebsiteContext GetInMemoryDB()
        {
            InMemoryDB     DB = new InMemoryDB();
            WebsiteContext C  = DB.GetInMemoryDB(true);

            return(C);
        }
 public PayPalController(IPayPalService payPalService, AuthContext authContext, WebsiteContext websiteContext, UserManager <ApplicationUser> userManager)
 {
     _payPalService  = payPalService;
     _authContext    = authContext;
     _websiteContext = websiteContext;
     _userManager    = userManager;
 }
        public async void ProductNoCapitalsTest()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("CHICKENSTICKS");

            Assert.Equal("ChickenSticks", x.ElementAt(0).GetSearchAbleString());
        }
 public ReviewController(WebsiteContext context, SecteUserManager userManager, SignInManager <SecteUser> signInManager, Random random, IMemoryCache cache)
 {
     _context       = context;
     _userManager   = userManager;
     _signInManager = signInManager;
     _random        = random;
     _cache         = cache;
 }
Example #13
0
 public void AddGebruiker(User u)
 {
     using (var context = new WebsiteContext())
     {
         context.Users.Add(u);
         context.SaveChanges();
     }
 }
Example #14
0
 public static Tag GetTag(WebsiteContext context, string tag)
 {
     if (tag == "")
     {
         return(null);
     }
     return(context.Tags.First(x => x.TagName.Equals(tag, StringComparison.OrdinalIgnoreCase)));
 }
        public async void RecipePartTest()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("Nood");

            Assert.Equal("ChickenNoodles", x.ElementAt(0).GetSearchAbleString());
        }
        public async void NewsItemNoCapitalsTest()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("HAPPYPIZZA");

            Assert.Equal("HappyPizza", x.ElementAt(0).GetSearchAbleString());
        }
        public async void EmployeeNoCapitalsTest()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("JOHAN");

            Assert.Equal("Johan", x.ElementAt(0).GetSearchAbleString());
        }
        public IActionResult Index(WebsiteContext websiteContext)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            return(null);
        }
        public void AddDBOTestRecipe()
        {
            WebsiteContext   C  = GetInMemoryDB();
            SearchController SC = new SearchController(C);
            Recipe           P  = new Recipe();

            P.Name = "Cheese";
            SC.AddDBO(P, new RecipeSearch(C));
            Assert.Equal("Cheese", SC.DBO.ElementAt(0).GetSearchAbleString());
        }
        public async void SingleRecipeName()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("ChickenWings");

            string q = x.ElementAt(0).GetSearchAbleString();

            Assert.Equal("ChickenWings", q);
        }
        public async void SingleNewsItemTitle()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("HappyPizza");

            string q = x.ElementAt(0).GetSearchAbleString();

            Assert.Equal("HappyPizza", q);
        }
Example #22
0
        public IActionResult Index(bool approved = false)
        {
            var websiteContext = new WebsiteContext {
                Approved      = approved,
                CopyrightYear = 2015,
                Version       = new Version(1, 3, 3, 7),
                TagsToShow    = 20
            };

            return(View(websiteContext));
        }
Example #23
0
        public void Testcounter()
        {
            InMemoryDB     DB = new InMemoryDB();
            WebsiteContext C  = DB.GetInMemoryDB(true);

            SeederInMemoryDB.Seed(C);
            Assert.Equal(1, DB.ProductPKConvert(C.Products.ToList().ElementAt(0).ArticleNumber));
            Assert.Equal(2, DB.ProductPKConvert(C.Products.ToList().ElementAt(1).ArticleNumber));
            Assert.Equal(3, DB.ProductPKConvert(C.Products.ToList().ElementAt(2).ArticleNumber));
            Assert.Equal(4, DB.ProductPKConvert(C.Products.ToList().ElementAt(3).ArticleNumber));
        }
Example #24
0
        public WebsiteContext GetInMemoryDB(bool NewDB)
        {
            if (NewDB == true)
            {
                var options = new DbContextOptionsBuilder <WebsiteContext>()
                              .UseInMemoryDatabase(Guid.NewGuid().ToString()).UseLazyLoadingProxies()
                              .Options;
                C = new WebsiteContext(options);
            }

            return(C);
        }
Example #25
0
        public IActionResult WebsiteInformation(bool approved = false)
        {
            var context = new WebsiteContext()
            {
                Approved      = approved,
                CopyrightYear = 2020,
                TagsToShow    = 3,
                Version       = new Version(1, 1, 1)
            };

            return(View(context));
        }
Example #26
0
        public IActionResult Privacy()
        {
            WebsiteContext webContext = new WebsiteContext
            {
                Version       = new Version(1, 3),
                CopyrightYear = 1638,
                Approved      = true,
                TagsToShow    = 131
            };

            return(View(webContext));
        }
        public void AddDBOTestEmployee()
        {
            WebsiteContext   C  = GetInMemoryDB();
            SearchController SC = new SearchController(C);
            Employee_Profile P  = new Employee_Profile
            {
                Name = "Cheese"
            };

            SC.AddDBO(P, new EmployeeSearch(C));
            Assert.Equal("Cheese", SC.DBO.ElementAt(0).GetSearchAbleString());
        }
        public void AddDBOTestNewsItem()
        {
            WebsiteContext   C  = GetInMemoryDB();
            SearchController SC = new SearchController(C);
            News_Item        P  = new News_Item
            {
                Title = "Cheese"
            };

            SC.AddDBO(P, new NewsSearch(C));
            Assert.Equal("Cheese", SC.DBO.ElementAt(0).GetSearchAbleString());
        }
        public async void DoubleSearchSingleAwnserTest()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("Marit Marit");

            Assert.Equal("Marit", x.ElementAt(0).GetSearchAbleString());
            Assert.Equal(2, x.ElementAt(0).GetCounter());
            //------
            // How to test an exception: https://stackoverflow.com/questions/45017295/assert-an-exception-using-xunit
            Assert.Throws <System.ArgumentOutOfRangeException>(() => x.ElementAt(1));
            //------
        }
        public async void TotalSearchTest()
        {
            WebsiteContext   C  = GetInMemoryDBWithSeeder();
            SearchController SC = new SearchController(C);
            var x = await SC.SearchEngine("Marit Marit Ketchup ChickenWings HappyPizza");

            Assert.Equal("Marit", x.ElementAt(0).GetSearchAbleString());
            Assert.Equal(2, x.ElementAt(0).GetCounter());
            Assert.Equal(4, x.Count());
            Assert.Equal("Ketchup", x.ElementAt(1).GetSearchAbleString());
            Assert.Equal("ChickenWings", x.ElementAt(2).GetSearchAbleString());
            Assert.Equal("HappyPizza", x.ElementAt(3).GetSearchAbleString());
        }