public bool addNewData(VoyageData data)
        {
            bool          result     = false;
            DbConnection  connection = new DbConnection();
            SqlConnection con        = connection.connectToDatabase();
            SqlCommand    cmd        = new SqlCommand();

            cmd.Connection  = con;
            cmd.CommandText = "INSERT INTO VoyageData(VoyageUserID,ImageData,VoyageContent,VoyageState,VoyageCity)" +
                              "VALUES(@userId,@image,@content,@state,@city)";

            cmd.Parameters.AddWithValue("@userId", data.UserId);
            cmd.Parameters.AddWithValue("@image", data.imageData);
            cmd.Parameters.AddWithValue("@content", data.VoyageContent);
            cmd.Parameters.AddWithValue("@state", data.VoyageState);
            cmd.Parameters.AddWithValue("@city", data.VoyageCity);

            try
            {
                con.Open();
                int rows_affected = cmd.ExecuteNonQuery();
                result = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Occured:" + ex.Message);
                result = false;
            }
            finally
            {
                con.Close();
            }
            return(result);
        }
예제 #2
0
        public Voyage Ajout(Voyage voyage)
        {
            var voyageData = new VoyageData();

            if (voyage.DateAller > DateTime.Now.AddDays(3) && voyage.DateRetour > voyage.DateAller.AddDays(2) &&
                new DestinationData().GetById(voyage.DestinationId) != null)
            {
                voyageData.Ajout(voyage);
            }


            return(voyage);
        }
        public bool addNewVoyageData(VoyageData data)
        {
            bool result = false;
            //creating the connection to the database
            DbConnection  connection = new DbConnection();
            SqlConnection con        = connection.connectToDatabase();
            //create the instance to the SqlCommand Object
            SqlCommand cmd = new SqlCommand();

            //Command Object population to the connection and providing the Query string to the sql command object
            cmd.Connection  = con;
            cmd.CommandText = "INSERT INTO VoyageData(VoyageUserID,ImageData,VoyageContent,VoyageState,VoyageCity)" +
                              "VALUES(@userId,@image,@content,@state,@city)";
            //using the parameterized query
            cmd.Parameters.AddWithValue("@userId", data.UserId);
            cmd.Parameters.AddWithValue("@image", data.imageData);
            cmd.Parameters.AddWithValue("@content", data.VoyageContent);
            cmd.Parameters.AddWithValue("@state", data.VoyageState);
            cmd.Parameters.AddWithValue("@city", data.VoyageCity);

            //try block starting
            try
            {
                //open the connection to database
                con.Open();
                //returns the number of rows affected in the database
                int rows_affected = cmd.ExecuteNonQuery();
                //return the result of the operation
                result = true;
            }
            //starting of the catch block
            catch (Exception ex)
            {
                //just for checking for the developer purpose
                Console.WriteLine("Error Occured:" + ex.Message);
                //using the custom exception to return the error message at the client side
                Custom_Exception custom_Exception = new Custom_Exception();
                //Giving the appropriate values to the custom exception object
                custom_Exception.Title            = "Voyage_Guide Custom Exception Message";
                custom_Exception.ExceptionMessage = ex.Message;
                //throwthe fault exception
                throw new FaultException <Custom_Exception>(custom_Exception);
            }
            finally
            {
                //Closing the Database Connection
                con.Close();
            }
            return(result);
        }
예제 #4
0
        public bool Supprimer(int voyageId)
        {
            var voyageData  = new VoyageData();
            var dossierData = new DossierData();
            var voyage      = voyageData.GetById(voyageId);

            if (dossierData.GetList().Where(x => x.VoyageId == voyageId).Count() > 0)
            {
                return(false);
            }
            else
            {
                return(voyageData.Effacer(voyage));
            }
        }
예제 #5
0
        public bool addNewVoyageData([FromBody] VoyageData data)
        {
            bool result = false;
            //creating the connection to the database
            DbConnection  connection = new DbConnection();
            SqlConnection con        = connection.connectToDatabase();
            //create the instance to the SqlCommand Object
            SqlCommand cmd = new SqlCommand();

            //Command Object population to the connection and providing the Query string to the sql command object
            cmd.Connection  = con;
            cmd.CommandText = "INSERT INTO VoyageData(VoyageUserID,ImageData,VoyageContent,VoyageState,VoyageCity)" +
                              "VALUES(@userId,@image,@content,@state,@city)";
            //using the parameterized query
            cmd.Parameters.AddWithValue("@userId", data.UserId);
            cmd.Parameters.AddWithValue("@image", data.imageData);
            cmd.Parameters.AddWithValue("@content", data.VoyageContent);
            cmd.Parameters.AddWithValue("@state", data.VoyageState);
            cmd.Parameters.AddWithValue("@city", data.VoyageCity);

            //try block starting
            try
            {
                //open the connection to database
                con.Open();
                //returns the number of rows affected in the database
                int rows_affected = cmd.ExecuteNonQuery();
                //return the result of the operation
                result = true;
            }
            //starting of the catch block
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                //Closing the Database Connection
                con.Close();
            }
            return(result);
        }
예제 #6
0
        public DossierReservation Accepter(int dossierReservationId)
        {
            var dossierReservation = new DossierData().GetById(dossierReservationId);

            if (dossierReservation != null &&
                dossierReservation.EtatDossierReservation == EtatDossierReservation.EnCours)
            {
                var voyage = new VoyageData().GetById(dossierReservation.VoyageId);
                if (voyage.PlacesDisponibles >= dossierReservation.Participants.Count)
                {
                    dossierReservation.EtatDossierReservation = EtatDossierReservation.Accepte;
                    new DossierData().Update(dossierReservation);
                    new VoyageService().Reserver(voyage, dossierReservation.Participants.Count);
                }
                else
                {
                    dossierReservation.EtatDossierReservation  = EtatDossierReservation.Refuse;
                    dossierReservation.RaisonAnnulationDossier = RaisonAnnulationDossier.PlacesInsuffisantes;
                    new DossierData().Update(dossierReservation);
                }
            }
            return(dossierReservation);
        }
예제 #7
0
 /// <summary>
 /// Creates or updates a voyage.
 /// </summary>
 /// <param name="voyageData">The detailed voyage object.</param>
 /// <returns>
 /// The voyage object returned from the service (including ID).
 /// </returns>
 public Voyage CreateOrUpdate(VoyageData voyageData)
 {
     return(PostObject <Voyage, VoyageData>(voyageData, "/api/v1/voyages"));
 }