public async Task <SearchDataDto> Paging([FromBody] SearchDataDto searchDataDto)
        {
            int page;

            switch (searchDataDto.Paging)
            {
            case "prev":
                page = searchDataDto.CurrentPage - 1;
                break;

            case "next":
                page = searchDataDto.CurrentPage + 1;
                break;

            default:
                page = int.Parse(searchDataDto.Paging);
                break;
            }

            int leftMostPage = searchDataDto.LeftMostPage;

            SearchData model = new SearchData
            {
                SearchText   = searchDataDto.SearchText,
                LeftMostPage = searchDataDto.LeftMostPage,
                PageCount    = searchDataDto.PageCount,
                PageRange    = searchDataDto.PageRange,
                Paging       = searchDataDto.Paging,
                CurrentPage  = searchDataDto.CurrentPage
            };

            await _searchProvider.QueryPagingFull(model, page, leftMostPage).ConfigureAwait(false);


            var results = new SearchDataDto
            {
                SearchText   = model.SearchText,
                LeftMostPage = model.LeftMostPage,
                PageCount    = model.PageCount,
                PageRange    = model.PageRange,
                Paging       = model.Paging,
                CurrentPage  = model.CurrentPage,
                Results      = new SearchResultItems
                {
                    PersonCities = new List <PersonCityDto>(),
                    TotalCount   = model.PersonCities.TotalCount.GetValueOrDefault()
                }
            };

            var docs = model.PersonCities.GetResults().ToList();

            foreach (var doc in docs)
            {
                results.Results.PersonCities.Add(new PersonCityDto
                {
                    CityCountry = doc.Document.CityCountry,
                    FamilyName  = doc.Document.FamilyName,
                    Github      = doc.Document.Github,
                    Id          = doc.Document.Id,
                    Info        = doc.Document.Info,
                    Metadata    = doc.Document.Metadata,
                    Mvp         = doc.Document.Mvp,
                    Name        = doc.Document.Name,
                    Twitter     = doc.Document.Twitter,
                    Web         = doc.Document.Web
                });
            }

            return(results);
        }
Esempio n. 2
0
        public SearchDataDto GetDataWithFilter(int userID, Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Notification notification)
        {
            totalRows         = 0;
            notification      = new Notification();
            notification.Type = NotificationType.Success;

            SearchDataDto data = new SearchDataDto();

            data.Data = new List <ShowroomDataDto>();
            data.ProductionItemWithDescriptions = new List <ProductionItemWithDescription>();

            try
            {
                string clientUD                 = (filters.ContainsKey("clientUD") && filters["clientUD"] != null) ? filters["clientUD"].ToString() : null;
                string productionItemUD         = (filters.ContainsKey("productionItemUD") && filters["productionItemUD"] != null) ? filters["productionItemUD"].ToString() : null;
                string productionItemNM         = (filters.ContainsKey("productionItemNM") && filters["productionItemNM"] != null) ? filters["productionItemNM"].ToString() : null;
                string factoryUD                = (filters.ContainsKey("factoryUD") && filters["factoryUD"] != null) ? filters["factoryUD"].ToString() : null;
                string factoryWarehouses        = (filters.ContainsKey("listFactoryWarehouse") && filters["listFactoryWarehouse"] != null) ? filters["listFactoryWarehouse"].ToString() : null;
                string factoryWarehousePalletUD = (filters.ContainsKey("factoryWarehousePalletUD") && filters["factoryWarehousePalletUD"] != null) ? filters["factoryWarehousePalletUD"].ToString() : null;
                string season = (filters.ContainsKey("season") && filters["season"] != null) ? filters["season"].ToString() : null;

                int?companyID = fwFactory.GetCompanyID(userID);

                using (var context = CreateContext())
                {
                    if (companyID.HasValue) // Only Eurofar, An Viet Thinh And OrangePine
                    {
                        if (companyID.Value == 3 || companyID.Value == 4 || companyID.Value == 13)
                        {
                            totalRows  = context.ShowroomRpt_function_ShowroomSearchResult(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, factoryWarehousePalletUD, season, orderBy, orderDirection).Count();
                            data.Data1 = converter.DB2DTO_Showroom2Rpt(context.ShowroomRpt_function_ShowroomSearchResult(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, factoryWarehousePalletUD, season, orderBy, orderDirection).ToList());
                            data.Data  = converter.DB2DTO_Showroom2Rpt(context.ShowroomRpt_function_ShowroomSearchResult(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, factoryWarehousePalletUD, season, orderBy, orderDirection).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                            data.ProductionItemWithDescriptions = converter.DB2DTO_ProductionItemWithDescription(context.ShowroomRpt_function_ProductionItemWithDescription(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, orderBy, orderDirection).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                            data.TotalQuantity = 0;
                            for (int i = 0; i < data.Data1.Count; i++)
                            {
                                if (data.Data1[i].WarehouseQuantity != null)
                                {
                                    data.TotalQuantity += data.Data1[i].WarehouseQuantity;
                                }
                            }
                        }

                        if (companyID.Value == 1)
                        {
                            if (string.IsNullOrEmpty(factoryWarehouses))
                            {
                                factoryWarehouses = "39,41"; // SPOGA WAREHOUSE AND SEAL SAMPLE WAREHOUSE
                            }

                            totalRows  = context.ShowroomRpt_function_ShowroomSearchResult(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, factoryWarehousePalletUD, season, orderBy, orderDirection).Count();
                            data.Data1 = converter.DB2DTO_Showroom2Rpt(context.ShowroomRpt_function_ShowroomSearchResult(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, factoryWarehousePalletUD, season, orderBy, orderDirection).ToList());
                            data.Data  = converter.DB2DTO_Showroom2Rpt(context.ShowroomRpt_function_ShowroomSearchResult(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, factoryWarehousePalletUD, season, orderBy, orderDirection).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                            data.ProductionItemWithDescriptions = converter.DB2DTO_ProductionItemWithDescription(context.ShowroomRpt_function_ProductionItemWithDescription(userID, companyID, clientUD, productionItemUD, productionItemNM, factoryUD, factoryWarehouses, orderBy, orderDirection).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                            data.TotalQuantity = 0;
                            for (int i = 0; i < data.Data1.Count; i++)
                            {
                                if (data.Data1[i].WarehouseQuantity != null)
                                {
                                    data.TotalQuantity += data.Data1[i].WarehouseQuantity;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }

            return(data);
        }