예제 #1
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 NarrativeSearchVMDC SearchNarrative(string currentUser, string user, string appID, string overrideID, NarrativeSearchCriteriaDC searchCriteria, int page, int pageSize,
                                                   ISpecification <Narrative> specification, IRepository <Narrative> 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 <Narrative, Object> > sortExpression = x => new { x.NarrativeType };

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

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

                    NarrativeSearchVMDC results = new NarrativeSearchVMDC();

                    // Convert to data contracts
                    List <NarrativeSearchMatchDC> destinations = mappingService.Map <IEnumerable <Narrative>, List <NarrativeSearchMatchDC> >(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);
            }
        }
예제 #2
0
 // Partial method for evaluation of search criteria
 partial void EvaluateSearchCriteria(NarrativeSearchCriteriaDC searchCriteria, ref ISpecification <Narrative> specification);
예제 #3
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>
        /// <returns></returns>
        public NarrativeSearchVMDC SearchNarrative(string currentUser, string user, string appID, string overrideID, NarrativeSearchCriteriaDC searchCriteria, int page, int pageSize)
        {
            // Create unit of work
            IUnitOfWork uow = new UnitOfWork(currentUser);

            // Create repository
            IRepository <Narrative> dataRepository = new Repository <Narrative>(uow.ObjectContext, currentUser, user, appID, overrideID);

            // Create specification for filtering
            ISpecification <Narrative> specification = new Specification <Narrative>();

            //Create ExceptionManager
            IExceptionManager exceptionManager = new ExceptionManager();

            //Create MappingService
            IMappingService mappingService = new MappingService();

            // Call overload with injected objects
            return(SearchNarrative(currentUser, user, appID, overrideID, searchCriteria, page, pageSize, specification, dataRepository, uow, exceptionManager, mappingService));
        }