Ejemplo n.º 1
0
        public void Map_CacheTest_ReturnMappedObject()
        {
            IMapper mapper = new DtoMapper();

            mapper.Map <Source, Destination>(SourceToTest);

            Destination actualDestination = mapper.Map <Source, Destination>(SourceToTest);

            Assert.Equal(ExpectedDestination, actualDestination);
        }
Ejemplo n.º 2
0
        public void Map_MappingUsingCache()
        {
            IMapper mapper = new DtoMapper();

            mapper.Map <Source, Destination>(Source); //create cache for "Source -> Destination" pair

            Destination actual = mapper.Map <Source, Destination>(Source);

            Assert.Equal(ExpectedWithoutConfiguration, actual);
        }
Ejemplo n.º 3
0
        public IEnumerable <DoctorDto> GetAllDoctors(string filterString)
        {
            var doctorEntities = doctorRepository.GetDoctors();

            if (!string.IsNullOrEmpty(filterString))
            {
                doctorEntities = doctorEntities.Where(x => x.FirstName.Contains(filterString) || x.LastName.Contains(filterString));
            }

            return(mapper.Map(doctorEntities));
        }
Ejemplo n.º 4
0
 public void SetUp()
 {
     DtoMapper mapper = new DtoMapper(new LinkProvider());
      m_order = new Order();
      m_order.Cancel("You are too slow.");
      m_dto = mapper.Map<Order, OrderDto>(m_order);
 }
Ejemplo n.º 5
0
            // Converts order DTOs to VMs
            static IEnumerable <OrderVm> GetExpectedOrders(IEnumerable <OrderDto> orders)
            {
                var dtoMapper = new DtoMapper();
                var vmMapper  = new VmMapper();

                return(orders.Select(order => vmMapper.Map(dtoMapper.Map(order, null))));
            }
Ejemplo n.º 6
0
 public void SetUp()
 {
     var mapper = new DtoMapper(new LinkProvider());
      m_order = new Order();
      m_order.Pay("123", "jose");
      m_dto = mapper.Map<Order, OrderDto>(m_order);
 }
Ejemplo n.º 7
0
        public void SetUp()
        {
            var mapper = new DtoMapper(new LinkProvider());

            m_order = new Order();
            m_dto   = mapper.Map <Order, OrderDto>(m_order);
        }
Ejemplo n.º 8
0
        public void Map_SimpleMapping()
        {
            IMapper mapper = new DtoMapper();

            Destination actual = mapper.Map <Source, Destination>(Source);

            Assert.Equal(ExpectedWithoutConfiguration, actual);
        }
Ejemplo n.º 9
0
        public async Task AddCoordinateToList(int coordinateListId, Coordinate coordinate)
        {
            coordinate.CoordinateListId = coordinateListId;
            CoordinateDto coordinateDto = DtoMapper.Map(coordinate);

            Coordinates.Add(coordinateDto);
            await SaveChangesAsync().ConfigureAwait(false);
        }
Ejemplo n.º 10
0
        public void SetUp()
        {
            DtoMapper mapper = new DtoMapper(new LinkProvider());

            m_order = new Order();
            m_order.Cancel("You are too slow.");
            m_dto = mapper.Map <Order, OrderDto>(m_order);
        }
Ejemplo n.º 11
0
        public void SetUp()
        {
            var mapper = new DtoMapper(new LinkProvider());

            m_order = new Order();
            m_order.Pay("123", "jose");
            m_order.Finish();
            m_dto = mapper.Map <Order, OrderDto>(m_order);
        }
