public static Common.Models.Events.EventMatter RelateToMatter(Common.Models.Events.Event model, Common.Models.Matters.Matter matter, Common.Models.Account.Users actor) { Common.Models.Events.EventMatter em; DBOs.Events.EventMatter dbo = null; em = Data.Events.EventMatter.Get(model.Id.Value, matter.Id.Value); if (em != null) { return(em); } em = new Common.Models.Events.EventMatter(); em.Id = Guid.NewGuid(); em.CreatedBy = em.ModifiedBy = actor; em.Created = em.Modified = DateTime.UtcNow; em.Event = model; em.Matter = matter; dbo = Mapper.Map <DBOs.Events.EventMatter>(em); using (IDbConnection conn = Database.Instance.GetConnection()) { conn.Execute("INSERT INTO \"event_matter\" (\"id\", \"event_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @EventId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo); } return(em); }
public static Common.Models.Events.EventMatter RelateToMatter(Common.Models.Events.Event model, Common.Models.Matters.Matter matter, Common.Models.Account.Users actor, IDbConnection conn = null, bool closeConnection = true) { Common.Models.Events.EventMatter em; DBOs.Events.EventMatter dbo = null; em = Data.Events.EventMatter.Get(model.Id.Value, matter.Id.Value); if (em != null) { return(em); } em = new Common.Models.Events.EventMatter(); em.Id = Guid.NewGuid(); em.CreatedBy = em.ModifiedBy = actor; em.Created = em.Modified = DateTime.UtcNow; em.Event = model; em.Matter = matter; dbo = Mapper.Map <DBOs.Events.EventMatter>(em); conn = DataHelper.OpenIfNeeded(conn); if (conn.Execute("INSERT INTO \"event_matter\" (\"id\", \"event_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @EventId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo) > 0) { model.Id = conn.Query <DBOs.Events.EventMatter>("SELECT currval(pg_get_serial_sequence('event_matter', 'id')) AS \"id\"").Single().Id; } DataHelper.Close(conn, closeConnection); return(em); }