Ejemplo n.º 1
0
        internal IFacadeUpdateResult <GridRowData> SaveGridRow(GridRowData row)
        {
            ArgumentValidator.IsNotNull("row", row);

            FacadeUpdateResult <GridRowData> result = new FacadeUpdateResult <GridRowData>();
            IGridRowService service  = UnitOfWork.GetService <IGridRowService>();
            GridRow         instance = RetrieveOrNew <GridRowData, GridRow, IGridRowService>(result.ValidationResult, row.Id);

            if (result.IsSuccessful)
            {
                // Grid cells
                if (instance.IsNew)
                {
                    instance.ReferenceId = row.ReferenceId;
                    instance.GridId      = row.GridId;
                    instance.Sort        = row.Sort;

                    // Save row first
                    var saveRowQuery = service.Save(instance);
                    // Then save cells
                    foreach (GridCellData newValue in row.Cells)
                    {
                        GridCell child = instance.Cells.AddNewBo();
                        child.GridColumnId = newValue.GridColumnId;
                        child.ValueText    = newValue.ValueText;
                        child.ValueHtml    = newValue.ValueHtml;
                        child.ValueInt     = newValue.ValueInt;
                        child.ValueDate    = newValue.ValueDate;
                        child.ValueUrl     = newValue.ValueUrl;
                    }
                }
                else
                {
                    foreach (GridCellData newValue in row.Cells)
                    {
                        GridCell child = instance.Cells.SingleOrDefault(o => object.Equals(o.GridColumnId, newValue.GridColumnId));
                        if (child != null)
                        {
                            child.GridColumnId = newValue.GridColumnId;
                            child.ValueText    = newValue.ValueText;
                            child.ValueHtml    = newValue.ValueHtml;
                            child.ValueInt     = newValue.ValueInt;
                            child.ValueDate    = newValue.ValueDate;
                            child.ValueUrl     = newValue.ValueUrl;
                        }
                        else
                        {
                            AddError(result.ValidationResult, "GridCellCannotBeFound");
                        }
                    }
                }

                var saveQuery = service.Save(instance);

                result.AttachResult(instance.RetrieveData <GridRowData>());
                result.Merge(saveQuery);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private IList <GridRowData> GetGridRows()
        {
            IList <GridRowData> rows = new List <GridRowData>();

            // IngredientGrid
            {
                GridRowData row = new GridRowData();
                rows.Add(row);
                row.GridId = IngredientGridId;
                row.Sort   = 1;

                GridCellData cell1 = new GridCellData();
                row.Cells.Add(cell1);
                cell1.GridColumnId = BlockRegister.RecipeIngredientGrid.Col_Sortorder;
                cell1.ValueText    = "1";

                GridCellData cell2 = new GridCellData();
                row.Cells.Add(cell2);
                cell2.GridColumnId = BlockRegister.RecipeIngredientGrid.Col_IngredientName;
                cell2.ValueText    = "ingredient.Label";

                GridCellData cell3 = new GridCellData();
                row.Cells.Add(cell3);
                cell3.GridColumnId = BlockRegister.RecipeIngredientGrid.Col_Quantity;
                cell3.ValueText    = "2";

                GridCellData cell4 = new GridCellData();
                row.Cells.Add(cell4);
                cell4.GridColumnId = BlockRegister.RecipeIngredientGrid.Col_UnitOfMeasure;
                cell4.ValueText    = "ingredient.UnitOfMeasureName";
            }

            // InstructionGrid
            {
                GridRowData row = new GridRowData();
                rows.Add(row);
                row.GridId = InstructionGridId;
                row.Sort   = 1;

                GridCellData cell1 = new GridCellData();
                row.Cells.Add(cell1);
                cell1.GridColumnId = BlockRegister.RecipeInstructionGrid.Col_Sortorder;
                cell1.ValueText    = "1";

                GridCellData cell2 = new GridCellData();
                row.Cells.Add(cell2);
                cell2.GridColumnId = BlockRegister.RecipeInstructionGrid.Col_Description;
                cell2.ValueText    = "step.Description";
            }

            return(rows);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update GridRows and their GridCells
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public IFacadeUpdateResult <GridRowData> SaveGridRow(GridRowData row)
        {
            UnitOfWork.BeginTransaction();
            IFacadeUpdateResult <GridRowData> result = ReferenceSystem.SaveGridRow(row);

            if (result.IsSuccessful)
            {
                UnitOfWork.CommitTransaction();
            }
            else
            {
                UnitOfWork.RollbackTransaction();
            }

            return(result);
        }