public async Task GetEditRow()
        {
            // Setup: Create a row delete
            var columns = Common.GetColumns(false);
            var rs      = await Common.GetResultSet(columns, false);

            var       etm = Common.GetStandardMetadata(columns);
            RowDelete rd  = new RowDelete(0, rs, etm);

            // If: I attempt to get an edit row
            DbCellValue[] cells = rs.GetRow(0).ToArray();
            EditRow       er    = rd.GetEditRow(cells);

            // Then:
            // ... The state should be dirty
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyDelete, er.State);

            // ... The ID should be the same as the one provided
            Assert.Equal(0, er.Id);

            // ... The row should match the cells that were given and should be dirty
            Assert.Equal(cells.Length, er.Cells.Length);
            for (int i = 0; i < cells.Length; i++)
            {
                DbCellValue originalCell = cells[i];
                EditCell    outputCell   = er.Cells[i];

                Assert.Equal(originalCell.DisplayValue, outputCell.DisplayValue);
                Assert.Equal(originalCell.IsNull, outputCell.IsNull);
                Assert.True(outputCell.IsDirty);
                // Note: No real need to check the RawObject property
            }
        }
        public async Task GetEditRowNoAdditions()
        {
            // Setup: Generate a standard row create
            RowCreate rc = await GetStandardRowCreate();

            // If: I request an edit row from the row create
            EditRow er = rc.GetEditRow(null);

            // Then:
            // ... The row should not be null
            Assert.NotNull(er);

            // ... The row should not be clean
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should have a bunch of empty cells (equal to number of columns) and all are dirty
            Assert.Equal(rc.newCells.Length, er.Cells.Length);
            Assert.All(er.Cells, ec =>
            {
                Assert.Equal(string.Empty, ec.DisplayValue);
                Assert.False(ec.IsNull);
                Assert.True(ec.IsDirty);
            });
        }
        public async Task GetEditRowWithAdditions()
        {
            // Setp: Generate a row create with a cell added to it
            RowCreate rc = await GetStandardRowCreate();

            const string setValue = "foo";

            rc.SetCell(0, setValue);

            // If: I request an edit row from the row create
            EditRow er = rc.GetEditRow(null);

            // Then:
            // ... The row should not be null and contain the same number of cells as columns
            Assert.NotNull(er);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should not be clean
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should have a single non-empty cell at the beginning that is dirty
            Assert.Equal(setValue, er.Cells[0].DisplayValue);
            Assert.False(er.Cells[0].IsNull);
            Assert.True(er.Cells[0].IsDirty);

            // ... The rest of the cells should be blank, but dirty
            for (int i = 1; i < er.Cells.Length; i++)
            {
                EditCell ec = er.Cells[i];
                Assert.Equal(string.Empty, ec.DisplayValue);
                Assert.False(ec.IsNull);
                Assert.True(ec.IsDirty);
            }
        }
        public async Task GetEditRowWithDefaultValue()
        {
            // Setup: Generate a row create with default values
            const long rowId = 100;

            Common.TestDbColumnsWithTableMetadata data = new Common.TestDbColumnsWithTableMetadata(false, false, 3, 0);
            ResultSet rs = await Common.GetResultSet(data.DbColumns, false);

            RowCreate rc = new RowCreate(rowId, rs, data.TableMetadata);

            // If: I request an edit row from the row create
            EditRow er = rc.GetEditRow(null);

            // Then:
            // ... The row should not be null
            Assert.NotNull(er);

            // ... The row should not be clean
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row sould have a bunch of default values (equal to number of columns) and all are dirty
            Assert.Equal(rc.newCells.Length, er.Cells.Length);
            Assert.All(er.Cells, ec =>
            {
                Assert.Equal(Common.DefaultValue, ec.DisplayValue);
                Assert.False(ec.IsNull);    // TODO: Update when we support null default values better
                Assert.True(ec.IsDirty);
            });
        }
