Ejemplo n.º 1
0
 public IActionResult GetAllHouses()
 {
     try
     {
         return(Ok(_houseService.GetAllHouses()));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 2
0
        public IActionResult GetAllHouses()
        {
            var requestResult = _houseService.GetAllHouses();

            if (!requestResult.Status)
            {
                if (requestResult.ServerError)
                {
                    return(StatusCode(500));
                }

                return(BadRequest(new FailedHouseResponse
                {
                    Status = requestResult.Status,
                    Errors = requestResult.Errors
                }));
            }

            return(Ok(new SuccessAllHousesResponse
            {
                Status = requestResult.Status,
                Houses = requestResult.Houses
            }));
        }
Ejemplo n.º 3
0
 public ActionResult <List <House> > GetAllHouses()
 {
     return(Ok(_houseService.GetAllHouses()));
 }
Ejemplo n.º 4
0
 public IEnumerable <House> GetAllHouses()
 {
     return(_houseService.GetAllHouses());
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetAllHouses(string world, TownType townType, HouseType houseType, [FromQuery] int status = -1, [FromQuery] string orderBy = "", [FromQuery] int sortDirection = 0)
        {
            var response = new Response <AllHousesDTO>
            {
                Succeed = false
            };

            if (string.IsNullOrEmpty(world))
            {
                response.Message = "The world name must be provided";
                return(BadRequest(response));
            }

            try
            {
                var r = await _houseService.GetAllHouses(
                    world,
                    townType.GetTown(),
                    houseType.GetHouse());

                response.Result = _mapper.Map <AllHousesDTO>(r.Response);
                IEnumerable <SimpleHouseDTO> filteredHouses = response.Result.Houses;

                if (status == (int)HouseStatusType.AUCTIONED_BID)
                {
                    filteredHouses = filteredHouses
                                     .Where(h => h.Status == HouseStatusType.AUCTIONED_BID);
                }
                else if (status == (int)HouseStatusType.AUCTIONED_NO_BID)
                {
                    filteredHouses = filteredHouses
                                     .Where(h => h.Status == HouseStatusType.AUCTIONED_NO_BID);
                }
                else if (status == (int)HouseStatusType.RENTED)
                {
                    filteredHouses = filteredHouses
                                     .Where(h => h.Status == HouseStatusType.RENTED);
                }

                switch (orderBy.ToLower())
                {
                case "size":
                    if (sortDirection == 0)
                    {
                        filteredHouses = filteredHouses.OrderBy(h => h.Size);
                    }
                    else
                    {
                        filteredHouses = filteredHouses.OrderByDescending(h => h.Size);
                    }
                    break;

                case "rent":
                    if (sortDirection == 0)
                    {
                        filteredHouses = filteredHouses.OrderBy(h => h.Rent);
                    }
                    else
                    {
                        filteredHouses = filteredHouses.OrderByDescending(h => h.Rent);
                    }
                    break;

                case "bid":
                    if (sortDirection == 0)
                    {
                        filteredHouses = filteredHouses
                                         .OrderBy(h => h.Bid.HasValue)
                                         .ThenBy(h => h.Bid);
                    }
                    else
                    {
                        filteredHouses = filteredHouses
                                         .OrderByDescending(h => h.Bid.HasValue)
                                         .ThenBy(h => h.Bid);
                    }
                    break;

                case "auction_end":
                    if (sortDirection == 0)
                    {
                        filteredHouses = filteredHouses
                                         .OrderBy(h => h.MinutesUntilAuctionEnds.HasValue)
                                         .ThenBy(h => h.MinutesUntilAuctionEnds);
                    }
                    else
                    {
                        filteredHouses = filteredHouses
                                         .OrderByDescending(h => h.MinutesUntilAuctionEnds.HasValue)
                                         .ThenBy(h => h.MinutesUntilAuctionEnds);
                    }
                    break;

                default:
                    if (sortDirection == 0)
                    {
                        filteredHouses = filteredHouses.OrderBy(h => h.Name);
                    }
                    else
                    {
                        filteredHouses = filteredHouses.OrderByDescending(h => h.Name);
                    }
                    break;
                }
                response.Result.Houses = filteredHouses.ToList();
                response.Succeed       = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(StatusCode(StatusCodes.Status500InternalServerError, response));
            }
            return(Ok(response));
        }