public MainResponse GetAllSponsors(BaseRecordFilterRequest request)
        {
            IEnumerable <SponsorResponse> sponsorResponses;
            SponsorListResponse           sponsorListResponse = new SponsorListResponse();

            sponsorResponses = (from sponsor in _context.Sponsors
                                join address in _context.Addresses
                                on sponsor.AddressId equals address.AddressId
                                into data1
                                from data in data1.DefaultIfEmpty()
                                where sponsor.IsActive == true &&
                                sponsor.IsDeleted == false &&
                                data.IsActive == true &&
                                data.IsDeleted == false
                                select new SponsorResponse
            {
                SponsorId = sponsor.SponsorId,
                SponsorName = sponsor.SponsorName,
                ContactName = sponsor.ContactName,
                Phone = sponsor.Phone,
                Email = sponsor.Email,
                AmountReceived = sponsor.AmountReceived,
                Address = data != null ? data.Address : "",
                ZipCodeId = data != null ? data.ZipCodeId :0,
                CityId = data != null ? data.CityId : 0,
                StateId = data != null ? _context.Cities.Where(x => x.CityId == data.CityId).Select(y => y.StateId).FirstOrDefault() : 0,
            }).ToList();

            if (sponsorResponses.Count() > 0)
            {
                if (request.SearchTerm != null && request.SearchTerm != "")
                {
                    sponsorResponses = sponsorResponses.Where(x => Convert.ToString(x.SponsorId).ToLower().Contains(request.SearchTerm) ||
                                                              x.SponsorName.ToLower().Contains(request.SearchTerm.ToLower()));
                }
                var propertyInfo = typeof(SponsorResponse).GetProperty(request.OrderBy);
                if (request.OrderByDescending == true)
                {
                    sponsorResponses = sponsorResponses.OrderByDescending(s => s.GetType().GetProperty(request.OrderBy).GetValue(s)).ToList();
                }
                else
                {
                    sponsorResponses = sponsorResponses.AsEnumerable().OrderBy(s => propertyInfo.GetValue(s, null)).ToList();
                }
                sponsorListResponse.TotalRecords = sponsorResponses.Count();
                if (request.AllRecords == true)
                {
                    sponsorResponses = sponsorResponses.ToList();
                }
                else
                {
                    sponsorResponses = sponsorResponses.Skip((request.Page - 1) * request.Limit).Take(request.Limit).ToList();
                }
            }
            sponsorListResponse.sponsorResponses = sponsorResponses.ToList();
            _mainResponse.SponsorListResponse    = sponsorListResponse;
            return(_mainResponse);
        }
Exemplo n.º 2
0
        public SponsorListResponse SearchSponsor(SearchRequest searchRequest)
        {
            IEnumerable <SponsorResponse> sponsorResponses;
            SponsorListResponse           sponsorListResponse = new SponsorListResponse();

            sponsorResponses = (from sponsor in _context.Sponsors
                                join address in _context.Addresses
                                on sponsor.AddressId equals address.AddressId
                                into data1
                                from data in data1.DefaultIfEmpty()
                                where sponsor.IsActive == true &&
                                sponsor.IsDeleted == false &&
                                data.IsActive == true &&
                                data.IsDeleted == false &&
                                ((searchRequest.SearchTerm != string.Empty ? Convert.ToString(sponsor.SponsorId).Contains(searchRequest.SearchTerm) : (1 == 1)) ||
                                 (searchRequest.SearchTerm != string.Empty ? sponsor.SponsorName.Contains(searchRequest.SearchTerm) : (1 == 1)))
                                select new SponsorResponse
            {
                SponsorId = sponsor.SponsorId,
                SponsorName = sponsor.SponsorName,
                ContactName = sponsor.ContactName,
                Phone = sponsor.Phone,
                Email = sponsor.Email,
                AmountReceived = sponsor.AmountReceived,
                Address = data != null ? data.Address : "",
                ZipCode = data != null ? data.ZipCode : "",
                StateId = data != null ? data.StateId : 0,
            }).ToList();

            if (sponsorResponses.Count() > 0)
            {
                var propertyInfo = typeof(SponsorResponse).GetProperty(searchRequest.OrderBy);
                if (searchRequest.OrderByDescending == true)
                {
                    sponsorResponses = sponsorResponses.OrderByDescending(s => s.GetType().GetProperty(searchRequest.OrderBy).GetValue(s)).ToList();
                }
                else
                {
                    sponsorResponses = sponsorResponses.AsEnumerable().OrderBy(s => propertyInfo.GetValue(s, null)).ToList();
                }
                sponsorListResponse.TotalRecords = sponsorResponses.Count();
                if (searchRequest.AllRecords == true)
                {
                    sponsorResponses = sponsorResponses.ToList();
                }
                else
                {
                    sponsorResponses = sponsorResponses.Skip((searchRequest.Page - 1) * searchRequest.Limit).Take(searchRequest.Limit).ToList();
                }
            }

            sponsorListResponse.sponsorResponses = sponsorResponses.ToList();
            return(sponsorListResponse);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the list of channel memberships.
        /// </summary>
        /// <param name="maxResults">The maximum results to return</param>
        /// <returns>The list of channel memberships</returns>
        public async Task <IEnumerable <Sponsor> > GetChannelMemberships(int maxResults = 1)
        {
            return(await this.YouTubeServiceWrapper(async() =>
            {
                List <Sponsor> results = new List <Sponsor>();
                string pageToken = null;
                do
                {
                    SponsorsResource.ListRequest request = this.connection.GoogleYouTubeService.Sponsors.List("id,snippet");
                    request.MaxResults = Math.Min(maxResults, 50);
                    request.PageToken = pageToken;

                    SponsorListResponse response = await request.ExecuteAsync();
                    results.AddRange(response.Items);
                    maxResults -= response.Items.Count;
                    pageToken = response.NextPageToken;
                } while (maxResults > 0 && !string.IsNullOrEmpty(pageToken));
                return results;
            }));
        }