Ejemplo n.º 12
0
        public void Save(TodoListAggregate listEntity)
        {
            var listDto        = new TodoListDto();
            var resultItemList = new List <TodoListItemDto>();

            DtoMapper.Map(listEntity, listDto);
            using (var c = _sqlConnectionProvider.GetConnection())
            {
                using (var tran = c.BeginTransaction())
                {
                    try
                    {
                        if (listEntity.Key == 0)
                        {
                            const string insertTodoListSql = "INSERT INTO [TodoList]([ListId],[Name]) OUTPUT INSERTED.[Id] VALUES(@listId, @name)";
                            listDto.Id = c.QuerySingle <int>(insertTodoListSql, new { listId = listDto.ListId, name = listDto.Name }, tran);
                        }
                        else
                        {
                            //const string insertTodoListSql = "UPDATE [TodoList]([Name]) VALUES(@Name)";
                            c.Update(listDto, tran);
                        }

                        //remove deleted items
                        const string deleteRemovedSql = "DELETE FROM [TodoItem] WHERE [TodoList_Id] = @listId AND Id NOT IN @ids";
                        c.Execute(deleteRemovedSql, new { listId = listDto.Id, ids = listEntity.Items.Select(e => e.Key) }, tran);

                        foreach (var itemEntity in listEntity.Items)
                        {
                            var dto = new TodoListItemDto();
                            DtoMapper.Map(listDto.Id, itemEntity, dto);

                            if (itemEntity.Key == 0)
                            {
                                dto.Id = (int)c.Insert(dto, tran);
                            }
                            else if (itemEntity.Key > 0)
                            {
                                c.Update(dto, tran);
                            }

                            resultItemList.Add(dto);
                        }

                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void Map_NullParameter_ArgumentNullExceptionThrown()
        {
            // arrange
            IMapper mapper = new DtoMapper();

            // act
            Func <object> act = () => mapper.Map <Source, Destination>(null);

            // assert
            Assert.Throws <ArgumentNullException>(act);
        }
Ejemplo n.º 14
0
        public void Map_MappingUsingConfiguration()
        {
            MapperConfiguration mapperConfiguration = new MapperConfiguration();

            mapperConfiguration.Register <Source, Destination, string>(source => source.Name, destination => destination.FirstName)
            .Register <Source, Destination, long>(source => source.OneNumberCanConvert, destination => destination.AnotherNumberCanConvert);
            IMapper mapper = new DtoMapper(mapperConfiguration);

            Destination actual = mapper.Map <Source, Destination>(Source);

            Assert.Equal(ExpectedWithConfiguration, actual);
        }
Ejemplo n.º 15
0
        public void Map_CacheMiss_GetCacheForDidNotCalled_CreateMappingFunctionCalled()
        {
            var mockCache = new Mock <IMappingFunctionsCache>();

            mockCache.Setup(cache => cache.HasCacheFor(It.IsAny <MappingTypesPair>())).Returns(false);
            Mock <IMappingFunctionsFactory> mockFactory = CreateFakeMappingFunctionsFactory();
            IMapper mapper = new DtoMapper(mockCache.Object, mockFactory.Object);

            mapper.Map <object, object>(new object());

            mockCache.Verify(cache => cache.GetCacheFor <object, object>(It.IsAny <MappingTypesPair>()), Times.Never);
            mockFactory.Verify(factory => factory.CreateMappingFunction <object, object>(It.IsAny <List <MappingPropertiesPair> >()), Times.Once);
        }
Ejemplo n.º 16
0
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            DtoMapper.Map();
            InitializeIocContainer.Initialize();
            var permissionManager = IocHelper.Resolve <IPermissionManager>();

            permissionManager.Initialize();
        }
Ejemplo n.º 17
0
        private void OnAddConsultationRequest()
        {
            var success = _backendRequestHandler.Handle(DtoMapper.Map(_viewModel));

            if (success)
            {
                _onConsultationAdded.CallIfNotNull();
                _window.Close();
            }
            else
            {
                MessageDialog.CreateNotification("Konsultation konnte nicht angelegt werden",
                                                 "Bitte geben Sie ggf. einen anderen Verfügbarkeitszeitraum an", "x.smartplan").Show(_window);
            }
        }
Ejemplo n.º 18
0
        public async Task <CoordinateList> CreateCoordinateList(List <Coordinate> coordinates)
        {
            CoordinateListDto coordinateListDto = new CoordinateListDto();

            CoordinateLists.Add(coordinateListDto);
            await SaveChangesAsync().ConfigureAwait(false);

            coordinates.ForEach(x => x.CoordinateListId = coordinateListDto.Id);
            List <CoordinateDto> coordinateDtos = coordinates.Select(DtoMapper.Map).ToList();

            Coordinates.AddRange(coordinateDtos);
            await SaveChangesAsync().ConfigureAwait(false);

            CoordinateList createdCoordinateList = DtoMapper.Map(coordinateListDto, coordinateDtos);

            return(createdCoordinateList);
        }
Ejemplo n.º 19
0
        public async Task <CoordinateList> GetCoordinateList(int coordinateListId)
        {
            CoordinateListDto coordinateListDto = await CoordinateLists
                                                  .AsQueryable()
                                                  .FirstOrDefaultAsync(x => x.Id == coordinateListId)
                                                  .ConfigureAwait(false);

            List <CoordinateDto> coordinateDtos = await Coordinates
                                                  .AsQueryable()
                                                  .Where(x => x.CoordinateListId == coordinateListId)
                                                  .ToListAsync()
                                                  .ConfigureAwait(false);

            CoordinateList coordinateList = DtoMapper.Map(coordinateListDto, coordinateDtos);

            return(coordinateList);
        }
Ejemplo n.º 20
0
        public void Map_NoCache_CheckCacheNotCalled()
        {
            Mock <IFunctionsCache> cacheMock = new Mock <IFunctionsCache>();

            cacheMock.Setup(cache => cache.Contains(It.IsAny <MappingTypeAssociation>())).Returns(false);

            Mock <IFunctionBuilder> builderMock = new Mock <IFunctionBuilder>();

            builderMock.Setup(builder => builder.Build <object, object>(
                                  It.IsAny <List <MappingProperty> >())).Returns(o => o);

            IMapper mapper = new DtoMapper(builderMock.Object, cacheMock.Object);

            mapper.Map <object, object>(new object());

            cacheMock.Verify(cache => cache.Get <object, object>(It.IsAny <MappingTypeAssociation>()), Times.Never);
            builderMock.Verify(builder => builder.Build <object, object>(It.IsAny <List <MappingProperty> >()), Times.Once);
        }
Ejemplo n.º 21
0
        public async Task <IReview> Update(int id, bool needUpdateText, string text, float?rate, bool?isVisible)
        {
            using (var provider = ContextProviderFactory.Create())
            {
                var reviews =
                    provider.GetTable <Review>()
                    .Where(t => t.Id == id);

                if (!reviews.Any())
                {
                    throw new InvalidOperationException($"No review with id = {id}");
                }

                if (reviews.Count() > 1)
                {
                    throw new InvalidOperationException($"По идентификатор найдено более 1 соответствия");
                }

                var review =
                    reviews.First();

                var res =
                    await provider.GetTable <Review>()
                    .Where(t => t.Id == id)
                    .UpdateAsync(t => new Review()
                {
                    IsVisible  = isVisible ?? t.IsVisible,
                    Text       = needUpdateText ? text : t.Text,
                    Rate       = rate ?? t.Rate,
                    UpdateDate = DateTime.Now
                });


                return(DtoMapper.Map <IReview>(review));
            }
        }
Ejemplo n.º 22
0
        public async Task <PagingResult <IAttractionWithLinks> > CustomFilter(int page,
                                                                              int pageSize,
                                                                              string name,
                                                                              int?cityId,
                                                                              int?districtId,
                                                                              int[] subjectIds,
                                                                              bool subjectsAtLeastOne,
                                                                              int[] placeTypeIds,
                                                                              bool placeTypesAtLeastOne,
                                                                              OrderModel orderModel)
        {
            using (var cp = _contextProviderFactory.Create())
            {
                var attrs =
                    cp.GetTable <Attraction>();

                if (cityId != null)
                {
                    attrs =
                        attrs.Where(w => w.CityId == cityId);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    attrs =
                        attrs.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.OrdinalIgnoreCase));
                }

                if (districtId != null)
                {
                    attrs =
                        attrs.Where(w => w.DistrictId == districtId);
                }

                if (subjectIds?.Any() ?? false)
                {
                    var attrSubjIds =
                        await
                        _attractionSubjectsService.Get(1, int.MaxValue, new SearchModel()
                    {
                        Filter = ParameterInArray(nameof(AttractionSubject.SubjectId),
                                                  subjectIds.Cast <object>().ToArray())
                    });

                    var groups =
                        attrSubjIds.Items.GroupBy(k => k.AttractionId).Where(w =>
                                                                             subjectsAtLeastOne ? subjectIds.Any(a => w.Select(s => s.SubjectId).Contains(a))
                                                                : subjectIds.All(a => w.Select(s => s.SubjectId).Contains(a)));

                    attrs =
                        attrs.Where(w => groups.Select(t => t.Key).Contains(w.Id));
                }

                if (placeTypeIds?.Any() ?? false)
                {
                    var attrPlaceTypes =
                        await
                        _attractionPlaceTypeService.Get(1, int.MaxValue, new SearchModel()
                    {
                        Filter = ParameterInArray(nameof(AttractionPlaceType.PlaceTypeId),
                                                  placeTypeIds.Cast <object>().ToArray())
                    });

                    var groups =
                        attrPlaceTypes.Items.GroupBy(k => k.AttractionId).Where(w =>
                                                                                placeTypesAtLeastOne ? placeTypeIds.Any(a => w.Select(s => s.PlaceTypeId).Contains(a))
                                                                : placeTypeIds.All(a => w.Select(s => s.PlaceTypeId).Contains(a)));

                    attrs =
                        attrs.Where(w => groups.Select(t => t.Key).Contains(w.Id));
                }


                IReadOnlyCollection <Attraction> attractions =
                    await attrs.GetFilteredTable(new SearchModel()
                {
                    Order = orderModel
                }, cp)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .ToArrayAsync();

                var paging =
                    new PagingResult <IAttraction>()
                {
                    Total = attrs.Count(),
                    Items = !attractions.Any()
                                                        ? new IAttraction[0]
                                                        : DtoMapper.Map <IAttraction[]>(attractions),
                };

                var res =
                    await GetPagingWithLinksInternal(paging);

                return(res);
            }
        }
 public override void Initialize(IAbpInitializationContext initializationContext)
 {
     base.Initialize(initializationContext);
     DtoMapper.Map();
 }
Ejemplo n.º 24
0
        public async Task <PagingResult <IHotelWithLinks> > CustomFilter(int page, int pageSize, string name, int?cityId, int?districtId, int?housingTypeId,
                                                                         int[] equipmentTypes, bool equipmentTypesAtLeastOne, int[] serviceTypes, bool serviceTypesAtLeastOne,
                                                                         OrderModel orderModel)
        {
            using (var cp = _contextProviderFactory.Create())
            {
                var hotels =
                    cp.GetTable <Hotel>();

                if (cityId != null)
                {
                    hotels =
                        hotels.Where(w => w.CityId == cityId);
                }

                if (housingTypeId != null)
                {
                    hotels =
                        hotels.Where(w => w.HousingTypeId == housingTypeId);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    hotels =
                        hotels.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.OrdinalIgnoreCase));
                }

                if (districtId != null)
                {
                    hotels =
                        hotels.Where(w => w.DistrictId == districtId);
                }

                if (equipmentTypes?.Any() ?? false)
                {
                    var attrSubjIds =
                        cp.GetTable <RouteSubjectName>()
                        .ToArray()
                        .GroupBy(atts => atts.RouteId)
                        .Where(w =>
                               equipmentTypesAtLeastOne
                                                                        ? equipmentTypes.Any(a => w.Select(s => s.SubjectNameId).Contains(a))
                                                                        : equipmentTypes.All(a => w.Select(s => s.SubjectNameId).Contains(a)))
                        .Select(s => s.Key);

                    hotels =
                        hotels.Where(w => attrSubjIds.Contains(w.Id));
                }

                if (serviceTypes?.Any() ?? false)
                {
                    var attrSubjIds =
                        cp.GetTable <RouteSubjectName>()
                        .ToArray()
                        .GroupBy(atts => atts.RouteId)
                        .Where(w =>
                               serviceTypesAtLeastOne
                                                                        ? serviceTypes.Any(a => w.Select(s => s.SubjectNameId).Contains(a))
                                                                        : serviceTypes.All(a => w.Select(s => s.SubjectNameId).Contains(a)))
                        .Select(s => s.Key);

                    hotels =
                        hotels.Where(w => attrSubjIds.Contains(w.Id));
                }

                IReadOnlyCollection <Hotel> hotelsFinal =
                    await hotels.GetFilteredTable(new SearchModel()
                {
                    Order = orderModel
                }, cp)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .ToArrayAsync();

                var paging =
                    new PagingResult <IHotel>()
                {
                    Total = hotels.Count(),
                    Items = !hotelsFinal.Any()
                                                        ? new IHotel[0]
                                                        : DtoMapper.Map <IHotel[]>(hotelsFinal),
                };

                var res =
                    await GetPagingWithLinksInternal(paging);

                return(res);
            }
        }
