public static Common.Models.Billing.ExpenseMatter Create( Common.Models.Billing.ExpenseMatter model, Common.Models.Account.Users creator, IDbConnection conn = null, bool closeConnection = true) { model.Created = model.Modified = DateTime.UtcNow; model.CreatedBy = model.ModifiedBy = creator; DBOs.Billing.ExpenseMatter dbo = Mapper.Map <DBOs.Billing.ExpenseMatter>(model); conn = DataHelper.OpenIfNeeded(conn); Common.Models.Billing.ExpenseMatter currentModel = Get(model.Matter.Id.Value, model.Expense.Id.Value, conn, false); if (currentModel != null) { // Update conn.Execute("UPDATE \"expense_matter\" SET \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " + "\"utc_disabled\"=null, \"disabled_by_user_pid\"=null WHERE \"id\"=@Id", dbo); model.Created = currentModel.Created; model.CreatedBy = currentModel.CreatedBy; } else { // Create if (conn.Execute("INSERT INTO \"expense_matter\" (\"id\", \"expense_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @ExpenseId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo) > 0) { model.Id = conn.Query <DBOs.Billing.ExpenseMatter>("SELECT currval(pg_get_serial_sequence('expense_matter', 'id')) AS \"id\"").Single().Id; } } DataHelper.Close(conn, closeConnection); return(model); }
public static Common.Models.Billing.ExpenseMatter Create(Common.Models.Billing.ExpenseMatter model, Common.Models.Account.Users creator) { model.Created = model.Modified = DateTime.UtcNow; model.CreatedBy = model.ModifiedBy = creator; DBOs.Billing.ExpenseMatter dbo = Mapper.Map <DBOs.Billing.ExpenseMatter>(model); using (IDbConnection conn = Database.Instance.GetConnection()) { Common.Models.Billing.ExpenseMatter currentModel = Get(model.Matter.Id.Value, model.Expense.Id.Value); if (currentModel != null) { // Update conn.Execute("UPDATE \"expense_matter\" SET \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " + "\"utc_disabled\"=null, \"disabled_by_user_pid\"=null WHERE \"id\"=@Id", dbo); model.Created = currentModel.Created; model.CreatedBy = currentModel.CreatedBy; } else { // Create conn.Execute("INSERT INTO \"expense_matter\" (\"id\", \"expense_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @ExpenseId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo); } } return(model); }