Ejemplo n.º 1
0
        /// <summary>
        /// Searches items by barcode/description and the selected store.
        /// </summary>
        /// <param name="e">An instance of ItemSearchTerms passed as parameters</param>
        /// <returns></returns>
        public ItemSearchResultModel SearchItem(ItemSearchTerms e)
        {
            switch (e.searchBy)
            {
            case SearchBy.Barcode:
                return(SearchByBarcodeAndStore(e));

            case SearchBy.Description:
                return(SearchByDescriptionAndStore(e));

            default:
                throw new ArgumentOutOfRangeException("please pass in a barcode or item description for searching");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Search for item price data by description and store
        /// </summary>
        /// <param name="e">Input data for search</param>
        /// <returns></returns>
        private ItemSearchResultModel SearchByDescriptionAndStore(ItemSearchTerms e)
        {
            ItemSearchResultModel SearhResult;
            var descriptionsParameters = new { Description = e.Item.Description, StoreId = e.Store.Id };

            using (IDbConnection cnx = new SqlConnection(CnxString))
            {
                SearhResult = cnx.Query <ItemSearchResultModel>("usp_SearchItemByDescriptionAndStore", descriptionsParameters,
                                                                commandType: CommandType.StoredProcedure).FirstOrDefault();
            }
            if (SearhResult == null)
            {
                SearhResult = new ItemSearchResultModel {
                    ErrorMessage = "Item does not exist in the specified store."
                };
            }
            return(SearhResult);
        }