Ejemplo n.º 25
0
        public async Task <PagingResult <IRestaurantWithLinks> > CustomFilter(int page, int pageSize, string name,
                                                                              int?cityId, int?districtId, int?cateringTypeId,
                                                                              int[] cuisineTypeIds, bool atLeastOneCuisineType, int[] denyTypeIds, bool atLeastOneDenyType,
                                                                              OrderModel orderModel)
        {
            using (var cp = _contextProviderFactory.Create()) {
                var rests =
                    cp.GetTable <Restaurant>();

                if (cityId != null)
                {
                    rests =
                        rests.Where(w => w.CityId == cityId);
                }

                if (cateringTypeId != null)
                {
                    rests =
                        rests.Where(w => w.CateringTypeId == cateringTypeId);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    rests =
                        rests.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.OrdinalIgnoreCase));
                }

                if (districtId != null)
                {
                    rests =
                        rests.Where(w => w.DistrictId == districtId);
                }

                if (cuisineTypeIds?.Any() ?? false)
                {
                    var attrCuisines =
                        cp.GetTable <RestaurantCuisineType>()
                        .ToArray()
                        .GroupBy(atts => atts.RestaurantId)
                        .Where(w =>
                               atLeastOneCuisineType
                                                                        ? cuisineTypeIds.Any(a => w.Select(s => s.CuisineTypeId).Contains(a))
                                                                        : cuisineTypeIds.All(a => w.Select(s => s.CuisineTypeId).Contains(a)))
                        .Select(s => s.Key);

                    rests =
                        rests.Where(w => attrCuisines.Contains(w.Id));
                }

                if (denyTypeIds?.Any() ?? false)
                {
                    var attrDeny =
                        cp.GetTable <RestaurantDenyType>()
                        .ToArray()
                        .GroupBy(atts => atts.RestaurantId)
                        .Where(w =>
                               atLeastOneDenyType
                                                                        ? denyTypeIds.Any(a => w.Select(s => s.DenyTypeId).Contains(a))
                                                                        : denyTypeIds.All(a => w.Select(s => s.DenyTypeId).Contains(a)))
                        .Select(s => s.Key);

                    rests =
                        rests.Where(w => attrDeny.Contains(w.Id));
                }

                IReadOnlyCollection <Restaurant> restsFinal =
                    await rests.GetFilteredTable(new SearchModel()
                {
                    Order = orderModel
                }, cp)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .ToArrayAsync();

                var paging =
                    new PagingResult <IRestaurant>()
                {
                    Total = rests.Count(),
                    Items = !restsFinal.Any()
                                                        ? new IRestaurant[0]
                                                        : DtoMapper.Map <IRestaurant[]>(restsFinal),
                };

                var res =
                    await GetPagingWithLinksInternal(paging);

                return(res);
            }
        }
