public IHttpActionResult GetGasStations([FromUri] GasStationsParametersGetAll gasStationsParametersGetAll) { IList <GasStationsDTO> gasStationsDTO = _gasstationsservice.GetGasStations(gasStationsParametersGetAll, out ReturnValues returnValues); if (!returnValues.Error) { return(Ok(new ResponseSuccess { Success = true, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message, Data = new { GasStations = gasStationsDTO } })); } return(Ok(new ResponseError { Success = false, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message })); }
public IList <GasStationsDTO> GetGasStations(GasStationsParametersGetAll gasStationsParametersGetAll, out ReturnValues returnValues) { IList <GasStationsDTO> gasStationsDTO = null; returnValues = new ReturnValues(); try { var query = _unitOfWork.GasStationRepository.QueryableObject() .Where(row => row.Status == true); if (!String.IsNullOrEmpty(gasStationsParametersGetAll.Name)) { query = query.Where(row => row.Name.Contains(gasStationsParametersGetAll.Name)); } if (!String.IsNullOrEmpty(gasStationsParametersGetAll.TypeGas)) { switch (gasStationsParametersGetAll.TypeGas) { case "Gasolina Comum": query = query.Where(row => row.GasolinaComum == true); break; case "Gasolina Aditivada": query = query.Where(row => row.GasolinaAditivada == true); break; case "Disel": query = query.Where(row => row.Disel == true); break; case "Gás": query = query.Where(row => row.Gas == true); break; } } if (!String.IsNullOrEmpty(gasStationsParametersGetAll.DistrictID)) { query = query.Where(row => row.DistrictID == gasStationsParametersGetAll.DistrictID); } gasStationsDTO = query.Select(row => new GasStationsDTO() { ID = row.ID.ToString(), Status = row.Status.ToString(), Name = row.Name, Phone = row.Phone, GasolinaComum = row.GasolinaComum.ToString(), GasolinaAditivada = row.GasolinaAditivada.ToString(), Disel = row.Disel.ToString(), Gas = row.Gas.ToString(), PriceGasolinaComum = row.PriceGasolinaComum.ToString(), PriceGasolinaAditivada = row.PriceGasolinaAditivada.ToString(), PriceDisel = row.PriceDisel.ToString(), PriceGas = row.PriceGas.ToString(), Latitude = row.Latitude, Longitude = row.Longitude, CEP = row.CEP, Address = row.Address, Number = row.Number, DistrictID = row.DistrictID, CityID = row.CityID, StateID = row.StateID, CreatedOn = row.CreatedOn.ToString(), UpdatedOn = row.UpdatedOn.ToString(), distance = "", lastUpdatePrice = "" }).ToList(); double lat = -30.076721; double longui = -51.031796; if (!String.IsNullOrEmpty(gasStationsParametersGetAll.latitude) && !String.IsNullOrEmpty(gasStationsParametersGetAll.longitude)) { lat = Convert.ToDouble(gasStationsParametersGetAll.latitude); longui = Convert.ToDouble(gasStationsParametersGetAll.longitude); } foreach (var gas in gasStationsDTO) { gas.distance = getDistance(Convert.ToDouble(gas.Latitude), Convert.ToDouble(gas.Longitude), lat, longui).ToString(); } ; if (!String.IsNullOrEmpty(gasStationsParametersGetAll.Order)) { switch (gasStationsParametersGetAll.Order) { case "More Relevant": switch (gasStationsParametersGetAll.TypeGas) { case "Gasolina Comum": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGasolinaComum)).OrderBy(o => Convert.ToDouble(o.distance)).Take(30).ToList(); break; case "Gasolina Aditivada": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGasolinaAditivada)).OrderBy(o => Convert.ToDouble(o.distance)).Take(30).ToList(); break; case "Disel": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceDisel)).OrderBy(o => Convert.ToDouble(o.distance)).Take(30).ToList(); break; case "Gás": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGas)).OrderBy(o => Convert.ToDouble(o.distance)).Take(30).ToList(); break; default: gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGasolinaComum)).OrderBy(o => Convert.ToDouble(o.distance)).Take(30).ToList(); break; } break; case "Highest Price": switch (gasStationsParametersGetAll.TypeGas) { case "Gasolina Comum": gasStationsDTO = gasStationsDTO.OrderByDescending(o => Convert.ToDecimal(o.PriceGasolinaComum)).Take(30).ToList(); break; case "Gasolina Aditivada": gasStationsDTO = gasStationsDTO.OrderByDescending(o => Convert.ToDecimal(o.PriceGasolinaAditivada)).Take(30).ToList(); break; case "Disel": gasStationsDTO = gasStationsDTO.OrderByDescending(o => Convert.ToDecimal(o.PriceDisel)).Take(30).ToList(); break; case "Gás": gasStationsDTO = gasStationsDTO.OrderByDescending(o => Convert.ToDecimal(o.PriceGas)).Take(30).ToList(); break; default: gasStationsDTO = gasStationsDTO.OrderByDescending(o => Convert.ToDecimal(o.PriceGasolinaComum)).Take(30).ToList(); break; } break; case "Lower Price": switch (gasStationsParametersGetAll.TypeGas) { case "Gasolina Comum": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGasolinaComum)).Take(30).ToList(); break; case "Gasolina Aditivada": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGasolinaAditivada)).Take(30).ToList(); break; case "Disel": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceDisel)).Take(30).ToList(); break; case "Gás": gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGas)).Take(30).ToList(); break; default: gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGasolinaComum)).Take(30).ToList(); break; } break; } } else { gasStationsDTO = gasStationsDTO.OrderBy(o => Convert.ToDecimal(o.PriceGasolinaComum)).OrderBy(o => Convert.ToDouble(o.distance)).Take(20).ToList(); } foreach (var gas in gasStationsDTO) { gas.lastUpdatePrice = GetlastUpdatePrice(gas.ID); //gas.distance = getDistanceGoogle(lat.ToString() + "," + longui.ToString(), Convert.ToDouble(gas.Latitude).ToString()+ "," +Convert.ToDouble(gas.Longitude).ToString()).ToString(); } ; returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok)); } catch (Exception ex) { returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message); } return(gasStationsDTO as IList <GasStationsDTO>); }