Ejemplo n.º 1
0
        public ActionResult Category(string category)
        {
            PaginationDTO <PostCardDTO>     postCardPaginationDTO   = postService.GetPostCardPagination(pageNumber: 1, pageSize: Settings.POST_PAGE_SIZE, category);
            PaginationModel <PostCardModel> postCardPaginationModel = dataMapper.MapPostCardPaginationDTOToModel(postCardPaginationDTO);

            return(View(postCardPaginationModel));
        }
Ejemplo n.º 2
0
        public ActionResult PostGrid(string category, int pageNumber = 1, string searchQuery = null)
        {
            object jsonObject;

            if (pageNumber <= 0)
            {
                jsonObject = new { status = 500 };
                return(Json(jsonObject));
            }

            PaginationDTO <PostCardDTO> postCardPaginationDTO = postService.GetPostCardPagination(pageNumber, Settings.HOME_POST_PAGE_SIZE, category, searchQuery);

            if (postCardPaginationDTO == null)
            {
                jsonObject = new { status = 500 };
            }
            else
            {
                PaginationModel <PostCardModel> postCardPaginationModel = dataMapper.MapPostCardPaginationDTOToModel(postCardPaginationDTO);

                jsonObject = new
                {
                    status = 200,
                    data   = postCardPaginationModel
                };
            }

            return(Json(jsonObject));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <List <Image> > > Get([FromQuery] PaginationDTO paginationDTO)
        {
            var queryable = _context.Images.AsQueryable();
            await HttpContext.InsertPaginationParametersInResponse(queryable, paginationDTO.RecordsPerPage); //InsertPaginationParametersInResponse located in BlazorProject.Server/Helpers/HttpContextExtensions

            return(await queryable.Paginate(paginationDTO).ToListAsync());
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <List <ReviewDTO> > > Get(int movieId, [FromQuery] PaginationDTO pagination)
        {
            var queryable = context.Reviews.Include(x => x.User).AsQueryable();

            queryable = queryable.Where(x => x.MovieId == movieId);
            return(await Get <Review, ReviewDTO>(pagination, queryable));
        }
Ejemplo n.º 5
0
        public PaginationDTO <CommentDTO> GetCommentPagination(int pageNumber, int pageSize, string postId = null, string commentId = null, string searchQuery = null)
        {
            PaginationEntity <CommentEntity> commentPaginationEntity = commentRepository.GetCommentPagination(pageNumber, pageSize, postId, commentId, searchQuery);
            PaginationDTO <CommentDTO>       commentPaginationDTO    = dataMapper.MapCommentPaginationEntityToDTO(commentPaginationEntity);

            return(commentPaginationDTO);
        }
Ejemplo n.º 6
0
        public PaginationDTO <CommentDTO> GetCommentPaginationOfPostWithPreservedFetch(string postId, DateTime createdDate, int pageSize)
        {
            PaginationEntity <CommentEntity> commentPaginationEntity = commentRepository.GetCommentPaginationOfPostWithPreservedFetch(postId, createdDate, pageSize);
            PaginationDTO <CommentDTO>       commentPaginationDTO    = dataMapper.MapCommentPaginationEntityToDTO(commentPaginationEntity);

            return(commentPaginationDTO);
        }
Ejemplo n.º 7
0
        public async Task <Tuple <PaginationDTO, List <ChatMessage> > > GetAllChatsPagination(int id, int skip, int take)
        {
            var cleanTake = 200;
            var cleanSkip = 0;

            var ChatMessage = await _context.Chats.Where(c => c.FolderId == id).OrderByDescending(c => c.MessageTime).ToListAsync();

            var result = ChatMessage.Skip(cleanSkip).Take(cleanTake).ToList();

            var allowNext = false; //allow older messages
            var allowBack = false; //allow newer messages

            if (cleanSkip > 0)
            {
                allowBack = true;
            }
            if ((cleanSkip + cleanTake) < ChatMessage.Count())
            {
                allowNext = true;
            }

            var pagesCounter = ChatMessage.Count() / cleanTake; //totalmessages divided by current take
            var currentPage  = (cleanSkip + cleanTake) / cleanTake;

            var paginationDto = new PaginationDTO(cleanSkip, cleanTake, allowNext, allowBack, pagesCounter, currentPage);

            return(new Tuple <PaginationDTO, List <ChatMessage> >(paginationDto, result));
        }
Ejemplo n.º 8
0
        public async Task <List <NewsFullDTO> > GetNews(PaginationDTO pagination)
        {
            try
            {
                var res = await _context.News
                          .Take(pagination.Take)
                          .Skip(pagination.Skip)
                          .OrderByDescending(c => c.Date)
                          .ToListAsync();

                foreach (var i in res)
                {
                    i.ViewCount++;
                }

                _context.News.UpdateRange(res);
                await _context.SaveChangesAsync();

                return(_mapper.Map <List <NewsFullDTO> >(res));
            }
            catch (Exception ex)
            {
                throw new Exception("Не удалось достать новости");
            }
        }
Ejemplo n.º 9
0
        public List <CompanyInfoDTO> GetCompanyInfos(PaginationDTO cmd, ref int pagesCount)
        {
            var query = from c in db.CompanyInfos
                        where c.IsDeleted == false
                        select new CompanyInfoDTO()
            {
                Accountant     = c.Accountant,
                Address        = c.Address,
                BankDetails    = c.BankDetails,
                City           = c.City,
                Director       = c.Director,
                INN            = c.INN,
                LegalName      = c.LegalName,
                Id             = c.Id,
                MFO            = c.MFO,
                PaymentAccount = c.PaymentAccount,
                Phone          = c.Phone,
                OKONX          = c.OKONX,
            };


            pagesCount = (int)Math.Ceiling((double)(from p in query select p).Count() / cmd.PageSize);
            query      = query.Page(cmd.PageSize, cmd.Page);
            return(query.ToList());
        }
Ejemplo n.º 10
0
        public PaginationDTO <PostCardDTO> GetPostCardPagination(int pageNumber, int pageSize, string category = null, string searchQuery = null)
        {
            PaginationEntity <PostEntity> postPaginationEntity  = postRepository.GetPostPagination(pageNumber, pageSize, category, searchQuery);
            PaginationDTO <PostCardDTO>   postCardPaginationDTO = dataMapper.MapPostCardPaginationEntityToDTO(postPaginationEntity);

            return(postCardPaginationDTO);
        }
Ejemplo n.º 11
0
        public ActionResult Index(int?page)
        {
            var pagination = new PaginationDTO();

            pagination.ActualPageNumber = (page ?? 1);

            var model = new RelDepartamentos();

            model.TopMaisAvaliados  = new List <DepartamentosModel>();
            model.TopMenosAvaliados = new List <DepartamentosModel>();

            model = relRepo.RelDepartamentos(1, 1);

            model.TopMaisAvaliados.ForEach(x =>
            {
                x.Departamento = string.IsNullOrEmpty(x.Departamento) ? "não informado na integração" : x.Departamento;
            });

            model.TopMenosAvaliados.ForEach(x =>
            {
                x.Departamento = string.IsNullOrEmpty(x.Departamento) ? "não informado na integração" : x.Departamento;
            });

            return(View(model));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <List <Person> > > Get([FromQuery] PaginationDTO paginationDTO)
        {
            var queryable = context.People.AsQueryable();
            await HttpContext.InsertPaginationParameterInResponse(queryable, paginationDTO.RecordsPerPage);

            return(await queryable.Paginate(paginationDTO).ToListAsync());
        }
Ejemplo n.º 13
0
        public static async Task <PaginatedResponse <T> > GetHelper <T>(this IHttpService httpService, string url,
                                                                        PaginationDTO paginationDTO)
        {
            string newURL = "";

            if (url.Contains("?"))
            {
                newURL = $"{url}&page={paginationDTO.Page}&recordsPerPage={paginationDTO.RecordsPerPage}";
            }
            else
            {
                newURL = $"{url}?page={paginationDTO.Page}&recordsPerPage={paginationDTO.RecordsPerPage}";
            }

            var httpResponse = await httpService.Get <T>(newURL);

            var totalAmountPages  = int.Parse(httpResponse.HttpResponseMessage.Headers.GetValues("totalAmountPages").FirstOrDefault());
            var paginatedResponse = new PaginatedResponse <T>
            {
                Response         = httpResponse.Response,
                TotalAmountPages = totalAmountPages
            };

            return(paginatedResponse);
        }
Ejemplo n.º 14
0
 public static IQueryable <T> Paginate <T>(this IQueryable <T> queryable,
                                           PaginationDTO pagination)
 {
     return(queryable
            .Skip((pagination.Page - 1) * pagination.QuantityPerPage)
            .Take(pagination.QuantityPerPage));
 }
Ejemplo n.º 15
0
 public void FromDto <V>(PaginationDTO <V, U> paginationDto)
 {
     SearchQuery = paginationDto.SearchQuery;
     TotalCount  = paginationDto.TotalCount;
     ObjectList  = paginationDto.ObjectList == null ? null
         : paginationDto.ObjectList.Select(e => (T)Convert.ChangeType(e, typeof(T)));
 }
        public async Task <ActionResult <List <ContentCreatorDTO> > > Get([FromQuery] PaginationDTO paginationDTO,
                                                                          [FromQuery] ContentCreatorFilters contentCreatorFilters)
        {
            var queryable = GetContentCreatorQueryable();

            if (!string.IsNullOrEmpty(contentCreatorFilters.UserNameContains))
            {
                queryable = queryable.Where(u => u.RealName.Contains(contentCreatorFilters.UserNameContains) || u.UserName.Contains(contentCreatorFilters.UserNameContains));
            }

            if (contentCreatorFilters.TechnologyId != null && contentCreatorFilters.TechnologyId.Count > 0)
            {
                queryable = queryable.Where(u => u.ApplicationUserTechnology.Any(t => contentCreatorFilters.TechnologyId.Contains(t.TechnologyId)));
            }


            await HttpContext.InserPaginationHeader(queryable);

            queryable = queryable.Paginate(paginationDTO);

            var entities = await queryable.ToListAsync();


            var dto = mapper.Map <List <ContentCreatorDTO> >(entities);

            //Mapear tecnologias
            var technologyIdUserGroup = entities.Select(x => new
            {
                x.Id,
                TechnologyIds = x.ApplicationUserTechnology.Select(y => y.TechnologyId)
            }).ToList();

            var totalIds = technologyIdUserGroup.Aggregate(new List <int>(), (before, next) =>
            {
                before.AddRange(next.TechnologyIds);
                return(before);
            }).Distinct();

            var technologies = await applicationDbContext.Technologies.Where(t => totalIds.Contains(t.Id)).ToListAsync();

            technologyIdUserGroup.ForEach(g =>
            {
                var creator = dto.FirstOrDefault(c => g.Id == c.UserId);

                var creatorTechnologies = g.TechnologyIds.Select(x => technologies.FirstOrDefault(t => t.Id == x));

                creator.ApplicationUserTechnology = mapper.Map <List <UserTechnologyDTO> >(creatorTechnologies);

                var currentUser = entities.FirstOrDefault(u => u.Id == g.Id);

                int principalIndex = currentUser.ApplicationUserTechnology.FindIndex(x => x.IsPrincipal);
                if (principalIndex != -1)
                {
                    creator.ApplicationUserTechnology[principalIndex].IsPrincipal = true;
                }
            });


            return(dto);
        }
Ejemplo n.º 17
0
        public async Task <ActionResult <List <UserInfoDTO> > > Get([FromQuery] PaginationDTO pagination)
        {
            var queryable = context.Users.AsQueryable();

            queryable = queryable.OrderBy(x => x.Email);
            return(await Get <ApplicationUser, UserInfoDTO>(pagination));
        }
        public static async Task <PaginatedResponse <T> > GetHelper <T>(this IHttpService httpService, string url,
                                                                        PaginationDTO paginationDTO, bool includeToken = true)
        {
            string newURL = "";

            if (url.Contains("?")) //if url has "?" it means it already has queryStrings
            {
                newURL = $"{url}&page={paginationDTO.Page}&recordsPerPage={paginationDTO.RecordsPerPage}";
            }
            else
            {
                newURL = $"{url}?page={paginationDTO.Page}&recordsPerPage={paginationDTO.RecordsPerPage}";
            }

            var httpResponse = await httpService.Get <T>(newURL, includeToken);

            var totalAmountOfPages = int.Parse(httpResponse.HttpResponseMessage.Headers.GetValues("totalAmountOfPages").FirstOrDefault());
            var paginatedResponse  = new PaginatedResponse <T>
            {
                Response           = httpResponse.Response,
                TotalAmountOfPages = totalAmountOfPages
            };

            return(paginatedResponse);
        }
Ejemplo n.º 19
0
        public ActionResult Index(int?page)
        {
            var pagination = new PaginationDTO();

            pagination.ActualPageNumber = (page ?? 1);

            var model = new RelatoriosDeProdutosModel();

            model.Produtos         = new List <ProdutoModel>();
            model.TopMaisAvaliado  = new List <ProdutoModel>();
            model.TopMenosAvaliado = new List <ProdutoModel>();
            model = produtoRepo.RelTopProdutos(1, pagination.ActualPageNumber);



            if (model != null && model.Produtos.Any())
            {
                pagination.RowsPerPage = model.Produtos.FirstOrDefault().RowsPerPage;
                pagination.TotalRows   = model.Produtos.FirstOrDefault().TotalRows;

                ViewBag.Produtos = new StaticPagedList <ProdutoModel>(model.Produtos.ToList(), pagination.ActualPageNumber, pagination.RowsPerPage, pagination.TotalRows);
            }
            else
            {
                model.Produtos   = new List <ProdutoModel>();
                ViewBag.Produtos = new StaticPagedList <ProdutoModel>(model.Produtos.ToList(), 1, 1, pagination.TotalRows);
            }

            return(View(model));
        }
Ejemplo n.º 20
0
        protected async Task <ActionResult <List <TDTO> > > Get <TEntity, TDTO>(PaginationDTO paginationDTO, IQueryable <TEntity> queryable) where TEntity : class
        {
            await HttpContext.InsertParametersPagination(queryable, paginationDTO.RecordsPage);

            var entities = await queryable.Paginate(paginationDTO).ToListAsync();

            return(_mapper.Map <List <TDTO> >(entities));
        }
Ejemplo n.º 21
0
        protected async Task <List <TDTO> > Get <TEntity, TDTO>(PaginationDTO paginationDTO, IQueryable <TEntity> queryable) where TEntity : class
        {
            await HttpContext.InsertPaginationParams(queryable, paginationDTO.RowsPerPage);

            var entities = await queryable.Paginate(paginationDTO).ToListAsync();

            return(mapper.Map <List <TDTO> >(entities));
        }
Ejemplo n.º 22
0
        public List <ExpenseDTO> GetExpenses(PaginationDTO cmd, int userId, ref int pagesCount)
        {
            var userData    = new UserBL().GetAccountUser(userId);
            var workplaceId = userData.WorkPlace.Id;
            var isSuperUser = userData.PositionRole == 1 || userData.isSunnat;

            return(new ExpenseDalFacade().GetExpenses(cmd, workplaceId.Value, isSuperUser, ref pagesCount));
        }
Ejemplo n.º 23
0
        public async Task <ActionResult <List <BlogDTO> > > GetByUserId(int id, [FromQuery] PaginationDTO paginationDTO)
        {
            var blogDTOs = await _blogService.GetAllByUserIdAsync(id);

            await HttpContext.InsertPaginationParametersInResponseAsync(blogDTOs, paginationDTO.RecordsPerPage);

            return(blogDTOs.Paginate(paginationDTO).ToList());
        }
Ejemplo n.º 24
0
        public static IQueryable <T> Paginate <T>(this IQueryable <T> queryable, PaginationDTO pagination, int totalAmountPages)
        {
            var currentPage = pagination.Page > totalAmountPages ? totalAmountPages : pagination.Page;

            return(queryable
                   .Skip((currentPage - 1) * pagination.RecordsPerPage)
                   .Take(pagination.RecordsPerPage));
        }
Ejemplo n.º 25
0
        public async Task <ActionResult <List <Person> > > Get([FromQuery] PaginationDTO paginationDTO)
        {
            var paginatedResponse = await personRepository.GetPeople(paginationDTO);

            HttpContext.InsertPaginationParametersInResponse(paginatedResponse.TotalAmountPages);

            return(paginatedResponse.Response);
        }
Ejemplo n.º 26
0
        public async Task <ActionResult <List <UserDTO> > > GetListUsers([FromQuery] PaginationDTO paginationDTO)
        {
            var queryable = context.Users.AsQueryable();
            await HttpContext.InsertParametersPaginationInHeader(queryable);

            var users = await queryable.OrderBy(x => x.Email).Paginate(paginationDTO).ToListAsync();

            return(mapper.Map <List <UserDTO> >(users));
        }
Ejemplo n.º 27
0
        public async Task <ActionResult <List <CustomerDTO> > > Get([FromQuery] PaginationDTO pagination)
        {
            var queryable = context.Customers.AsQueryable();
            await HttpContext.InsertPaginationParametersInResponse(queryable, pagination.RecordsPerPage);

            var customer = await queryable.Paginate(pagination).ToListAsync();

            return(mapper.Map <List <CustomerDTO> >(customer));
        }
Ejemplo n.º 28
0
        protected async Task <List <TDTO> > Get <TEntity, TDTO>(PaginationDTO pagination) where TEntity : class
        {
            var queryable = context.Set <TEntity>().AsNoTracking().AsQueryable();
            await HttpContext.InsertPaginationParametersInResponse(queryable, pagination.RecordsPerPage);

            var entities = await queryable.Paginate(pagination).ToListAsync();

            return(mapper.Map <List <TDTO> >(entities));
        }
Ejemplo n.º 29
0
        public void Paginate_WhenCalled_ReturnsPaginatedIenumerable()
        {
            var enumerable    = Enumerable.Range(0, 10);
            var paginationDTO = new PaginationDTO(2, 5);

            var result = enumerable.Paginate(paginationDTO);

            Assert.That(result, Is.EquivalentTo(new[] { 5, 6, 7, 8, 9 }));
        }
Ejemplo n.º 30
0
        public async Task <ActionResult <List <PersonDTO> > > Get([FromQuery] PaginationDTO pagination)
        {
            var querable = _context.People.AsQueryable();
            await HttpContext.InsertPaginationParametersInResponse(querable, pagination.RecordsPerPage);

            var people = await querable.Paginate(pagination).ToListAsync();

            return(_mapper.Map <List <PersonDTO> >(people));
        }