コード例 #1
0
        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));
        }
コード例 #2
0
        public IHttpActionResult GetGasStationsByID([FromUri] GasStationsParametersID gasStationsParametersID)
        {
            if (gasStationsParametersID != null && ModelState.IsValid)
            {
                GasStationsDTO gasStationsDTO = _gasstationsservice.GetGasStationsByID(gasStationsParametersID, 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));
        }
コード例 #3
0
        public GasStationsDTO GetGasStationsByID(GasStationsParametersID gasStationsParametersID, out ReturnValues returnValues)
        {
            GasStation     gasStation;
            GasStationsDTO gasStationsDTO = null;

            returnValues = new ReturnValues();
            int ID = Convert.ToInt32(gasStationsParametersID.ID);

            try
            {
                gasStation = _unitOfWork.GasStationRepository.Get(row => row.ID == ID);
                if (gasStation == null)
                {
                    returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.NotFound));
                    return(gasStationsDTO);
                }

                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()
                };

                gasStationsDTO.lastUpdatePrice     = GetlastUpdatePrice(gasStationsDTO.ID);
                gasStationsDTO.NamelastUpdatePrice = GetNamelastUpdatePrice(gasStationsDTO.ID);

                returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok));
            }
            catch (Exception ex)
            {
                returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message);
            }
            return(gasStationsDTO);
        }
コード例 #4
0
        //public RegistrationsDTO UpdateRegistrationsbyID(RegistrationsParametersUpdate usersParametersUpdate, out ReturnValues returnValues)
        //{
        //    Registration registration;
        //    RegistrationsDTO registrationsDTO = null;
        //    returnValues = new ReturnValues();
        //    int ID = Convert.ToInt32(usersParametersUpdate.ID);

        //    try
        //    {
        //        registration = _unitOfWork.RegistrationRepository.Get(row => row.ID == ID);
        //        if (registration == null)
        //        {
        //            returnValues.SetReturnValues(true, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.NotFound));
        //            return registrationsDTO;
        //        }

        //        registration.Name = usersParametersUpdate.Name;
        //        registration.Email = usersParametersUpdate.Email;
        //        registration.CPFCNPJ = usersParametersUpdate.CPFCNPJ;
        //        registration.Phone = usersParametersUpdate.Phone;
        //        registration.Password = Utils.Encrypt(usersParametersUpdate.Password);
        //        registration.CEP = usersParametersUpdate.CEP;
        //        registration.Address = usersParametersUpdate.Address;
        //        registration.Number = usersParametersUpdate.Number;
        //        registration.DistrictID = usersParametersUpdate.DistrictID;
        //        registration.CityID = usersParametersUpdate.CityID;
        //        registration.StateID = usersParametersUpdate.StateID;
        //        registration.UpdatedOn = DateTime.Now;

        //        _unitOfWork.RegistrationRepository.Update(registration);
        //        _unitOfWork.PersistChanges();

        //        registrationsDTO = new RegistrationsDTO
        //        {
        //            ID = registration.ID.ToString(),
        //            Status = registration.Status.ToString(),
        //            Name = registration.Name,
        //            Email = registration.Email,
        //            CPFCNPJ = registration.CPFCNPJ,
        //            Phone = registration.Phone,
        //            Username = registration.Username,
        //            Password = registration.Password,
        //            CEP = registration.CEP,
        //            Address = registration.Address,
        //            Number = registration.Number,
        //            DistrictID = registration.DistrictID,
        //            CityID = registration.CityID,
        //            StateID = registration.StateID,
        //            Type = registration.Type,
        //            CreatedOn = registration.CreatedOn.ToString(),
        //            UpdatedOn = registration.UpdatedOn.ToString()
        //        };

        //        returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok));
        //    }
        //    catch (Exception ex)
        //    {
        //        returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message);
        //    }

        //    return registrationsDTO;
        //}

        public GasStationsDTO DeleteGasStationsByID(GasStationsParametersID gasStationsParametersID, out ReturnValues returnValues)
        {
            #region Parameters

            GasStation     gasStation;
            GasStationsDTO gasStationsDTO = null;
            returnValues = new ReturnValues();
            int ID = Convert.ToInt32(gasStationsParametersID.ID);

            #endregion

            try
            {
                gasStation = _unitOfWork.GasStationRepository.Get(row => row.ID == ID);
                if (gasStation == null)
                {
                    returnValues.SetReturnValues(true, ErrorCodes.NotFound, Utils.GetEnumDescription(ErrorCodes.NotFound));
                    return(gasStationsDTO);
                }

                _unitOfWork.GasStationRepository.Delete(gasStation);
                _unitOfWork.PersistChanges();

                gasStationsDTO = new GasStationsDTO
                {
                    ID = gasStation.ID.ToString(),
                };

                returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok));
            }
            catch (Exception ex)
            {
                returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message);
            }
            return(gasStationsDTO);
        }
コード例 #5
0
        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);
        }