public static Common.Models.Opportunities.OpportunityContact Create(
            Common.Models.Opportunities.OpportunityContact model,
            Common.Models.Account.Users creator,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            Common.Models.Opportunities.OpportunityContact orig =
                DataHelper.Get <Common.Models.Opportunities.OpportunityContact, DBOs.Opportunities.OpportunityContact>(
                    "SELECT * FROM \"opportunity_contact\" WHERE\"opportunity_id\"=@OpportunityId AND \"contact_id\"=@ContactId",
                    new { OpportunityId = model.Opportunity.Id.Value, ContactId = model.Contact.Id.Value }, conn, closeConnection);

            if (orig != null)
            {
                if (orig.Disabled.HasValue || orig.DisabledBy != null)
                {
                    model.Id = orig.Id;
                    orig     = Edit(model, creator, conn, false);
                    orig     = Enable(model, creator, conn, false);
                }
            }
            else
            {
                model.Created   = model.Modified = DateTime.UtcNow;
                model.CreatedBy = model.ModifiedBy = creator;

                DBOs.Opportunities.OpportunityContact dbo = Mapper.Map <DBOs.Opportunities.OpportunityContact>(model);

                conn = DataHelper.OpenIfNeeded(conn);

                if (conn.Execute("INSERT INTO \"opportunity_contact\" (\"opportunity_id\", \"contact_id\", " +
                                 "\"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " +
                                 "VALUES (@OpportunityId, @ContactId, " +
                                 "@UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)",
                                 dbo) > 0)
                {
                    model.Id = conn.Query <DBOs.Opportunities.OpportunityContact>("SELECT currval(pg_get_serial_sequence('opportunity_contact', 'id')) AS \"id\"").Single().Id;
                }
            }
            DataHelper.Close(conn, closeConnection);

            return(model);
        }
        public static Common.Models.Opportunities.OpportunityContact Edit(
            Common.Models.Opportunities.OpportunityContact model,
            Common.Models.Account.Users modifier,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            model.ModifiedBy = modifier;
            model.Modified   = DateTime.UtcNow;
            DBOs.Opportunities.OpportunityContact dbo = Mapper.Map <DBOs.Opportunities.OpportunityContact>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            conn.Execute("UPDATE \"opportunity_contact\" SET " +
                         "\"opportunity_id\"=@OpportunityId, \"contact_id\"=@ContactId, " +
                         "\"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " +
                         "WHERE \"id\"=@Id", dbo);

            DataHelper.Close(conn, closeConnection);

            return(model);
        }