예제 #1
0
        public ActionResult CategoriesSearch(string categoriesName)
        {
            categoriesName = categoriesName.Trim();

            var campCategList = _campCategService.GetAllCategories().ToList();
            var findCampCateg =
                campCategList.Find(x => x.Name.ToLower() == categoriesName.ToLower());
            var notFoundCateg = false;

            var culture = _workContextAccessor.GetContext().CurrentCulture.Trim();
            var cultureSearch = culture == "en-SG" ? "en-SG" : (culture == "id-ID" ? "id-ID" : "en-MY");

            if (findCampCateg != null)
            {
                var searchCampaignsRequest = new SearchCampaignsRequest
                {
                    Tag = categoriesName.ToLowerInvariant(),
                    Culture = cultureSearch,
                    Skip = 0,
                    Take = Take
                };

                var searchCampaignsResponse = _campService.SearchCampaignsForTag(searchCampaignsRequest);
                _searchCampaignItems = searchCampaignsResponse.Campaigns;

                campCategList.Remove(findCampCateg);
            }
            else
            {
                notFoundCateg = true;
            }

            var notResult = CheckResult();

            var price = PriceForCampaign(notResult);

            var searchViewModel = new SearchViewModel
            {
                NotResult = notResult,
                Filter = categoriesName,
                Campaigns = _searchCampaignItems,
                NewRow = 0,
                NotFoundCategories = notFoundCateg,
                CampCategList = campCategList,
                Price = price
            };

            return View(searchViewModel);
        }
예제 #2
0
        public ActionResult Search(string filter, int? page)
        {
            page = page ?? 0;
            var skip = (int) page*Take;

            filter = filter.Trim();

            var culture = _workContextAccessor.GetContext().CurrentCulture.Trim();
            var cultureSearch = culture == "en-SG" ? "en-SG" : (culture == "id-ID" ? "id-ID" : "en-MY");

            SearchCampaignsResponse searchCampaignsResponse;

            if (!string.IsNullOrEmpty(filter))
            {
                var searchCampaignsRequest = new SearchCampaignsRequest
                {
                    Filter = filter,
                    Culture = cultureSearch,
                    Skip = skip,
                    Take = Take
                };

                searchCampaignsResponse = _campService.SearchCampaignsForFilter(searchCampaignsRequest);
                _searchCampaignItems = searchCampaignsResponse.Campaigns;
            }
            else
            {
                var searchCampaignsRequest = new SearchCampaignsRequest
                {
                    Culture = cultureSearch,
                    Skip = skip,
                    Take = Take
                };

                searchCampaignsResponse = _campService.SearchCampaigns(searchCampaignsRequest);
                _searchCampaignItems = searchCampaignsResponse.Campaigns;
            }

            var notResult = CheckResult();

            var price = PriceForCampaign(notResult);

            if (Request.IsAjaxRequest())
            {
                var searchViewModel = new SearchViewModel
                {
                    NotResult = notResult,
                    Filter = filter,
                    Campaigns = _searchCampaignItems,
                    Price = price
                };

                return PartialView("_CustomerRow", searchViewModel);
            }
            else
            {
                var searchViewModel = new SearchViewModel
                {
                    NotResult = notResult,
                    Filter = filter,
                    Campaigns = _searchCampaignItems,
                    Price = price
                };

                return View(searchViewModel);
            }
        }
예제 #3
0
        public SearchCampaignsResponse SearchCampaignsForFilter(SearchCampaignsRequest request)
        {
            var response = new SearchCampaignsResponse();

            using (var connection = new SqlConnection(_shellSettings.DataConnectionString))
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    using (var command = connection.CreateCommand())
                    {
                        command.Transaction = transaction;
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "SearchCampaignsForFilter";

                        var currentDateParameter = new SqlParameter("@CurrentDate", SqlDbType.DateTime)
                        {
                            Value = DateTime.UtcNow
                        };
                        var cultureParameter = new SqlParameter("@Culture", SqlDbType.NVarChar, 50)
                        {
                            Value = request.Culture
                        };
                        var filterParameter = new SqlParameter("@Filter", SqlDbType.NVarChar, 4000)
                        {
                            Value = "%" + request.Filter + "%"
                        };
                        var skipParameter = new SqlParameter("@Skip", SqlDbType.Int)
                        {
                            Value = request.Skip
                        };
                        var takeParameter = new SqlParameter("@Take", SqlDbType.Int)
                        {
                            Value = request.Take
                        };

                        command.Parameters.Add(currentDateParameter);
                        command.Parameters.Add(cultureParameter);
                        command.Parameters.Add(filterParameter);
                        command.Parameters.Add(skipParameter);
                        command.Parameters.Add(takeParameter);

                        using (var reader = command.ExecuteReader())
                        {
                            response.Campaigns = GetSearchCampaignItemsFrom(reader);
                        }
                    }
                    
                    FillSearchCampaignItemsWithData(response.Campaigns, transaction);

                    transaction.Commit();
                }
            }
            return response;
        }