public IHttpActionResult CreateGasStations([FromBody] GasStationsParametersCreate gasStationsParametersCreate) { if (gasStationsParametersCreate != null && ModelState.IsValid) { GasStationsDTO gasStationsDTO = _gasstationsservice.CreateGasStations(gasStationsParametersCreate, out ReturnValues returnValues); if (!returnValues.Error) { return(Ok(new ResponseSuccess { Success = true, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message, Data = new { gasStation = gasStationsDTO, }, })); } return(Ok(new ResponseError { Success = false, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message })); } return(BadRequest(ModelState)); }
public GasStationsDTO CreateGasStations(GasStationsParametersCreate gasStationsParametersCreate, out ReturnValues returnValues) { #region Parameters GasStation gasStation; GasStationsDTO gasStationsDTO = null; returnValues = new ReturnValues(); #endregion try { gasStation = new GasStation() { Status = false, Name = gasStationsParametersCreate.Name, Phone = string.IsNullOrEmpty(gasStationsParametersCreate.Phone) ? null : gasStationsParametersCreate.Phone, GasolinaComum = string.IsNullOrEmpty(gasStationsParametersCreate.GasolinaComum) ? false : Convert.ToBoolean(gasStationsParametersCreate.GasolinaComum), GasolinaAditivada = string.IsNullOrEmpty(gasStationsParametersCreate.GasolinaAditivada) ? false : Convert.ToBoolean(gasStationsParametersCreate.GasolinaAditivada), Disel = string.IsNullOrEmpty(gasStationsParametersCreate.Disel) ? false : Convert.ToBoolean(gasStationsParametersCreate.Disel), Gas = string.IsNullOrEmpty(gasStationsParametersCreate.Gas) ? false : Convert.ToBoolean(gasStationsParametersCreate.Gas), PriceGasolinaComum = string.IsNullOrEmpty(gasStationsParametersCreate.PriceGasolinaComum) ? 0 : Math.Round(Convert.ToDecimal(gasStationsParametersCreate.PriceGasolinaComum), 2), PriceGasolinaAditivada = string.IsNullOrEmpty(gasStationsParametersCreate.PriceGasolinaAditivada) ? 0 : Math.Round(Convert.ToDecimal(gasStationsParametersCreate.PriceGasolinaAditivada), 2), PriceDisel = string.IsNullOrEmpty(gasStationsParametersCreate.PriceDisel) ? 0 : Math.Round(Convert.ToDecimal(gasStationsParametersCreate.PriceDisel), 2), PriceGas = string.IsNullOrEmpty(gasStationsParametersCreate.PriceGas) ? 0 : Math.Round(Convert.ToDecimal(gasStationsParametersCreate.PriceGas), 2), Latitude = string.IsNullOrEmpty(gasStationsParametersCreate.Latitude) ? null : gasStationsParametersCreate.Latitude, Longitude = string.IsNullOrEmpty(gasStationsParametersCreate.Longitude) ? null : gasStationsParametersCreate.Longitude, CEP = string.IsNullOrEmpty(gasStationsParametersCreate.CEP) ? null : gasStationsParametersCreate.CEP, Address = gasStationsParametersCreate.Address, Number = gasStationsParametersCreate.Number, DistrictID = gasStationsParametersCreate.DistrictID, CityID = gasStationsParametersCreate.CityID, StateID = gasStationsParametersCreate.StateID, CreatedOn = DateTime.Now }; _unitOfWork.GasStationRepository.Insert(gasStation); _unitOfWork.PersistChanges(); gasStationsDTO = new GasStationsDTO { ID = gasStation.ID.ToString(), Status = gasStation.Status.ToString(), Name = gasStation.Name, Phone = gasStation.Phone, GasolinaComum = gasStation.GasolinaComum.ToString(), GasolinaAditivada = gasStation.GasolinaAditivada.ToString(), Disel = gasStation.Disel.ToString(), Gas = gasStation.Gas.ToString(), PriceGasolinaComum = gasStation.PriceGasolinaComum.ToString(), PriceGasolinaAditivada = gasStation.PriceGasolinaAditivada.ToString(), PriceDisel = gasStation.PriceDisel.ToString(), PriceGas = gasStation.PriceGas.ToString(), Latitude = gasStation.Latitude, Longitude = gasStation.Longitude, CEP = gasStation.CEP, Address = gasStation.Address, Number = gasStation.Number, DistrictID = gasStation.DistrictID, CityID = gasStation.CityID, StateID = gasStation.StateID, CreatedOn = gasStation.CreatedOn.ToString(), UpdatedOn = gasStation.UpdatedOn.ToString(), }; returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok)); } catch (Exception ex) { returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message + " inner --> " + ex.InnerException); } return(gasStationsDTO); }