Ejemplo n.º 1
0
        private void Filter()
        {
            var node = SelectedNode ?? Root;

            if (node != null)
            {
                INodeFilter filter   = new PictureFilter();
                var         filtered = filter.Filter(node.Children);
                Root = new Node("FILTERED", filtered);
            }
        }
Ejemplo n.º 2
0
        public IActionResult Picture([FromRoute] int touristSpotId, [FromQuery] PictureFilter filter)
        {
            try
            {
                if (filter == null)
                {
                    filter = new PictureFilter();
                }

                filter.TouristSpotId = touristSpotId;
                var results = this.pictureAppService.GetBy(filter);
                return(this.Response(results));
            }
            catch (SnowmanLabsChallengeException slcex)
            {
                return(this.Response(slcex));
            }
            catch (Exception ex)
            {
                return(this.Response(ex));
            }
        }
        public async Task<PagingResult<PictureDto>> GetPictures(PictureFilter filter)
        {
            using (var context = new PicturesDbContext())
            {
                var selectQuery = from picture in context.Pictures
                    join style in context.Styles on picture.StyleId equals style.Id
                    join painter in context.Painters on picture.PainterId equals painter.Id
                    join campaignPicture in context.CampaignPicture on picture.Id equals campaignPicture.PictureId into
                    campaignPictureDiF
                    from campaignPicture in campaignPictureDiF.DefaultIfEmpty()
                    join campaign in context.Campaigns on campaignPicture.CampaignId equals campaign.Id into campaignDiF
                    from campaign in campaignDiF.DefaultIfEmpty()
                    select new {picture, painter, style, campaign};

                if (filter.PainterId.HasValue && filter.PainterId.Value > 0)
                {
                    selectQuery = selectQuery.Where(i => i.painter.Id == filter.PainterId.Value);
                }

                if (filter.CampaignId.HasValue && filter.CampaignId.Value > 0)
                {
                    selectQuery = selectQuery.Where(i => i.campaign.Id == filter.CampaignId.Value);
                }


                var query = from row in selectQuery
                            group row.campaign by new {row.picture, row.painter, row.style} into campaignGr
                        select campaignGr;

                var itemsCount = query.Count();

                query = query.OrderBy(i => i.Key.picture.Id);

                if (filter.PageSize.HasValue && filter.PageNumber.HasValue)
                {
                    query = query.Skip(filter.PageSize.Value*filter.PageNumber.Value).Take(filter.PageSize.Value);
                }

                var result = query.ToArray().Select(item => new PictureDto
                        {
                            Id = item.Key.picture.Id,
                            Name = item.Key.picture.Name,
                            Painter =
                                new PainterDto
                                {
                                    Id = item.Key.painter.Id,
                                    Name = item.Key.painter.Name,
                                    BirthYear = item.Key.painter.BirthYear,
                                    DeathYear = item.Key.painter.DeadYear
                                },
                            Year = item.Key.picture.Year,
                            Style = new StyleDto {Id = item.Key.style.Id, Name = item.Key.style.Name},
                            Guid = item.Key.picture.Guid,
                            ImageUrl = item.Key.picture.ImageUrl,
                            Campaigns = item.Where(i => i != null).Select(i => new CampaignDto() {Id = i.Id, Name = i.Name}).ToArray()
                        }).ToArray();

                return new PagingResult<PictureDto>()
                {
                    Items = result,
                    TotalCount = itemsCount
                };
            }
        }
        public async Task<PagingResult<PictureDto>> GetPictures(PictureFilter filter)
        {
            var pictures = await _pictureDataAccess.GetPictures(filter);

            return pictures;
        }