Esempio n. 1
0
        public ActionResult Search(int page = 1)
        {
            // Create service instance
            IUcbService sc = UcbService;

            // Create model
            CustomerSearchVM model = new CustomerSearchVM();

            try
            {
                CustomerSearchVMDC response = sc.SearchCustomer(CurrentUser, CurrentUser, appID, "", null, page, PageSize);

                // Close service communication
                ((ICommunicationObject)sc).Close();

                //Map response back to view model
                model.MatchList = Mapper.Map <IEnumerable <CustomerSearchMatchDC>, List <CustomerSearchMatchModel> >(response.MatchList);

                // Set paging values
                model.TotalRows  = response.RecordCount;
                model.PageSize   = sessionManager.PageSize;
                model.PageNumber = page;

                // Store the page number we were on
                sessionManager.CustomerPageNumber = model.PageNumber;

                return(View(model));
            }
            catch (Exception e)
            {
                // Handle the exception
                string message = ExceptionManager.HandleException(e, (ICommunicationObject)sc);
                model.Message = message;

                return(View(model));
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="searchCriteria"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <param name="specification"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public CustomerSearchVMDC SearchCustomer(string currentUser, string user, string appID, string overrideID, CustomerSearchCriteriaDC searchCriteria, int page, int pageSize,
                                                 ISpecification <Customer> specification, IRepository <Customer> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == specification)
                {
                    throw new ArgumentOutOfRangeException("specification");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Evaluate search criteria if supplied
                    if (null != searchCriteria)
                    {
                        EvaluateSearchCriteria(searchCriteria, ref specification);
                    }

                    // Set default sort expression
                    System.Linq.Expressions.Expression <Func <Customer, Object> > sortExpression = x => new { x.Title };

                    // Find all items that satisfy the specification created above.
                    IEnumerable <Customer> dataEntities = dataRepository.Find(specification, sortExpression, page, pageSize);

                    // Get total count of items for search critera
                    int itemCount = dataRepository.Count(specification);

                    CustomerSearchVMDC results = new CustomerSearchVMDC();

                    // Convert to data contracts
                    List <CustomerSearchMatchDC> destinations = mappingService.Map <IEnumerable <Customer>, List <CustomerSearchMatchDC> >(dataEntities);

                    results.MatchList      = destinations;
                    results.SearchCriteria = searchCriteria;
                    results.RecordCount    = itemCount;

                    return(results);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }