예제 #1
0
        /// <summary>
        /// Inserts a search log item
        /// </summary>
        /// <param name="SearchTerm">The search term</param>
        /// <param name="CustomerID">The customer identifier</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <returns>Search log item</returns>
        public static SearchLog InsertSearchLog(string SearchTerm, int CustomerID, DateTime CreatedOn)
        {
            CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn);

            DBSearchLog dbItem = DBProviderManager <DBSearchLogProvider> .Provider.InsertSearchLog(SearchTerm, CustomerID, CreatedOn);

            SearchLog item = DBMapping(dbItem);

            return(item);
        }
예제 #2
0
        private static SearchLog DBMapping(DBSearchLog dbItem)
        {
            if (dbItem == null)
                return null;

            SearchLog item = new SearchLog();
            item.SearchLogID = dbItem.SearchLogID;
            item.SearchTerm = dbItem.SearchTerm;
            item.CustomerID = dbItem.CustomerID;
            item.CreatedOn = dbItem.CreatedOn;

            return item;
        }
예제 #3
0
        /// <summary>
        /// Gets a search log item
        /// </summary>
        /// <param name="SearchLogID">The search log item identifier</param>
        /// <returns>Search log item</returns>
        public static SearchLog GetSearchLogByID(int SearchLogID)
        {
            if (SearchLogID == 0)
            {
                return(null);
            }

            DBSearchLog dbItem = DBProviderManager <DBSearchLogProvider> .Provider.GetSearchLogByID(SearchLogID);

            SearchLog item = DBMapping(dbItem);

            return(item);
        }
예제 #4
0
        /// <summary>
        /// Inserts a search log item
        /// </summary>
        /// <param name="searchLog">Search log item</param>
        public void InsertSearchLog(SearchLog searchLog)
        {
            if (searchLog == null)
            {
                throw new ArgumentNullException("searchLog");
            }

            searchLog.SearchTerm = CommonHelper.EnsureNotNull(searchLog.SearchTerm);
            searchLog.SearchTerm = CommonHelper.EnsureMaximumLength(searchLog.SearchTerm, 100);



            _context.SearchLog.AddObject(searchLog);
            _context.SaveChanges();
        }
예제 #5
0
        private static SearchLog DBMapping(DBSearchLog dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            SearchLog item = new SearchLog();

            item.SearchLogID = dbItem.SearchLogID;
            item.SearchTerm  = dbItem.SearchTerm;
            item.CustomerID  = dbItem.CustomerID;
            item.CreatedOn   = dbItem.CreatedOn;

            return(item);
        }
예제 #6
0
        private static SearchLogCollection DBMapping(DBSearchLogCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            SearchLogCollection collection = new SearchLogCollection();

            foreach (DBSearchLog dbItem in dbCollection)
            {
                SearchLog item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
예제 #7
0
        /// <summary>
        /// Inserts a search log item
        /// </summary>
        /// <param name="searchLog">Search log item</param>
        public void InsertSearchLog(SearchLog searchLog)
        {
            if (searchLog == null)
                throw new ArgumentNullException("searchLog");

            searchLog.SearchTerm = CommonHelper.EnsureNotNull(searchLog.SearchTerm);
            searchLog.SearchTerm = CommonHelper.EnsureMaximumLength(searchLog.SearchTerm, 100);

            _context.SearchLog.AddObject(searchLog);
            _context.SaveChanges();
        }
        protected void BindData()
        {
            try
            {
                string keywords = txtSearchTerm.Text.Trim();
                pagerProducts.PageSize = this.ProductService.SearchPageProductsPerPage;

                if (!String.IsNullOrEmpty(keywords))
                {
                    int searchTermMinimumLength = this.SettingManager.GetSettingValueInteger("Search.ProductSearchTermMinimumLength", 3);
                    if (keywords.Length < searchTermMinimumLength)
                        throw new NopException(string.Format(GetLocaleResourceString("Search.SearchTermMinimumLengthIsNCharacters"), searchTermMinimumLength));

                    bool advSearch = cbAdvancedSearch.Checked;
                    int categoryId = 0;
                    int manufacturerId = 0;
                    decimal? minPriceConverted = null;
                    decimal? maxPriceConverted = null;
                    bool searchInProductDescriptions = false;
                    if (advSearch)
                    {
                        //categories
                        if (ddlCategories.Items.Count > 0)
                            categoryId = int.Parse(this.ddlCategories.SelectedItem.Value);

                        //manufacturers
                        if (ddlManufacturers.Items.Count > 0)
                            manufacturerId = int.Parse(this.ddlManufacturers.SelectedItem.Value);

                        //min price
                        decimal? minPrice = null;
                        try
                        {
                            if (!string.IsNullOrEmpty(txtPriceFrom.Text.Trim()))
                            {
                                minPrice = decimal.Parse(txtPriceFrom.Text.Trim());
                                if (minPrice.HasValue)
                                {
                                    minPriceConverted = this.CurrencyService.ConvertCurrency(minPrice.Value, NopContext.Current.WorkingCurrency, this.CurrencyService.PrimaryStoreCurrency);
                                }
                            }
                        }
                        catch
                        {
                            txtPriceFrom.Text = string.Empty;
                        }

                        //max price
                        decimal? maxPrice = null;
                        try
                        {
                            if (!string.IsNullOrEmpty(txtPriceTo.Text.Trim()))
                            {
                                maxPrice = decimal.Parse(txtPriceTo.Text.Trim());
                                if (maxPrice.HasValue)
                                {
                                    maxPriceConverted = this.CurrencyService.ConvertCurrency(maxPrice.Value, NopContext.Current.WorkingCurrency, this.CurrencyService.PrimaryStoreCurrency);
                                }
                            }
                        }
                        catch
                        {
                            txtPriceTo.Text = string.Empty;
                        }

                        //search in descriptions
                        searchInProductDescriptions = cbSearchInProductDescriptions.Checked;
                    }

                    int totalRecords = 0;
                    var products = this.ProductService.GetAllProducts(categoryId,
                        manufacturerId, 0, 0, null,
                        minPriceConverted, maxPriceConverted,
                        keywords, searchInProductDescriptions,
                        100, 0, new List<int>(), out totalRecords);

                    lvProducts.DataSource = products;
                    lvProducts.DataBind();
                    lvProducts.Visible = products.Count > 0;
                    pagerProducts.Visible = products.Count > pagerProducts.PageSize;
                    lblNoResults.Visible = !lvProducts.Visible;

                    int customerId = 0;
                    if (NopContext.Current.User != null)
                        customerId = NopContext.Current.User.CustomerId;

                    var searchLog = new SearchLog()
                    {
                        SearchTerm = txtSearchTerm.Text.Trim(),
                        CustomerId = customerId,
                        CreatedOn = DateTime.UtcNow
                    };

                    this.SearchLogService.InsertSearchLog(searchLog);
                }
                else
                {
                    pagerProducts.Visible = false;
                    lvProducts.Visible = false;
                }
            }
            catch (Exception exc)
            {
                lvProducts.Visible = false;
                pagerProducts.Visible = false;
                lblError.Text = Server.HtmlEncode(exc.Message);
            }
        }