Exemple #1
0
        private async Task LoadItemAttributeLookupList(DataGridParameters currentDataGridParameters)
        {
            // store old select items list
            try
            {
                var _response = await _AttributeWooLinkedViewRepository.LoadViewItemsPaginatedAsync(currentDataGridParameters);

                if (dataModels == null)
                {
                    dataModels = new List <ItemAttributeLookupView>(_response);  // not sure why we have to use a holding variable just following the demo code
                }
                else
                {
                    dataModels.Clear();
                    dataModels.AddRange(_response);
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError($"Error running async tasks: {ex.Message}");
                throw;
            }
            //restore the old items that were selected.
            SelectedItemAttributeLookups = _AttributeWooLinkedViewRepository.PopSelectedItems(dataModels);
            StateHasChanged();
        }
        private void SetSelectedDataGridParameters(Parameter newParameter, string columnName)
        {
            DataGridParameters.SelectedItem = newParameter;

            DataGridParameters.Focus();
            DataGridParameters.CurrentColumn = (DataGridColumn)FormObjectMethod.FindName(columnName);
            DataGridParameters.CurrentCell   = new DataGridCellInfo(newParameter, DataGridParameters.CurrentColumn);
            DataGridParameters.BeginEdit();
        }
        public override async Task <List <Item> > GetPagedItemsAsync(DataGridParameters currentDataGridParameters)    //int startPage, int currentPageSize)
        {
            IItemRepository      _ItemRepository = _AppUnitOfWork.itemRepository();
            DataGridItems <Item> _dataGridItems  = await _ItemRepository.GetPagedDataEagerWithFilterAndOrderByAsync(currentDataGridParameters);

            List <Item> _Items = _dataGridItems.Entities.ToList();

            _GridSettings.TotalItems = _dataGridItems.TotalRecordCount;
            return(_Items);
        }
Exemple #4
0
        public override async Task <List <ItemCategoryLookup> > GetPagedItemsAsync(DataGridParameters currentDataGridParameters)    //int startPage, int currentPageSize)
        {
            IItemCategoryLookupRepository _itemCategoryLookupRepository = _AppUnitOfWork.itemCategoryLookupRepository();
            //_gridSettings.TotalItems = await _itemCategoryLookupRepository.CountAsync();  // get the total number of items to use for paging.
            DataGridItems <ItemCategoryLookup> _dataGridItems = await _itemCategoryLookupRepository.GetPagedDataEagerWithFilterAndOrderByAsync(currentDataGridParameters);

            List <ItemCategoryLookup> _itemCategoryLookups = _dataGridItems.Entities.ToList();

            _GridSettings.TotalItems = _dataGridItems.TotalRecordCount;

            return(_itemCategoryLookups);
        }
Exemple #5
0
        public override DataGridParameters GetDataGridCurrent(DataGridReadDataEventArgs <ItemCategoryLookupView> inputDataGridReadData, string inputCustomerFilter)
        {
            DataGridParameters _dataGridParameters = new DataGridParameters
            {
                CurrentPage  = inputDataGridReadData.Page,
                PageSize     = inputDataGridReadData.PageSize,
                CustomFilter = inputCustomerFilter
            };

            if (inputDataGridReadData.Columns != null)
            {
                foreach (var col in inputDataGridReadData.Columns)
                {
                    if (col.Direction != Blazorise.SortDirection.None)
                    {
                        if (_dataGridParameters.SortParams == null)
                        {
                            _dataGridParameters.SortParams = new List <SortParam>();
                        }
                        _dataGridParameters.SortParams.Add(new SortParam
                        {
                            FieldName = col.Field,
                            Direction = col.Direction
                        });
                    }
                    if (!string.IsNullOrEmpty(col.SearchValue))
                    {
                        if (_dataGridParameters.FilterParams == null)
                        {
                            _dataGridParameters.FilterParams = new List <FilterParam>();
                        }
                        _dataGridParameters.FilterParams.Add(new FilterParam
                        {
                            FieldName = col.Field,
                            FilterBy  = col.SearchValue
                        });
                    }
                }
            }
            return(_dataGridParameters);
        }
        public override async Task <List <ItemView> > LoadViewItemsPaginatedAsync(DataGridParameters currentDataGridParameters)
        {
            List <Item> _Items = await GetPagedItemsAsync(currentDataGridParameters);

            List <ItemView> _itemViewLookups = new List <ItemView>();
            // Get a list of all the Attribute maps that exists
            List <Guid> _ItemAttribIds = _Items.Where(it => it.ItemId != Guid.Empty).Select(it => it.ItemId).ToList();   // get all the ids selected
            // Get all related ids
            List <WooProductMap> WooProductMaps = await GetWooMappedItemsAsync(_ItemAttribIds);

            // Map Items to Woo AttributeMap
            foreach (var entity in _Items)
            {
                //  map all the items across to the view then allocate extra woo stuff if exists.
                WooProductMap _wooProductMap = WooProductMaps.Where(wam => wam.ItemId == entity.ItemId).FirstOrDefault();    //  if retrieving / record await GetWooMappedItemAsync(itemCat.ItemId);

                _itemViewLookups.Add(new ItemView
                {
                    ItemId     = entity.ItemId,
                    ItemName   = entity.ItemName,
                    SKU        = entity.SKU,
                    IsEnabled  = entity.IsEnabled,
                    ItemDetail = entity.ItemDetail,
                    PrimaryItemCategoryLookupId = ((entity.PrimaryItemCategoryLookupId ?? Guid.Empty) == Guid.Empty) ? null : (Guid)entity.PrimaryItemCategoryLookupId,
                    ParentItemId        = ((entity.ParentItemId ?? Guid.Empty) == Guid.Empty) ? null : (Guid)entity.ParentItemId,
                    ReplacementItemId   = ((entity.ReplacementItemId ?? Guid.Empty) == Guid.Empty) ? null : (Guid)entity.ReplacementItemId,
                    ItemAbbreviatedName = entity.ItemAbbreviatedName,
                    ParentItem          = entity.ParentItem,
                    ReplacementItem     = entity.ReplacementItem,
                    ItemCategories      = entity.ItemCategories,
                    ItemAttributes      = entity.ItemAttributes,
                    ItemImages          = entity.ItemImages,
                    SortOrder           = entity.SortOrder,
                    BasePrice           = entity.BasePrice,
                    ManageStock         = entity.ManageStock,
                    QtyInStock          = entity.QtyInStock,
                    CanUpdateWooMap     = (_wooProductMap == null) ? null : _wooProductMap.CanUpdate
                });;
            }
            return(_itemViewLookups);
        }
Exemple #7
0
        public async Task HandleReadDataAsync(DataGridReadDataEventArgs <ItemAttributeLookupView> inputDataGridReadData)
        {
            if (IsLoading)
            {
                return;
            }
            IsLoading = true;
            //
            try
            {
                if (!inputDataGridReadData.CancellationToken.IsCancellationRequested)
                {
                    DataGridParameters _dataGridParameters = _AttributeWooLinkedViewRepository.GetDataGridCurrent(inputDataGridReadData, _GridSettings.CustomFilterValue);
                    if (_GridSettings.PageSize != inputDataGridReadData.PageSize)
                    {                                                                    /// page sized changed so jump back to original page
                        _GridSettings.CurrentPage = _dataGridParameters.CurrentPage = 1; // force this
                        _GridSettings.PageSize    = inputDataGridReadData.PageSize;
                        //                  await Reload();
                    }
                    await SetLoadStatus("Checking Woo status & loading Attributes");
                    await SetLoadStatus("Checking Woo status");

                    _GridSettings.WooIsActive = await _AttributeWooLinkedViewRepository.WooIsActiveAsync(_AppState);
                    await SetLoadStatus("Loading Attributes");
                    await LoadItemAttributeLookupList(_dataGridParameters);

                    _Status = string.Empty;
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError($"Error running async tasks: {ex.Message}");
                throw;
            }
            finally
            {
                IsLoading = false;
            }
        }
Exemple #8
0
        public override async Task <List <ItemCategoryLookupView> > LoadViewItemsPaginatedAsync(DataGridParameters currentDataGridParameters)
        {
            List <ItemCategoryLookup> _itemCategoryLookups = await GetPagedItemsAsync(currentDataGridParameters);

            List <ItemCategoryLookupView> _itemCategoryViewLookups = new List <ItemCategoryLookupView>();
            // Get a list of all the category maps that exists
            List <Guid> _itemCatIds = _itemCategoryLookups.Where(it => it.ItemCategoryLookupId != Guid.Empty).Select(it => it.ItemCategoryLookupId).ToList();   // get all the ids selected
            // Get all related ids
            List <WooCategoryMap> wooCategoryMaps = await GetWooMappedItemsAsync(_itemCatIds);

            // Map Items to Woo CategoryMap
            foreach (var itemCat in _itemCategoryLookups)
            {
                //  map all the items across to the view then allocate extra woo stuff if exists.
                WooCategoryMap _wooCategoryMap = wooCategoryMaps.Where(wcm => wcm.ItemCategoryLookupId == itemCat.ItemCategoryLookupId).FirstOrDefault();    //  if retrieving / record await GetWooMappedItemAsync(itemCat.ItemCategoryLookupId);

                _itemCategoryViewLookups.Add(new ItemCategoryLookupView
                {
                    ItemCategoryLookupId = itemCat.ItemCategoryLookupId,
                    CategoryName         = itemCat.CategoryName,
                    UsedForPrediction    = itemCat.UsedForPrediction,
                    ParentCategoryId     = itemCat.ParentCategoryId,
                    ParentCategory       = itemCat.ParentCategory,
                    Notes      = itemCat.Notes,
                    RowVersion = itemCat.RowVersion,

                    CanUpdateWooMap = (_wooCategoryMap == null) ? null : _wooCategoryMap.CanUpdate
                });
            }
            return(_itemCategoryViewLookups);
        }
        public async Task <DataGridItems <ItemAttributeLookup> > GetPagedDataEagerWithFilterAndOrderByAsync(DataGridParameters currentDataGridParameters) // (int startPage, int currentPageSize)
        {
            DataGridItems <ItemAttributeLookup> _dataGridData = null;
            DbSet <ItemAttributeLookup>         _table        = _Context.Set <ItemAttributeLookup>();

            try
            {
                _Logger.LogDebug($"Getting all records with eager loading of ItemAttributeLookup order by an filter Data Grid Parameters: {currentDataGridParameters.ToString()}");
                // get a list of Order bys and filters
                List <OrderByParameter <ItemAttributeLookup> >         _orderByExpressions  = GetOrderByExpressions(currentDataGridParameters.SortParams);
                List <Expression <Func <ItemAttributeLookup, bool> > > _filterByExpressions = GetFilterByExpressions(currentDataGridParameters.FilterParams);

                // start with a basic Linq Query with Eager loading
                IQueryable <ItemAttributeLookup> _query = _table.Include(ial => ial.ItemAttributeVarietyLookups.Take(AppUnitOfWork.CONST_MAX_DETAIL_PAGES));    //only take the first 50
                if ((_orderByExpressions != null) && (_orderByExpressions.Count > 0))
                {
                    // add order bys
                    if (_orderByExpressions.Count == 1)
                    {
                        _query = _orderByExpressions[0].IsAscending
                            ? _query.OrderBy(_orderByExpressions[0].OrderByExperssion)
                            : _query.OrderByDescending(_orderByExpressions[0].OrderByExperssion);
                    }
                    else   // we are only catering for one ThenBy, we could add more if else's here
                    {
                        _query = _orderByExpressions[0].IsAscending
                            ? (_orderByExpressions[1].IsAscending
                                ? _query.OrderBy(_orderByExpressions[0].OrderByExperssion).ThenBy(_orderByExpressions[1].OrderByExperssion)
                                : _query.OrderBy(_orderByExpressions[0].OrderByExperssion).ThenByDescending(_orderByExpressions[1].OrderByExperssion))
                            : (_orderByExpressions[1].IsAscending
                                ? _query.OrderByDescending(_orderByExpressions[0].OrderByExperssion).ThenBy(_orderByExpressions[1].OrderByExperssion)
                                : _query.OrderByDescending(_orderByExpressions[0].OrderByExperssion).ThenByDescending(_orderByExpressions[1].OrderByExperssion));
                    }
                }
                else   // default sort
                {
                    _query = _query.OrderBy(ial => ial.OrderBy);
                }

                //This is functionally comes from
                //https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/how-to-use-expression-trees-to-build-dynamic-queries
                //now the per column filters
                if (!String.IsNullOrEmpty(currentDataGridParameters.CustomFilter) || _filterByExpressions != null)
                {
                    Expression <Func <ItemAttributeLookup, bool> > _queryWhere = PredicateBuilder.New <ItemAttributeLookup>(true);
                    if (!String.IsNullOrEmpty(currentDataGridParameters.CustomFilter))
                    {
                        _queryWhere = _queryWhere.And(ial => ((ial.AttributeName.ToLower().Contains(currentDataGridParameters.CustomFilter)) ||
                                                              (ial.Notes.ToLower().Contains(currentDataGridParameters.CustomFilter))));
                    }
                    if (_filterByExpressions != null)
                    {
                        foreach (var flt in _filterByExpressions)
                        {
                            _queryWhere = _queryWhere.And(flt);
                        }
                    }
                    _query = _query.Where(_queryWhere);   //  (_queryWhere);
                }

                //now we can add the page stuff - first get the count to return
                _dataGridData = new DataGridItems <ItemAttributeLookup>();
                _dataGridData.TotalRecordCount = _query.Count();
                _query = _query
                         .Skip((currentDataGridParameters.CurrentPage - 1) * currentDataGridParameters.PageSize)
                         .Take(currentDataGridParameters.PageSize); // take 3 pages at least.
                // and execute
                _dataGridData.Entities = await _query.ToListAsync();
            }
            catch (Exception ex)
            {
                _AppUnitOfWork.LogAndSetErrorMessage($"!!!Error Getting all records from ItemAttributeLookupRepository: {ex.Message} - Inner Exception {ex.InnerException}");
#if DebugMode
                throw;     // #Debug?
#endif
            }
            return(_dataGridData);
        }
Exemple #10
0
        public override async Task <List <ItemAttributeLookupView> > LoadViewItemsPaginatedAsync(DataGridParameters currentDataGridParameters)
        {
            List <ItemAttributeLookup> _itemAttributeLookups = await GetPagedItemsAsync(currentDataGridParameters);

            List <ItemAttributeLookupView> _itemAttributeViewLookups = new List <ItemAttributeLookupView>();
            // Get a list of all the Attribute maps that exists
            List <Guid> _ItemAttribIds = _itemAttributeLookups.Where(it => it.ItemAttributeLookupId != Guid.Empty).Select(it => it.ItemAttributeLookupId).ToList();   // get all the ids selected
            // Get all related ids
            List <WooProductAttributeMap> WooProductAttributeMaps = await GetWooMappedItemsAsync(_ItemAttribIds);

            // Map Items to Woo AttributeMap
            foreach (var itemAttrib in _itemAttributeLookups)
            {
                //  map all the items across to the view then allocate extra woo stuff if exists.
                WooProductAttributeMap _wooProductAttributeMap = WooProductAttributeMaps.Where(wam => wam.ItemAttributeLookupId == itemAttrib.ItemAttributeLookupId).FirstOrDefault();    //  if retrieving / record await GetWooMappedItemAsync(itemCat.ItemAttributeLookupId);

                _itemAttributeViewLookups.Add(new ItemAttributeLookupView
                {
                    ItemAttributeLookupId       = itemAttrib.ItemAttributeLookupId,
                    AttributeName               = itemAttrib.AttributeName,
                    ItemAttributeVarietyLookups = itemAttrib.ItemAttributeVarietyLookups,
                    OrderBy = itemAttrib.OrderBy,
                    Notes   = itemAttrib.Notes,

                    CanUpdateWooMap = (_wooProductAttributeMap == null) ? null : _wooProductAttributeMap.CanUpdate
                });
            }
            return(_itemAttributeViewLookups);
        }
        public object SaveDataGridStatus(DataGridStatusDto oDataGridStatusDto)
        {
            SqlHelper sqlHelper = new SqlHelper(connectionString);

            try
            {
                sqlHelper.VerifyConnection();

                StringBuilder       DataGridInsert = new StringBuilder();
                List <SqlParameter> DataGridParameters;

                if (oDataGridStatusDto.Id > 0)
                {
                    DataGridParameters = new List <SqlParameter>
                    {
                        new SqlParameter("id", oDataGridStatusDto.Id),
                        new SqlParameter("pivot_mode", oDataGridStatusDto.PivotMode),
                        new SqlParameter("column_state", oDataGridStatusDto.ColumnState),
                        new SqlParameter("group_state", oDataGridStatusDto.GroupState),
                        new SqlParameter("sort_state", oDataGridStatusDto.SortState),
                        new SqlParameter("filter_state", oDataGridStatusDto.FilterState),
                        new SqlParameter("external_filter_state", oDataGridStatusDto.ExternalFilterState)
                    };

                    DataGridInsert = new StringBuilder($@"UPDATE [data_grid_layouts] 
                                                        SET [pivot_mode] = @pivot_mode,[column_state]= @column_state  
                                                        ,[group_state]  = @group_state ,[sort_state] = @sort_state
                                                        ,[filter_state] = @filter_state, [external_filter_state] = @external_filter_state
                                                        WHERE  id= @id; SELECT   @@ROWCOUNT;");
                }
                else
                {
                    DataGridParameters = new List <SqlParameter>
                    {
                        new SqlParameter("id", oDataGridStatusDto.Id),
                        new SqlParameter("gridId", oDataGridStatusDto.GridId),
                        new SqlParameter("grid_name", oDataGridStatusDto.GridName),
                        new SqlParameter("grid_layout_name", oDataGridStatusDto.GridLayoutName),
                        new SqlParameter("userId", oDataGridStatusDto.UserId),
                        new SqlParameter("pivot_mode", oDataGridStatusDto.PivotMode),
                        new SqlParameter("column_state", oDataGridStatusDto.ColumnState),
                        new SqlParameter("group_state", oDataGridStatusDto.GroupState),
                        new SqlParameter("sort_state", oDataGridStatusDto.SortState),
                        new SqlParameter("filter_state", oDataGridStatusDto.FilterState),
                        new SqlParameter("external_filter_state", oDataGridStatusDto.ExternalFilterState),
                        new SqlParameter("is_public", oDataGridStatusDto.IsPublic ? 1 : 0)
                    };
                    DataGridInsert = new StringBuilder($@"INSERT INTO [data_grid_layouts]
                                                        ([grid_name] 
                                                        ,[userId]  
                                                        ,[grid_id]
                                                        ,[pivot_mode]  
                                                        ,[column_state]  
                                                        ,[group_state]  
                                                        ,[sort_state] 
                                                        ,[filter_state]
                                                        ,[external_filter_state]
                                                        ,[grid_layout_name]
                                                        ,[is_public]
                                                         )
                                                        VALUES
                                                        (@grid_name
                                                         ,@userId
                                                        ,@gridId
                                                        ,@pivot_mode 
                                                        ,@column_state
                                                        ,@group_state
                                                        ,@sort_state
                                                        ,@filter_state
                                                        ,@external_filter_state
                                                        ,@grid_layout_name
                                                        ,@is_public);
                                                        SELECT SCOPE_IDENTITY() AS 'Identity'");
                }

                sqlHelper.Insert(DataGridInsert.ToString(), CommandType.Text, DataGridParameters.ToArray(),
                                 out int dataGridId);
                sqlHelper.CloseConnection();
            }
            catch (Exception ex)
            {
                sqlHelper.SqlRollbackTransaction();
                sqlHelper.CloseConnection();
                Console.WriteLine($"SQL Rollback Transaction Exception: {ex}");
                return(Utils.Wrap(false));
            }

            return(Utils.Wrap(true));
        }
Exemple #12
0
 public virtual Task <List <TEntityView> > LoadViewItemsPaginatedAsync(DataGridParameters currentDataGridParameters)
 {
     _Logger.LogError($"LoadViewItemsPaginatedAsync for Entity: {currentDataGridParameters.ToString()} not implemented, place holder executed. Please implement.");
     throw new NotImplementedException();
 }
Exemple #13
0
 public virtual Task <List <TEntity> > GetPagedItemsAsync(DataGridParameters currentDataGridParameters) // int startPage, int currentPageSize)
 {
     _Logger.LogError($"GetPagedItemsAsync for Entity: {currentDataGridParameters.ToString()} not implemented, place holder executed. Please implement.");
     throw new NotImplementedException();
 }
        public override async Task <List <ItemAttributeVarietyLookupView> > LoadViewItemsPaginatedAsync(DataGridParameters currentDataGridParameters)
        {
            if (_TaskIsBusy)
            {
                return(null);
            }

            _TaskIsBusy = true;

            List <ItemAttributeVarietyLookup> _itemAttributeVarietyLookups = await GetPagedItemsAsync(currentDataGridParameters);

            List <ItemAttributeVarietyLookupView> _itemAttributeVarietyViewLookups = new List <ItemAttributeVarietyLookupView>();
            // Get a list of all the AttributeVariety maps that exists
            List <Guid> _ItemAttributeVarietyIds = _itemAttributeVarietyLookups.Where(it => it.ItemAttributeVarietyLookupId != Guid.Empty).Select(it => it.ItemAttributeVarietyLookupId).ToList();   // get all the ids selected
            // Get all related ids
            List <WooProductAttributeTermMap> WooProductAttributeTermMaps = await GetWooMappedItemsAsync(_ItemAttributeVarietyIds);

            // now get all the Units of Measure as a lazy load
            List <Guid?>   _itemAttributeVarietyUomIds = _itemAttributeVarietyLookups.Where(it => (it.UoMId != null) && (it.UoMId != Guid.Empty)).Select(it => it.UoMId).Distinct().ToList(); // get all the ids selected should not return nulls
            List <ItemUoM> itemUoMs = await GetItemUoMsAsync(_itemAttributeVarietyUomIds);

            // Map Items to Woo AttributeVarietyMap
            foreach (var itemAttributeVariety in _itemAttributeVarietyLookups)
            {
                //  map all the items across to the view then allocate extra woo stuff if exists.
                WooProductAttributeTermMap _wooProductAttributeTermMap = WooProductAttributeTermMaps.Where(wam => wam.ItemAttributeVarietyLookupId == itemAttributeVariety.ItemAttributeVarietyLookupId).FirstOrDefault();    //  if retrieving / record await GetWooMappedItemAsync(itemCat.ItemAttributeVarietyLookupId);

                _itemAttributeVarietyViewLookups.Add(new ItemAttributeVarietyLookupView
                {
                    ItemAttributeVarietyLookupId = itemAttributeVariety.ItemAttributeVarietyLookupId,
                    ItemAttributeLookupId        = itemAttributeVariety.ItemAttributeLookupId,
                    VarietyName = itemAttributeVariety.VarietyName,
                    Symbol      = itemAttributeVariety.Symbol,
                    SortOrder   = itemAttributeVariety.SortOrder,
                    BGColour    = itemAttributeVariety.BGColour,
                    FGColour    = itemAttributeVariety.FGColour,
                    UoMId       = itemAttributeVariety.UoMId,
                    Notes       = itemAttributeVariety.Notes,
                    UoM         = (((itemAttributeVariety.UoMId ?? Guid.Empty) == Guid.Empty)) ? null
                            : itemUoMs?.Where(uid => uid.ItemUoMId == itemAttributeVariety.UoMId).FirstOrDefault(), // apply the "lazy" load to the item   /// : (itemUoMs == null) ? null : itemUoMs.Where(uid => uid.ItemUoMId == itemAttributeVariety.UoMId).FirstOrDefault(),
                    CanUpdateWooMap = _wooProductAttributeTermMap?.CanUpdate                                        //  (_wooProductAttributeTermMap == null) ? null : _wooProductAttributeTermMap.CanUpdate
                });
            }
            _TaskIsBusy = false;
            return(_itemAttributeVarietyViewLookups);
        }