public bool Save(UserTrip entity)
        {
            Check.IsNotNull(entity, "User trip shouldn't be empty");
            bool saved = false;

            entity.ModificationDate = TimeProvider.Now();
            _logger.Info("Start saving users trip");
            try
            {
                using (var con = new DatabaseConnection(DatabaseType.PostgreSql, GetConnectionString()))
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = InsertQuery;
                        cmd.AddIntParameter(":pUSRIDT", entity.UserId);
                        cmd.AddStringParameter(":pTRPNAM", entity.TripName);
                        cmd.AddStringParameter(":pINDUSRPAR", ConverterHelper.BoolToYesNoString(entity.HasParticipated));
                        cmd.AddStringParameter(":pINDUSRORG", ConverterHelper.BoolToYesNoString(entity.HasOrganized));
                        cmd.AddDoubleParameter(":pUSRNOT", entity.UserNote);
                        cmd.AddDoubleParameter(":pTRPMNT", entity.TripAmount);
                        cmd.AddDateTimeParameter(":pDATEFT", entity.ModificationDate);
                        saved = cmd.ExecuteNonQuery() > 0;
                        _logger.Info("End saving users trip " + (saved ? "Success" : "Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while saving user's trip with query : " + InsertQuery, ex);
                throw new ImportExportException("Error occured during database access " + ex.Message, ex);
            }

            return(saved);
        }
        public bool Save(TripParticipant entity)
        {
            Check.IsNotNull(entity, "Participant should be provided");
            var saved = false;

            entity.ModificationDate = TimeProvider.Now();
            _logger.Info("Start save trip participant");
            try
            {
                using (var con = new DatabaseConnection(DatabaseType.PostgreSql, GetConnectionString()))
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = InsertQuery;
                        cmd.AddIntParameter(":pTRPIDT", entity.TripId);
                        cmd.AddStringParameter(":pUSRPSD", entity.UserPseudo);
                        cmd.AddStringParameter(":pINDUSRPTP", ConverterHelper.BoolToYesNoString(entity.HasParticipated));
                        cmd.AddDoubleParameter(":pTRPNOT", entity.TripNote);
                        cmd.AddDateParameter(":pVALDAT", entity.ValidationDate);
                        cmd.AddDateTimeParameter(":pDATEFT", entity.ModificationDate);
                        saved = cmd.ExecuteNonQuery() > 0;
                        _logger.Info("End save trip participant : " + (saved ? "Success" : "Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while trying to save trip participant with query : " + InsertQuery, ex);
                throw new ImportExportException("Error occured during database access " + ex.Message, ex);
            }

            return(saved);
        }
        public bool Update(Friendship entity)
        {
            Check.IsNotNull(entity, "Friendship should be provided");

            var updated = false;

            entity.ModificationDate = TimeProvider.Now();
            _logger.Info("Start updating Friendship");
            try
            {
                using (var con = new DatabaseConnection(DatabaseType.PostgreSql, GetConnectionString()))
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = UpdateQuery;
                        cmd.AddIntParameter(":pUSRIDT", entity.UserId);
                        cmd.AddStringParameter(":pFRDPSD", entity.FriendName);
                        cmd.AddDateParameter(":pSTRDAT", entity.StartDate);
                        cmd.AddStringParameter(":pINDRSQUSR", ConverterHelper.BoolToYesNoString(entity.IsRequested));
                        cmd.AddStringParameter(":pINDWTG", ConverterHelper.BoolToYesNoString(entity.IsWaiting));
                        cmd.AddDateTimeParameter(":pDATEFT", entity.ModificationDate);
                        updated = cmd.ExecuteNonQuery() > 0;
                        _logger.Info("End updating Friendship : " + (updated ? "Success" : "Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while trying to update Friendship with the following query : " + UpdateQuery, ex);
                throw new ImportExportException("Error occured during database access " + ex.Message, ex);
            }

            return(updated);
        }
Esempio n. 4
0
        public bool Save(Pot entity)
        {
            Check.IsNotNull(entity, "Pot should be provided");

            var saved = false;

            entity.ModificationDate = TimeProvider.Now();
            _logger.Info("Start saving pot");

            try
            {
                // id
                var id = GetNewId();

                if (id <= 0)
                {
                    _logger.Info("Unable to retrieve new id to save a pot");
                    return(false);
                }
                using (var con = new DatabaseConnection(DatabaseType.PostgreSql, GetConnectionString()))
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = InsertQuery;
                        cmd.AddIntParameter(":pIDT", id);
                        cmd.AddStringParameter(":pORG", entity.Organizer);
                        cmd.AddStringParameter(":pPOTMOD", ModelEnumConverter.PotModeToString(entity.Mode));
                        cmd.AddDoubleParameter(":pCURMNT", entity.CurrentAmount);
                        cmd.AddDoubleParameter(":pTGTMNT", entity.TargetAmount);
                        cmd.AddIntParameter(":pTRPIDT", entity.TripId);
                        cmd.AddStringParameter(":pNAM", entity.Name);
                        cmd.AddDateParameter(":pSTRDAT", entity.StartDate);
                        cmd.AddDateParameter(":pENDDAT", entity.EndDate);
                        cmd.AddDateParameter(":pVALDAT", entity.ValidityDate);
                        cmd.AddStringParameter(":pDSC", entity.Description);
                        cmd.AddStringParameter(":pINDCANCEL", ConverterHelper.BoolToYesNoString(entity.IsCancelled));
                        cmd.AddStringParameter(":pCANCELRSN", entity.CancellationReason);
                        cmd.AddDateParameter(":pCANCELDAT", entity.CancellationDate);
                        cmd.AddDateTimeParameter(":pDATEFT", entity.ModificationDate);
                        saved = cmd.ExecuteNonQuery() > 0;
                        _logger.Info("End saving pot " + (saved ? "Success" : "Error"));
                        if (saved)
                        {
                            entity.Id = id;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while trying to save pot with query : " + InsertQuery, ex);
                throw new ImportExportException("Error occured during database access " + ex.Message, ex);
            }

            return(saved);
        }
Esempio n. 5
0
        public bool Update(Pot entity)
        {
            var updated = false;

            Check.IsNotNull(entity, "Pot must provided for update");
            entity.ModificationDate = TimeProvider.Now();
            _logger.Info("Start updating pot");
            try
            {
                using (var con = new DatabaseConnection(DatabaseType.PostgreSql, GetConnectionString()))
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = UpdateQuery;
                        cmd.AddIntParameter(":pIDT", entity.Id);
                        cmd.AddStringParameter(":pORG", entity.Organizer);
                        cmd.AddStringParameter(":pPOTMOD", ModelEnumConverter.PotModeToString(entity.Mode));
                        cmd.AddDoubleParameter(":pCURMNT", entity.CurrentAmount);
                        cmd.AddDoubleParameter(":pTGTMNT", entity.TargetAmount);
                        cmd.AddStringParameter(":pNAM", entity.Name);
                        cmd.AddDateParameter(":pSTRDAT", entity.StartDate);
                        cmd.AddDateParameter(":pENDDAT", entity.EndDate);
                        cmd.AddDateParameter(":pVALDAT", entity.ValidityDate);
                        cmd.AddStringParameter(":pDSC", entity.Description);
                        cmd.AddStringParameter(":pINDCANCEL", ConverterHelper.BoolToYesNoString(entity.IsCancelled));
                        cmd.AddStringParameter(":pCANCELRSN", entity.CancellationReason);
                        cmd.AddDateParameter(":pCANCELDAT", entity.CancellationDate);
                        cmd.AddDateTimeParameter(":pDATEFT", entity.ModificationDate);
                        updated = cmd.ExecuteNonQuery() > 0;
                        _logger.Info("End updating pot : " + (updated ? "Success" : "Error"));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while trying to update pot with query : " + UpdateQuery, ex);
                throw new ImportExportException("Error occured during database access " + ex.Message, ex);
            }

            return(updated);
        }
Esempio n. 6
0
        public bool Update(PotUser entity)
        {
            Check.IsNotNull(entity, "Pot participant should be provided");
            var updated = false;

            entity.ModificationDate = TimeProvider.Now();
            _logger.Info("Start updating user pot");
            try
            {
                using (var con = new DatabaseConnection(DatabaseType.PostgreSql, GetConnectionString()))
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = UpdateQuery;
                        cmd.AddIntParameter(":pPOTIDT", entity.PotId);
                        cmd.AddIntParameter(":pUSRIDT", entity.UserId);
                        cmd.AddStringParameter(":pINDPAY", ConverterHelper.BoolToYesNoString(entity.HasPayed));
                        cmd.AddDoubleParameter(":pCURMNT", entity.Amount);
                        cmd.AddDoubleParameter(":pTGTMNT", entity.TargetAmount);
                        cmd.AddStringParameter(":pCANCELRSN", entity.CancellationReason);
                        cmd.AddStringParameter(":pINDCANCEL", ConverterHelper.BoolToYesNoString(entity.HasCancelled));
                        cmd.AddStringParameter(":pINDVAL", ConverterHelper.BoolToYesNoString(entity.HasValidated));
                        cmd.AddDateTimeParameter(":pDATEFT", entity.ModificationDate);
                        updated = cmd.ExecuteNonQuery() > 0;
                        _logger.Info("End updating user pot : " + (updated ? "Success" : "Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Error while trying to update user pot with query : " + UpdateQuery, ex);
                throw new ImportExportException("Error occured during database access " + ex.Message, ex);
            }

            return(updated);
        }