Ejemplo n.º 26
0
 public override void Initialize()
 {
     IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
     DtoMapper.Map();
 }
Ejemplo n.º 27
0
        public void Map_NullPassed_ExceptionThrown()
        {
            IMapper mapper = new DtoMapper();

            Assert.Throws <ArgumentNullException>(() => mapper.Map <object, object>(null));
        }
Ejemplo n.º 28
0
        public async Task <PagingResult <IRouteWithLinks> > CustomFilter(int page, int pageSize,
                                                                         string name,
                                                                         bool?animals,
                                                                         int[] peopleTypeIds,
                                                                         int[] ageTypeIds,
                                                                         int[] subjectNameIds,
                                                                         bool subjectNamesAtLeastOne,
                                                                         int[] subjectTypeIds,
                                                                         bool subjectTypesAtLeastOne,
                                                                         int?cityId,
                                                                         int?districtId,
                                                                         IFromToFilter <float> durationFilter,
                                                                         IFromToFilter <float> lengthFilter, OrderModel orderModel)
        {
            using (var cp = _contextProviderFactory.Create())
            {
                var routes =
                    cp.GetTable <Route>();

                if (cityId != null)
                {
                    routes = routes.Where(w => w.CityId == cityId);
                }

                if (districtId != null)
                {
                    routes = routes.Where(w => w.DistrictId == districtId);
                }

                if (animals != null)
                {
                    routes =
                        routes.Where(w => w.Animals == animals);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    routes =
                        routes.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.InvariantCultureIgnoreCase));
                }


                if (peopleTypeIds?.Any() ?? false)
                {
                    var attrSubjIds =
                        cp.GetTable <RoutePeopleType>()
                        .ToArray()
                        .GroupBy(atts => atts.RouteId)
                        .Where(w => peopleTypeIds.All(a => w.Select(s => s.PeopleTypeId).Contains(a))).Select(s => s.Key);

                    routes =
                        routes.Where(w => attrSubjIds.Contains(w.Id));
                }

                if (ageTypeIds?.Any() ?? false)
                {
                    var attrSubjIds =
                        cp.GetTable <RouteAgeType>()
                        .ToArray()
                        .GroupBy(atts => atts.RouteId)
                        .Where(w => ageTypeIds.All(a => w.Select(s => s.AgeTypeId).Contains(a))).Select(s => s.Key);

                    routes =
                        routes.Where(w => attrSubjIds.Contains(w.Id));
                }

                if (subjectNameIds?.Any() ?? false)
                {
                    var attrSubjIds =
                        cp.GetTable <RouteSubjectName>()
                        .ToArray()
                        .GroupBy(atts => atts.RouteId)
                        .Where(w =>
                               subjectNamesAtLeastOne
                                                                        ? subjectNameIds.Any(a => w.Select(s => s.SubjectNameId).Contains(a))
                                                                        : subjectNameIds.All(a => w.Select(s => s.SubjectNameId).Contains(a)))
                        .Select(s => s.Key);

                    routes =
                        routes.Where(w => attrSubjIds.Contains(w.Id));
                }

                if (subjectTypeIds?.Any() ?? false)
                {
                    var attrSubjIds =
                        cp.GetTable <RouteSubjectType>()
                        .ToArray()
                        .GroupBy(atts => atts.RouteId)
                        .Where(w => subjectTypesAtLeastOne
                                                                ? subjectTypeIds.Any(a => w.Select(s => s.SubjectTypeId).Contains(a))
                                                                : subjectTypeIds.All(a => w.Select(s => s.SubjectTypeId).Contains(a)))
                        .Select(s => s.Key);

                    routes =
                        routes.Where(w => attrSubjIds.Contains(w.Id));
                }

                if (durationFilter != null)
                {
                    routes =
                        routes.Where(w => w.Time >= durationFilter.From && w.Time <= durationFilter.To);
                }

                if (lengthFilter != null)
                {
                    routes =
                        routes.Where(w => w.Length >= lengthFilter.From && w.Length <= lengthFilter.To);
                }

                IReadOnlyCollection <Route> routesFinal =
                    await routes.GetFilteredTable(new SearchModel()
                {
                    Order = orderModel
                }, cp)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .ToArrayAsync();

                var paging =
                    new PagingResult <IRoute>()
                {
                    Total = routes.Count(),
                    Items = !routesFinal.Any()
                                                        ? new IRoute[0]
                                                        : DtoMapper.Map <IRoute[]>(routesFinal),
                };

                var res =
                    await GetPagingWithLinksInternal(paging);

                return(res);
            }
        }
