public ActionResult Search(int page = 1)
        {
            // Create service instance
            AdminServiceClient sc = new AdminServiceClient();

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

            try
            {
                #region Setup search citeria

                //Create search criteria data conatract
                StaffSearchCriteriaDC searchCriteriaDC = Mapper.Map <StaffSearchCriteriaDC>(model.SearchCriteria);

                #endregion

                // Call service
                StaffSearchVMDC response = sc.SearchStaff(CurrentUser, CurrentUser, appID, "", searchCriteriaDC, page, PageSize, true);

                // Close service communication
                sc.Close();

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

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

                // Store the page number we were on
                SessionManager.StaffPageNumber = model.PageNumber;

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

                return(View(model));
            }
        }
        public ActionResult SearchPost(StaffSearchVM model, int page = 1)
        {
            // Create service instance
            AdminServiceClient sc = new AdminServiceClient();

            #region Setup search citeria

            //Repopulate search criteria if already entered
            if (null == model.SearchCriteria && SessionManager.StaffSearchCritera != null)
            {
                model.SearchCriteria = SessionManager.StaffSearchCritera;
            }

            //Save search criteria to session
            SessionManager.StaffSearchCritera = model.SearchCriteria;

            //Create search criteria data conatract
            StaffSearchCriteriaDC searchCriteriaDC = Mapper.Map <StaffSearchCriteriaDC>(model.SearchCriteria);

            #endregion

            // Call service
            StaffSearchVMDC response = sc.SearchStaff(CurrentUser, CurrentUser, appID, "", searchCriteriaDC, page, PageSize, true);

            // Close service communication
            sc.Close();

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

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

            // Store the page number we were on
            SessionManager.StaffPageNumber = model.PageNumber;

            return(View(model));
        }
Beispiel #3
0
        public ActionResult Search(int page = 1)
        {
            // Create service instance
            IUcbService sc = UcbService;

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

            try
            {
                StaffSearchVMDC response = sc.SearchStaff(CurrentUser, CurrentUser, appID, "", null, page, PageSize, true);

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

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

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

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

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

                return(View(model));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Search for Staff items
        /// </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="includeInActive"></param>
        /// <param name="specification"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public StaffSearchVMDC SearchStaff(string currentUser, string user, string appID, string overrideID, StaffSearchCriteriaDC searchCriteria, int page, int pageSize, bool includeInActive,
                                           ISpecification <Staff> specification, ISpecification <Staff> isActiveSpecification, IRepository <Staff> 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)
                    {
                        EvaluateStaffSearchCriteria(searchCriteria, ref specification);
                    }

                    if (!includeInActive)
                    {
                        specification = specification.And(isActiveSpecification);
                    }

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

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

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

                    StaffSearchVMDC results = new StaffSearchVMDC();

                    // Convert to data contracts
                    List <StaffSearchMatchDC> destinations = mappingService.Map <IEnumerable <Staff>, List <StaffSearchMatchDC> >(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);
            }
        }