Ejemplo n.º 1
0
        public async Task <IActionResult> Get([FromQuery] PageFilter pageFilter, [FromQuery] OfferViewModelFilter filter)
        {
            Expression <Func <Offer, bool> > offerFilter = OfferFilter.ConvertTo(filter);

            offerFilter = offerFilter.AndAlso(x => x.Active == true);

            PagedFilter <Offer> pagedFilter =
                new PagedFilter <Offer>(pageFilter.Page, pageFilter.Limit, offerFilter);

            Expression <Func <Offer, object> >[] includes = new Expression <Func <Offer, object> >[] {
                x => x.Employer,
                x => x.OfferType
            };


            PagedResult <Offer> offers = await _offerService.Get(pagedFilter, include : includes);

            IEnumerable <OfferViewModel> offerViewModel = OfferViewModel.From(offers.Data);

            PagedResult <OfferViewModel> queryResult = new PagedResult <OfferViewModel>(offerViewModel,
                                                                                        offers.Page,
                                                                                        offers.Limit,
                                                                                        offers.ElementsCount);

            return(Ok(queryResult));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Print agents having most offers into console
        /// </summary>
        /// <param name="args">Arguments to call the service</param>
        /// <param name="numberOfItemsToShow">Number of items to display into the console</param>
        internal static void PrintData(string[] args, int numberOfItemsToShow)
        {
            ILogger     logger      = serviceProvider.GetService <ILogger <Program> >();
            OfferFilter offerFilter = serviceProvider.GetService <OfferFilter>();

            "Funda offer finder started..."
            .SendTo(Console.WriteLine);
            $"Searching offers by {string.Join(',', args)}"
            .SendTo(Console.WriteLine)
            .SendTo(objects: null, method: logger.LogInformation);
            $"Fetching Top {numberOfItemsToShow} selling agents, Please wait..."
            .SendTo(Console.WriteLine);

            string[]  headers   = new string[] { "Estate Agent Name", "Offer Count" };
            ConsoleUI consoleUI = new ConsoleUI(TableStart, ConsoleUI.Align.Left, headers);

            offerFilter.UpdateProgress(PrintProgress);

            try
            {
                var topAgents = offerFilter.GetEstateAgentsByHighestSaleOrder(args)
                                .GetAwaiter()
                                .GetResult()
                                .Take(numberOfItemsToShow);

                ArrayList tableData = new ArrayList(topAgents.Select(x => new string[] { x.Name, x.OfferCount.ToString() }).ToList());
                consoleUI.RePrint(tableData);
            }
            catch (NotCompletedException ncEx)
            {
                Console.WriteLine("\r\nAn error occured, please try again later");
                Console.WriteLine($"Reason: {ncEx.Message}");
            }
        }
Ejemplo n.º 3
0
        public async Task <Pagination <OfferListPreviewDto> > GetMyOffers([FromQuery] OfferFilter offerFilter)
        {
            var query = new GetMyOffersQuery {
                OfferFilter = offerFilter
            };

            return(await _mediator.Send(query));
        }
Ejemplo n.º 4
0
        public GetOfferPackageSubmissionResultRequest()
        {
            _hasParameters = true;

            _Autentication = new Autentication();

            _OfferFilter = new OfferFilter();

            _Parameters = new Dictionary <string, string>();
            _Parameters.Add("PackageID", "");
        }
Ejemplo n.º 5
0
        public async Task <Pagination <OfferListPreviewDto> > GetSellerOffers(
            [FromRoute] string sellerId, [FromQuery] OfferFilter offerFilter)
        {
            var query = new GetSellerOffersQuery
            {
                SellerId    = sellerId,
                OfferFilter = offerFilter
            };

            return(await _mediator.Send(query));
        }
Ejemplo n.º 6
0
        public async Task <Pagination <Offer> > GetAllByUserIdAsync(Guid userId, OfferFilter filter)
        {
            var offers = _appDbContext.Offers.AsQueryable()
                         .Where(x => x.OwnerId == userId && x.RemovedAt == null)
                         .OrderByDescending(x => x.PublishedAt == null)
                         .ThenByDescending(x => x.CreatedAt)
                         .ApplyFilter(filter);

            var pageDetails = new PageCriteria(filter.PageIndex, filter.PageSize);

            return(await offers.PaginateAsync(pageDetails));
        }
Ejemplo n.º 7
0
        public async Task <Pagination <Offer> > GetAllActiveAsync(OfferFilter filter)
        {
            var offers = _appDbContext.Offers
                         .AsQueryable()
                         .Where(OfferActiveExpression)
                         .ApplyFilter(filter)
                         .OrderBy(x => x.EndsAt)
                         .Include(x => x.Category);

            var pageDetails = new PageCriteria(filter.PageIndex, filter.PageSize);

            return(await offers.PaginateAsync(pageDetails));
        }
Ejemplo n.º 8
0
        public void Initialize()
        {
            mockedApiClient = new Mock <ApiClient>();
            mockedOption    = new Mock <IOptions <FundaApiSettings> >();
            mockedLogger    = new Mock <ILogger <OfferFilter> >();

            FundaApiSettings fundaApiSettings = new FundaApiSettings
            {
                BaseUri          = "http://partnerapi.funda.nl",
                Key              = "123456989abcdef",
                OfferUriTemplate = "feeds/Aanbod.svc/json/{key}?type=koop&zo={searchQuery}&page={pageIndex}&pagesize={pageSize}"
            };

            mockedOption.SetupGet(x => x.Value).Returns(fundaApiSettings);

            offerFilter = new OfferFilter(mockedOption.Object, mockedApiClient.Object, mockedLogger.Object);
        }
Ejemplo n.º 9
0
        public ActionResult <IEnumerable <UserOffer> > GetOffersByFilter([FromBody] OfferFilter filter)
        {
            List <UserOffer> result = context.UserOffers.ToList();

            if (!string.IsNullOrWhiteSpace(filter.UserId))
            {
                result = result.Where(x => x.UserId == filter.UserId).ToList();
            }
            if (!string.IsNullOrWhiteSpace(filter.Subject))
            {
                result = result.Where(x => x.Subject == filter.Subject).ToList();
            }
            if (filter.TeacherId != 0)
            {
                result = result.Where(x => x.TeacherId == filter.TeacherId).ToList();
            }
            return(result);
        }
Ejemplo n.º 10
0
        public static IQueryable <Offer> ApplyFilter(this IQueryable <Offer> queryable, OfferFilter filter)
        {
            if (queryable == null)
            {
                return(null);
            }

            if (filter.FromPrice != null)
            {
                queryable = queryable.Where(x => x.Price >= filter.FromPrice);
            }
            if (filter.ToPrice != null)
            {
                queryable = queryable.Where(x => x.Price <= filter.ToPrice);
            }
            if (filter.CategoryId != null)
            {
                queryable = queryable.Where(x => x.Category.Id == filter.CategoryId);
            }

            if (!string.IsNullOrWhiteSpace(filter.SearchPhrase))
            {
                queryable = queryable.Where(x => EF.Functions.Like(x.Name, $"%{filter.SearchPhrase}%"));
            }

            return(queryable);
        }
Ejemplo n.º 11
0
 public OfferFilterTests(FundaApiSettingsFixture settingsFixture)
 {
     offerFilter = new OfferFilter(settingsFixture, new JsonApiClient(settingsFixture), new NullLogger <OfferFilter>());
 }
 public GetOfferListRequest()
 {
     _OfferFilter = new OfferFilter();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Get the offers filtered by a given list of attributes in order to be displayed on the offer wall.
        /// </summary>
        /// <param name="filterAttributes"></param>
        /// <returns>return list of active offers suitable for displaying on an offer wall filtered by request attributes.</returns>
        private List<OfferApiObject> RetrieveOffers(Dictionary<string, string> filterAttributes, string ApiUser, OfferFilter offerFilter)
        {
            List<OfferApiObject> offers = null;
            try
            {
                if (offerFilter.Equals(OfferFilter.LiveOffer))
                    offers = OfferRepository().GetActiveOffersHavingValidTerm(false).ToList();
                else if (offerFilter.Equals(OfferFilter.TestOffer))
                    offers = OfferRepository().GetActiveOffersHavingValidTerm(true).ToList();
                else
                    offers = OfferRepository().GetActiveOffersHavingValidTerm().ToList();

                if (offers != null && offers.Count > 0)
                    offers = FilterOffers(offers, filterAttributes);
                else
                    return new List<OfferApiObject>();

                string country = string.Empty;

                if (filterAttributes.TryGetValue("COREcontact_country", out country) == false)
                {
                    country = DefaultCountryCode();
                }

                offers = UpdateOffersLink(offers, ApiUser, country);
            }
            catch
            {
                throw;
            }

            return offers;
        }