Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ISearch search, IDataAccess dataAccess, ICaching caching, UserManager<IdentityUser> userManager)
        {
            app.UseForwardedHeaders();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            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();
            }
            var pictures = dataAccess.GetPictures();
            var data = pictures.GroupBy(x => x.User_Id);
            var esData = new List<ES_DN_Photo>();
            foreach (var group in data)
            {
                var user = userManager.FindByIdAsync(group.Key).Result;

                esData.AddRange(group.Select(e => new ES_DN_Photo {
                    PhotoId = e.Id,
                    User = new ES_DN_User
                    {
                        UserId = user.Id,
                        Email = user.Email,
                        UserName = user.Email
                    },
                    Data = new ES_DN_Data
                    {
                        Name = e.OriginalName ?? e.Name,
                        TotalRating = e.Total_Rating,
                        Votes = e.Votes,
                        Url = e.Url,
                        Thumbnail_Url = e.Thumbnail_Url ?? e.Url
                    }
                }));
            }

            search.InsertPhotosAsync(esData);
            caching.InsertPhotosAsync(pictures);

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseSignalR(routes =>
            {
                routes.MapHub<GalleryHub>("/Comments");
            });

            app.UseMvc();
        }
Пример #2
0
        public async Task OnGet()
        {
            var rank = await _caching.GetRankAsync(3);

            if (rank == null || rank.Count() == 0)
            {
                rank = await _dataAccess.GetRankAsync(3);

                _caching.InsertPhotosAsync(rank);
            }
            Pictures = rank;
        }
Пример #3
0
        public async Task OnGet(int index = 1)
        {
            IEnumerable <User_Picture> userPictures = null;
            var Pics = await _caching.GetPhotosByScoreAsync((index - 1) * 6, index * 6);

            if (Pics == null)
            {
                Pics = await _dataAccess.GetPaginatedPicturesAsync(index, 6);

                _caching.InsertPhotosAsync(Pics);
            }
            if (Pics != null)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    userPictures = Pics.Select(elem => new User_Picture
                    {
                        Id            = elem.Id,
                        Rating        = elem.Rating,
                        Votes         = elem.Votes,
                        Url           = elem.Url,
                        Thumbnail_Url = elem.Thumbnail_Url,
                        Author        = elem.User_Id,
                        IsVoted       = true
                    });
                }
                else
                {
                    var userId   = User.FindFirst("userId");
                    var userPics = await _caching.GetVotesByUserIdAsync(userId.Value);

                    if (userPics == null || userPics.Count() == 0)
                    {
                        var picsVoted = await _dataAccess.GetVotesByUserIdAsync(userId.Value);

                        _caching.InsertVotesAsync(picsVoted);
                        userPics = picsVoted.Select(x => x.Picture_Id);
                    }
                    if (userPics != null)
                    {
                        userPictures = Pics.Select(elem => new User_Picture
                        {
                            Id            = elem.Id,
                            Rating        = elem.Rating,
                            Votes         = elem.Votes,
                            Url           = elem.Url,
                            Thumbnail_Url = elem.Thumbnail_Url,
                            Author        = elem.User_Id,
                            IsVoted       = elem.User_Id == userId.Value || userPics.Any(item => item == elem.Id)
                        });
                    }
                    else
                    {
                        userPictures = Pics.Select(elem => new User_Picture
                        {
                            Id            = elem.Id,
                            Rating        = elem.Rating,
                            Votes         = elem.Votes,
                            Url           = elem.Url,
                            Thumbnail_Url = elem.Thumbnail_Url,
                            Author        = elem.User_Id,
                            IsVoted       = elem.User_Id == userId.Value
                        });
                    }
                }
            }
            var picCount = await _dataAccess.GetPictureCountAsync();

            Pictures = new PaginatedList <User_Picture>(userPictures, (int)picCount, index, 6);
        }
Пример #4
0
        public async Task <IEnumerable <User_Picture> > GetPictures()
        {
            IEnumerable <User_Picture> user_Pictures = null;
            var Pics = await _caching.GetPhotosAsync();

            if (Pics == null)
            {
                Pics = await _dataAccess.GetPicturesAsync();

                _caching.InsertPhotosAsync(Pics);
            }
            if (Pics != null)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    user_Pictures = Pics.Select(elem => new User_Picture
                    {
                        Id            = elem.Id,
                        Rating        = elem.Rating,
                        Votes         = elem.Votes,
                        Url           = elem.Url,
                        Thumbnail_Url = elem.Thumbnail_Url,
                        Author        = elem.User_Id,
                        IsVoted       = true
                    });
                }
                else
                {
                    var userId   = User.FindFirst("userId");
                    var userPics = await _caching.GetVotesByUserIdAsync(userId.Value);

                    if (userPics == null || userPics.Count() == 0)
                    {
                        var picsVoted = await _dataAccess.GetVotesByUserIdAsync(userId.Value);

                        _caching.InsertVotesAsync(picsVoted);
                        userPics = picsVoted.Select(x => x.Picture_Id);
                    }
                    if (userPics != null)
                    {
                        return(Pics.Select(elem => new User_Picture
                        {
                            Id = elem.Id,
                            Rating = elem.Rating,
                            Votes = elem.Votes,
                            Url = elem.Url,
                            Thumbnail_Url = elem.Thumbnail_Url,
                            Author = elem.User_Id,
                            IsVoted = elem.User_Id == userId.Value || userPics.Any(item => item == elem.Id)
                        }));
                    }
                    else
                    {
                        return(Pics.Select(elem => new User_Picture
                        {
                            Id = elem.Id,
                            Rating = elem.Rating,
                            Votes = elem.Votes,
                            Url = elem.Url,
                            Thumbnail_Url = elem.Thumbnail_Url,
                            Author = elem.User_Id,
                            IsVoted = elem.User_Id == userId.Value
                        }));
                    }
                }
            }
            return(user_Pictures);
        }