Beispiel #1
0
        public async Task <IActionResult> Search(DistributorSearchViewModel distributorSearchModel)
        {
            List <DistributorServiceModel> distributorsFoundService = await this.distributorService.SearchDistributor(distributorSearchModel).ToListAsync();

            List <DistributorViewModel> distributorsFound = distributorsFoundService
                                                            .Select(d => d.To <DistributorViewModel>()).ToList();
            List <DistributorViewModel> distributorsFoundPage = distributorsFound.Skip((distributorSearchModel.CurrentPage - 1) * distributorSearchModel.PageSize).Take(distributorSearchModel.PageSize).ToList();

            distributorSearchModel.Count             = distributorsFound.Count;
            distributorSearchModel.DistributorsFound = distributorsFoundPage;
            return(this.View(distributorSearchModel));
        }
Beispiel #2
0
        public async Task SearchPerson_ByNoCriteria_ShouldReturnAllDistributors()
        {
            string errorMessagePrefix = "DistributorService SearchDistributor(DistributorSearchViewModel) method does not work properly.";

            var context = HealthInsDbContextInMemoryFactory.InitializeContext();

            this.distributorService = new DistributorService(context);

            await SeedData(context);

            DistributorSearchViewModel distributorSearchViewModel = new DistributorSearchViewModel()
            {
            };
            var actualResults = this.distributorService.SearchDistributor(distributorSearchViewModel);

            Assert.True(actualResults.Count() == 2, errorMessagePrefix);
        }
        public IQueryable <DistributorServiceModel> SearchDistributor(DistributorSearchViewModel distributorSearchModel)
        {
            string searchBy       = distributorSearchModel.SearchBy;
            string referenceIdStr = distributorSearchModel.ReferenceId;

            if (referenceIdStr == null || referenceIdStr.Equals(""))
            {
                return(this.context.Distributors.To <DistributorServiceModel>());
            }
            switch (searchBy)
            {
            case "userName": return(this.context.Distributors.Include(d => d.User).Where(d => d.User.UserName == referenceIdStr).To <DistributorServiceModel>());

            case "organizationId": long.TryParse(distributorSearchModel.ReferenceId, out long referenceId); return(this.context.Distributors.Include(d => d.Organization).Where(d => d.Organization.Id == referenceId).To <DistributorServiceModel>());

            default: long.TryParse(distributorSearchModel.ReferenceId, out referenceId); return(this.context.Distributors.Where(d => d.Id == referenceId).To <DistributorServiceModel>());
            }
        }
Beispiel #4
0
        public async Task SearchPerson_ByUserName_ShouldReturnResults()
        {
            string errorMessagePrefix = "DistributorService SearchDistributor(DistributorSearchViewModel) method does not work properly.";

            var context = HealthInsDbContextInMemoryFactory.InitializeContext();

            this.distributorService = new DistributorService(context);

            await SeedData(context);

            DistributorSearchViewModel distributorSearchViewModel = new DistributorSearchViewModel()
            {
                ReferenceId = "user1",
                SearchBy    = "userName"
            };
            var actualResults = this.distributorService.SearchDistributor(distributorSearchViewModel);

            Assert.True(actualResults.FirstOrDefault().Id == 12, errorMessagePrefix);
        }