Ejemplo n.º 29
0
        public async Task <PagingResult <IEventWithLinks> > CustomFilter(int page, int pageSize,
                                                                         int?cityId,
                                                                         int?districtId,
                                                                         IFromToFilter <DateTime> startDateFilter,
                                                                         IFromToFilter <DateTime> endDateFilter,
                                                                         IFromToFilter <DateTime> dateFilter,
                                                                         SearchModel search)
        {
            using (var cp = _contextProviderFactory.Create())
            {
                var events =
                    cp.GetTable <Event>();

                if (cityId != null)
                {
                    events = events.Where(w => w.CityId == cityId);
                }

                if (districtId != null)
                {
                    events = events.Where(w => w.DistrictId == districtId);
                }

                if (startDateFilter != null)
                {
                    events =
                        events.Where(w => w.StartDate >= startDateFilter.From && w.StartDate <= startDateFilter.To);
                }

                if (endDateFilter != null)
                {
                    events =
                        events.Where(w => w.EndDate >= endDateFilter.From && w.EndDate <= endDateFilter.To);
                }

                if (dateFilter != null)
                {
                    events =
                        events.Where(w => (w.StartDate >= dateFilter.From && w.StartDate <= dateFilter.To) ||
                                     (w.EndDate >= dateFilter.From && w.EndDate <= dateFilter.To) ||
                                     (w.StartDate <= dateFilter.From && w.EndDate >= dateFilter.To));
                }

                IReadOnlyCollection <Event> eventsFinal =
                    await events.GetFilteredTable(search, cp)
                    .Skip((page - 1) * pageSize)
                    .Take(pageSize)
                    .ToArrayAsync();

                var paging =
                    new PagingResult <IEvent>()
                {
                    Total = events.Count(),
                    Items = !eventsFinal.Any()
                                                        ? new IEvent[0]
                                                        : DtoMapper.Map <IEvent[]>(eventsFinal),
                };

                var res =
                    await GetPagingWithLinksInternal(paging);

                return(res);
            }
        }