Example #1
0
        public ClientResponseDto GetClientCampaignList()
        {
            var login = _jwtTokenService.GetClaimByName("Login");

            var client = _advertDbContext.Clients.Where(c => login.Equals(c.Login))
                         .Include(c => c.Campaigns)
                         .ThenInclude(c => c.Banners)
                         .FirstOrDefault();

            if (client == null)
            {
                throw new ResourceNotFoundException("No such client");
            }

            var clientResponseDto = new ClientResponseDto
            {
                FirstName = client.FirstName,
                LastName  = client.LastName,
                Email     = client.Email,
                Phone     = client.Phone,
                Campaigns = client.Campaigns.Select(c =>
                                                    new CampaignResponseDto
                {
                    StartDate           = c.StartDate,
                    EndDate             = c.EndDate,
                    PricePerSquareMeter = c.PricePerSquareMeter,
                    Banners             = c.Banners.Select(b =>
                                                           new BannerResponseDto
                    {
                        Name  = b.Name,
                        Area  = b.Area,
                        Price = b.Price
                    }).ToList()
                }).ToList()
            };

            clientResponseDto.Campaigns = clientResponseDto.Campaigns
                                          .OrderByDescending(c => c.StartDate).ToList();

            return(clientResponseDto);
        }