Esempio n. 1
0
        /// <inheritdoc />
        public int Add(LocationDTO locationDTO)
        {
            int n = 0;
            try
            {
                connexion.Open();
                command.CommandText = ADD_REQUEST;

                command.Parameters.Add(new MySqlParameter("@idMembre", locationDTO.IdMembre));
                command.Parameters.Add(new MySqlParameter("@idVoiture", locationDTO.IdVoiture));
                command.Parameters.Add(new MySqlParameter("@dateLocation", Convert.ToDateTime(locationDTO.DateLocation)));
                command.Parameters.Add(new MySqlParameter("@dateRetour", Convert.ToDateTime(locationDTO.DateRetour)));

                n = command.ExecuteNonQuery();
            }
            catch (MySqlException mySqlException)
            {
                throw mySqlException;
            }
            finally
            {
                connexion.Close();
            }
            return n;
        }
Esempio n. 2
0
 /// <inheritdoc />
 public int AddLocation(LocationDTO locationDTO)
 {
     try
     {
         return locationDAO.Add(locationDTO);
     }
     catch (DAOException daoException)
     {
         throw new ServiceException(daoException.Message);
     }
 }
Esempio n. 3
0
        /// <inheritdoc />
        public int Update(LocationDTO locationDTO, int id)
        {
            int n = 0;
            try
            {
                connexion.Open();
                command.CommandText = UPDATE_REQUEST;

                command.Parameters.Add(new MySqlParameter("@idMembre", locationDTO.IdMembre));
                command.Parameters.Add(new MySqlParameter("@idVoiture", locationDTO.IdVoiture));
                command.Parameters.Add(new MySqlParameter("@dateLocation", locationDTO.DateLocation));
                command.Parameters.Add(new MySqlParameter("@dateRetour", locationDTO.DateRetour));
                command.Parameters.Add(new MySqlParameter("@idLocation", id));
                n = command.ExecuteNonQuery();
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException);
            }
            finally
            {
                connexion.Close();
            }
            return n;
        }
Esempio n. 4
0
        /// <inheritdoc />
        public LocationDTO Read(int id)
        {
            LocationDTO locationDTO = new LocationDTO();
            try
            {
                connexion.Open();
                command.CommandText = READ_REQUEST;

                command.Parameters.Add(new MySqlParameter("@idLocation", id));
                MySqlDataReader dr = command.ExecuteReader();

                if (dr.Read())
                {
                    locationDTO.IdLocation = dr.GetInt32(0);
                    locationDTO.IdMembre = dr.GetInt32(1);
                    locationDTO.IdVoiture = dr.GetInt32(2);
                    locationDTO.DateLocation = dr.GetDateTime(3).ToString();
                    locationDTO.DateRetour = dr.GetMySqlDateTime(4).ToString();
                }
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException);
            }
            finally
            {
                connexion.Close();
            }
            return locationDTO;
        }
Esempio n. 5
0
        /// <inheritdoc />
        public List<LocationDTO> GetAll()
        {
            List<LocationDTO> locations = new List<LocationDTO>();

            LocationDTO locationDTO = new LocationDTO();
            try
            {
                connexion.Open();
                command.CommandText = GET_ALL_REQUEST;

                MySqlDataReader dr = command.ExecuteReader();
                while (dr.Read())
                {
                    locationDTO.IdLocation = dr.GetInt32(0);

                    MembreDTO membre = new MembreDTO();
                    locationDTO.IdMembre = dr.GetInt32(1);

                    VoitureDTO voiture = new VoitureDTO();
                    locationDTO.IdVoiture = dr.GetInt32(2);
                    locationDTO.DateLocation = dr.GetDateTime(3).ToString();
                    locationDTO.DateRetour = dr.GetDateTime(4).ToString();
                    locations.Add(locationDTO);
                }
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException);
            }
            finally
            {
                connexion.Close();
            }
            return locations;
        }
Esempio n. 6
0
        /// <inheritdoc />
        public List<LocationDTO> FindByVoiture(int idVoiture)
        {
            List<LocationDTO> locations = new List<LocationDTO>();
            LocationDTO locationDTO = new LocationDTO();
            try
            {
                connexion.Open();
                command.CommandText = FIND_BY_VOITURE;
                command.Parameters.Add(new MySqlParameter("@idVoiture", idVoiture));

                MySqlDataReader dr = command.ExecuteReader();

                while (dr.Read())
                {
                    locationDTO.IdLocation = dr.GetInt32(0);
                    locationDTO.IdMembre = dr.GetInt32(1);
                    locationDTO.IdVoiture = dr.GetInt32(2);
                    locationDTO.DateLocation = dr.GetDateTime(3).ToString();
                    locationDTO.DateRetour = dr.GetDateTime(4).ToString();
                    locations.Add(locationDTO);
                }
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException);
            }
            finally
            {
                connexion.Close();
            }
            return locations;
        }
Esempio n. 7
0
 /// <inheritdoc />
 public int UpdateLocation(LocationDTO locationDTO, int id)
 {
     try
     {
         return locationDAO.Update(locationDTO, id);
     }
     catch (DAOException daoException)
     {
         throw new ServiceException(daoException.Message);
     }
 }