예제 #5
0
        /// <summary>
        /// Retrieves a subset of rows with the pending updates applied. If more rows than exist
        /// are requested, only the rows that exist will be returned.
        /// </summary>
        /// <param name="startIndex">Index to start returning rows from</param>
        /// <param name="rowCount">The number of rows to return.</param>
        /// <returns>An array of rows with pending edits applied</returns>
        public async Task <EditRow[]> GetRows(long startIndex, int rowCount)
        {
            ThrowIfNotInitialized();

            // Get the cached rows from the result set
            ResultSetSubset cachedRows = startIndex < associatedResultSet.RowCount
                ? await associatedResultSet.GetSubset(startIndex, rowCount)
                : new ResultSetSubset
            {
                RowCount = 0,
                Rows     = new DbCellValue[][] { }
            };

            // Convert the rows into EditRows and apply the changes we have
            List <EditRow> editRows = new List <EditRow>();

            for (int i = 0; i < cachedRows.RowCount; i++)
            {
                long        rowId = i + startIndex;
                RowEditBase edr;
                if (EditCache.TryGetValue(rowId, out edr))
                {
                    // Ask the edit object to generate an edit row
                    editRows.Add(edr.GetEditRow(cachedRows.Rows[i]));
                }
                else
                {
                    // Package up the existing row into a clean edit row
                    EditRow er = new EditRow
                    {
                        Id    = rowId,
                        Cells = cachedRows.Rows[i].Select(cell => new EditCell(cell, false)).ToArray(),
                        State = EditRow.EditRowState.Clean
                    };
                    editRows.Add(er);
                }
            }

            // If the requested range of rows was at the end of the original cell set and we have
            // added new rows, we need to reflect those changes
            if (rowCount > cachedRows.RowCount)
            {
                long endIndex = startIndex + cachedRows.RowCount;
                var  newRows  = EditCache.Where(edit => edit.Key >= endIndex).Take(rowCount - cachedRows.RowCount);
                editRows.AddRange(newRows.Select(newRow => newRow.Value.GetEditRow(null)));
            }

            return(editRows.ToArray());
        }
        public async Task GetEditRow()
        {
            // Setup: Create a row update with a cell set
            var columns = Common.GetColumns(false);
            var rs      = await Common.GetResultSet(columns, false);

            var       etm = Common.GetStandardMetadata(columns);
            RowUpdate ru  = new RowUpdate(0, rs, etm);

            ru.SetCell(0, "foo");

            // If: I attempt to get an edit row
            DbCellValue[] cells = rs.GetRow(0).ToArray();
            EditRow       er    = ru.GetEditRow(cells);

            // Then:
            // ... The state should be dirty
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyUpdate, er.State);

            // ... The ID should be the same as the one provided
            Assert.Equal(0, er.Id);

            // ... The row should match the cells that were given, except for the updated cell
            Assert.Equal(cells.Length, er.Cells.Length);
            for (int i = 1; i < cells.Length; i++)
            {
                DbCellValue originalCell = cells[i];
                DbCellValue outputCell   = er.Cells[i];

                Assert.Equal(originalCell.DisplayValue, outputCell.DisplayValue);
                Assert.Equal(originalCell.IsNull, outputCell.IsNull);
                // Note: No real need to check the RawObject property
            }

            // ... The updated cell should match what it was set to and be dirty
            EditCell newCell = er.Cells[0];

            Assert.Equal("foo", newCell.DisplayValue);
            Assert.False(newCell.IsNull);
            Assert.True(newCell.IsDirty);
        }
