private WEXStockOverviewRptEntities CreateContext()
        {
            var context = new WEXStockOverviewRptEntities(Library.Helper.CreateEntityConnectionString("DAL.WEXStockOverviewRptModel"));

            context.Database.CommandTimeout = 180;
            return(context);
        }
        public DTO.SearchFormData GetDataWithFilter(int userId, System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <DTO.ProductSearchResultDTO>();
            totalRows = 0;

            //try to get data
            try
            {
                using (WEXStockOverviewRptEntities context = CreateContext())
                {
                    string ArticleCode   = null;
                    string SubEANCode    = null;
                    string Description   = null;
                    string ProductTypeNM = null;
                    bool?  NoImage       = false;
                    int?   ItemSourceID  = null;

                    if (filters.ContainsKey("ArticleCode") && !string.IsNullOrEmpty(filters["ArticleCode"].ToString()))
                    {
                        ArticleCode = filters["ArticleCode"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("SubEANCode") && !string.IsNullOrEmpty(filters["SubEANCode"].ToString()))
                    {
                        SubEANCode = filters["SubEANCode"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("Description") && !string.IsNullOrEmpty(filters["Description"].ToString()))
                    {
                        Description = filters["Description"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("ProductTypeNM") && !string.IsNullOrEmpty(filters["ProductTypeNM"].ToString()))
                    {
                        ProductTypeNM = filters["ProductTypeNM"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("NoImage") && filters["NoImage"] != null && !string.IsNullOrEmpty(filters["NoImage"].ToString()))
                    {
                        NoImage = (filters["NoImage"].ToString() == "true") ? true : false;
                    }
                    if (filters.ContainsKey("ItemSourceID") && filters["ItemSourceID"] != null && !string.IsNullOrEmpty(filters["ItemSourceID"].ToString()))
                    {
                        ItemSourceID = Convert.ToInt32(filters["ItemSourceID"]);
                    }
                    totalRows = context.WEXStockOverviewRpt_function_SearchProduct(ArticleCode, SubEANCode, Description, ProductTypeNM, NoImage, ItemSourceID, orderBy, orderDirection).Count();
                    var result = context.WEXStockOverviewRpt_function_SearchProduct(ArticleCode, SubEANCode, Description, ProductTypeNM, NoImage, ItemSourceID, orderBy, orderDirection);
                    //data.Data = converter.DB2DTO_ProductSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                    data.Data = converter.DB2DTO_ProductSearchResultList(result.ToList());
                    if (!fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_WEX_VVP))
                    {
                        data.Data.ForEach(o => o.VVPPrice = null);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }