public async Task <ActionResult <BidsDTO> > GetBids([FromQuery] BidsQueryOptions bidsQueryOptions) { string ownerId = this.GetUserId(); /*if (bid.OwnerId != ownerId) * { * return this.StatusCode(StatusCodes.Status401Unauthorized, "token id dosent match input id"); * }*/ Response <BidsDTO> response = await this.bidsManager.GetBids(bidsQueryOptions).ConfigureAwait(false); if (response.IsOperationSucceeded) { return(this.StatusCode(StatusCodes.Status201Created, response.DTOObject)); } return(this.StatusCode(StatusCodes.Status403Forbidden, response.SuccessOrFailureMessage)); /* * return new List<BidDTO> { * new BidDTO { * Id = " first bid in list", * Category = bidsFilters.Category, * }, * }; */ }
private IEnumerable <BidEntity> GetFilteredBids(BidsQueryOptions bidsFilters) { return(_context.Bids .Include(bid => bid.Product) .AsEnumerable() .Where(bid => FilterByCategories(bid, bidsFilters.Category, bidsFilters.SubCategory)) .Where(bid => FilterByPrices(bid, bidsFilters.MaxPrice, bidsFilters.MinPrice)) .Where(bid => FilterByQueryString(bid, bidsFilters.Search))); }
public async Task <ActionResult <BidsDTO> > GetBids([FromQuery] BidsQueryOptions bidsQueryOptions) { Response <BidsDTO> response = await this.bidsManager.GetBids(bidsQueryOptions).ConfigureAwait(false); if (response.IsOperationSucceeded) { return(this.StatusCode(StatusCodes.Status201Created, response.DTOObject)); } return(this.StatusCode(StatusCodes.Status500InternalServerError, response.SuccessOrFailureMessage)); }
public async Task <Response <BidsDTO> > GetBids(BidsQueryOptions bidsFilters) { // firts category and sub category // then string bidsSearchString = bidsFilters.Search; if (bidsFilters.Category == null && bidsSearchString == null) { return(await this.GetDefaultHomePageBids(bidsFilters.Page)); } else if (!ValidateBidsFilters(bidsFilters, out string validationErrorString)) { return(new Response <BidsDTO>() { DTOObject = null, IsOperationSucceeded = false, SuccessOrFailureMessage = validationErrorString }); } else // TODO : extract to sub methods { IEnumerable <BidEntity> filteredBids = this.GetFilteredBids(bidsFilters); IEnumerable <BidEntity> sortedBids = this.GetSortBids(filteredBids, bidsFilters.SortOrder, bidsFilters.SortBy); // return page int pageSize = bidsFilters.Limit == 0 || bidsFilters.Limit > _maxPageSize ? _pageDefaultSize : bidsFilters.Limit; var bidsPage = sortedBids .Skip(bidsFilters.Page * pageSize) .Take(pageSize) .Select(bidEntity => _mapper.Map <BidDTO>(bidEntity)) .ToList(); BidsDTO bidsDTO = new BidsDTO( pageNumber: bidsFilters.Page, numberOfPages: (int)Math.Ceiling((double)filteredBids.Count() / pageSize), bidsPage: bidsPage); return(new Response <BidsDTO>() { DTOObject = bidsDTO, IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage() }); } }
public async Task <ActionResult <BidsDTO> > GetBids([FromQuery] BidsQueryOptions bidsQueryOptions) { Response <BidsDTO> response = await this.bidsManager.GetBids(bidsQueryOptions).ConfigureAwait(false); if (response.IsOperationSucceeded) { return(this.StatusCode(StatusCodes.Status201Created, response.DTOObject)); } return(this.StatusCode(StatusCodes.Status403Forbidden, response.SuccessOrFailureMessage)); /* * return new List<BidDTO> { * new BidDTO { * Id = " first bid in list", * Category = bidsFilters.Category, * }, * }; */ }
private bool ValidateBidsFilters(BidsQueryOptions bidsFilters, out string validationErorrString) { validationErorrString = null; string demandedCategory = bidsFilters.Category; string demandedSubCategory = bidsFilters.SubCategory; if (demandedSubCategory != null && demandedCategory == null) { validationErorrString = $"Sub catergory has set to :{bidsFilters.SubCategory } while category is null"; return(false); } /* * // should implement it smarter with creating categories table and with kind of index on it * if (!_context.Bids.Select(bid =>bid.Category).ToHashSet().Contains(demandedCategory)) * { * validationErorrString = $"Catergory has set to :{demandedCategory } while category is not exist in DB"; * return false; * } */ // should implemnt also table of Category-SubCategory with many to one relationship to vaildate.... return(true); }
Task <Response <BidsDTO> > IBidsManager.GetBids(BidsQueryOptions bidsFilters) { throw new NotImplementedException(); }
public Task <Response <List <BidDTO> > > GetBids(BidsQueryOptions bidsFilters) { throw new NotImplementedException(); }