예제 #7
0
        public async Task GetRowsNoEdits()
        {
            // Setup: Create a session with a proper query and metadata
            Query             q   = QueryExecution.Common.GetBasicExecutedQuery();
            ResultSet         rs  = q.Batches[0].ResultSets[0];
            EditTableMetadata etm = Common.GetCustomEditTableMetadata(rs.Columns.Cast <DbColumn>().ToArray());
            EditSession       s   = await Common.GetCustomSession(q, etm);

            // If: I ask for 3 rows from session skipping the first
            EditRow[] rows = await s.GetRows(1, 3);

            // Then:
            // ... I should get back 3 rows
            Assert.Equal(3, rows.Length);

            // ... Each row should...
            for (int i = 0; i < rows.Length; i++)
            {
                EditRow er = rows[i];

                // ... Have properly set IDs
                Assert.Equal(i + 1, er.Id);

                // ... Have cells equal to the cells in the result set
                DbCellValue[] cachedRow = rs.GetRow(i + 1).ToArray();
                Assert.Equal(cachedRow.Length, er.Cells.Length);
                for (int j = 0; j < cachedRow.Length; j++)
                {
                    Assert.Equal(cachedRow[j].DisplayValue, er.Cells[j].DisplayValue);
                    Assert.Equal(cachedRow[j].IsNull, er.Cells[j].IsNull);
                    Assert.False(er.Cells[j].IsDirty);
                }

                // ... Be clean, since we didn't apply any updates
                Assert.Equal(EditRow.EditRowState.Clean, er.State);
                Assert.False(er.IsDirty);
            }
        }
        public async Task GetEditRowWithCalculatedValue()
        {
            // Setup: Generate a row create with an identity column
            const long rowId = 100;

            Common.TestDbColumnsWithTableMetadata data = new Common.TestDbColumnsWithTableMetadata(false, true, 0, 0);
            ResultSet rs = await Common.GetResultSet(data.DbColumns, true);

            RowCreate rc = new RowCreate(rowId, rs, data.TableMetadata);

            // If: I request an edit row from the row created
            EditRow er = rc.GetEditRow(null);

            // Then:
            // ... The row should not be null
            Assert.NotNull(er);
            Assert.Equal(er.Id, rowId);

            // ... The row should not be clean
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should have a TBD for the identity column
            Assert.Equal(rc.newCells.Length, er.Cells.Length);
            Assert.Equal(SR.EditDataComputedColumnPlaceholder, er.Cells[0].DisplayValue);
            Assert.False(er.Cells[0].IsNull);
            Assert.True(er.Cells[0].IsDirty);

            // ... The rest of the cells should have empty display values
            Assert.All(er.Cells.Skip(1), ec =>
            {
                Assert.Equal(string.Empty, ec.DisplayValue);
                Assert.False(ec.IsNull);
                Assert.True(ec.IsDirty);
            });
        }
예제 #9
0
        protected override IEnumerable <IEnumerable <InlineKeyboardButton> > DefineInlineKeyboard()
        {
            if (EditLabelActionsButton != null)
            {
                EditRow.Add(EditLabelActionsButton);
            }

            if (RemoveLabelActionsButton != null)
            {
                RemoveRow.Add(RemoveLabelActionsButton);
            }

            if (BackLabelActionsButton != null)
            {
                BackLabelActionsRow.Add(BackLabelActionsButton);
            }

            var inlineKeyboard = new List <List <InlineKeyboardButton> >
            {
                EditRow, RemoveRow, BackLabelActionsRow
            };

            return(inlineKeyboard);
        }
예제 #10
0
        public Response UpdateItemInDB(EditRow editRowObj)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(this._connectionString))
                {
                    SqlCommand cmd = new SqlCommand();
                    con.Open();
                    cmd.Connection = con;
                    List <List> listObj = new List <List>();
                    foreach (var rowObj in editRowObj.dynamicListItems)
                    {
                        var    result              = JsonConvert.DeserializeObject <Dictionary <string, string> >(rowObj.ToString());
                        string keyValuesQueryTxt   = string.Empty;
                        int    index               = 0;
                        string identityColumnValue = string.Empty;

                        foreach (var item in result)
                        {
                            if (item.Key == editRowObj.IdentityColumnName)
                            {
                                identityColumnValue = item.Value;
                            }
                            else
                            {
                                keyValuesQueryTxt += string.Concat(item.Key, " = '", item.Value, "'", (index == result.Count - 1) ? "" : ",");
                            }
                            index++;
                        }

                        cmd.CommandText = string.Format("UPDATE {0}.{1} SET {2} OUTPUT INSERTED.* WHERE {3}={4}", editRowObj.SchemaType, editRowObj.TableName, keyValuesQueryTxt, editRowObj.IdentityColumnName, identityColumnValue);

                        if (editRowObj.TableSchemaList == null && editRowObj.TableSchemaList.Count <= 0)
                        {
                            editRowObj.TableSchemaList = GetTableSchema(editRowObj.TableName, editRowObj.SchemaType);
                        }

                        var tblKeys = editRowObj.TableSchemaList.Select(schma => schma.ColumnName).ToList();

                        listObj.AddRange(GetOutputExecutionResult(cmd, tblKeys, result, "EDIT"));
                    }
                    if (listObj.Where(s => s.IsResponseSuccessfull == false).ToList().Count > 0)
                    {
                        return new Response()
                               {
                                   IsResponseSuccess = false, Message = listObj.Where(s => s.IsResponseSuccessfull == false).FirstOrDefault().Message, Result = listObj
                               }
                    }
                    ;
                    else
                    {
                        return new Response()
                               {
                                   IsResponseSuccess = true, Message = "SUCCESS", Result = listObj
                               }
                    };
                }
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsResponseSuccess = false, Message = ex.Message
                });
            }
        }