public async Task <ResourceDataResult> UpdateStop(int stopId, StopForUpdateDTO stopModel)
        {
            ResourceDataResult result = new ResourceDataResult();

            var stop = await _stopRepo.GetStopById(stopId);

            //upsert
            if (stop == null)
            {
                result.StatusCode = 201;
                stop = new Stop()
                {
                    Id = stopId
                };
            }

            stop = StopMapper.UpdateEntityToModel(stop, stopModel);

            if (stop != null && await _stopRepo.UpdateStop(stop))
            {
                result.Result = StopMapper.ConvertEntityToModel(stop);
                return(result);
            }

            return(null);
        }
        public async Task <StopDTO> CreateStop(StopForCreationDTO stopModel)
        {
            Stop stop = StopMapper.ConvertCreationModelToEntity(stopModel);

            if (await _stopRepo.CreateStop(stop))
            {
                return(StopMapper.ConvertEntityToModel(stop));
            }

            return(null);
        }
        public async Task <IEnumerable <StopDTO> > GetStops(IEnumerable <int> ids)
        {
            var stops = await _stopRepo.GetStops(ids);

            if (stops != null)
            {
                return(StopMapper.ConvertEntityToModel(stops));
            }

            return(null);
        }
        public async Task <StopDTO> GetStop(int stopId)
        {
            var stop = await _stopRepo.GetStopById(stopId);


            if (stop != null)
            {
                return(StopMapper.ConvertEntityToModel(stop));
            }

            return(null);
        }
        public async Task <StopForUpdateDTO> GetUpdateModelForStop(int stopId)
        {
            var stop = await _stopRepo.GetStopById(stopId);

            if (stop == null)
            {
                return(null);
            }

            StopForUpdateDTO updatedStop = StopMapper.ConvertEntityToModel <StopForUpdateDTO>(stop);

            return(updatedStop);
        }
        public async Task <ResourceDataResult> GetStops(PaginationProperties paginationProperties)
        {
            ResourceDataResult result = new ResourceDataResult();

            if (!_sortPropertyMappingService.ValidMappingExistsFor <StopDTO, Stop>(paginationProperties.OrderBy))
            {
                result.StatusCode   = 400;
                result.ErrorMessage = "Invalid sorting field in query string.";
                return(result);
            }

            PagedList <Stop> stops = await _stopRepo.GetStops(paginationProperties);

            //PagedList<StopDTO> stopModels = new PagedList<StopDTO>(StopMapper.ConvertEntityToModel(stops), stops.Count, stops.CurrentPage, stops.PageSize);

            if (stops != null && stops.Count > 0)
            {
                result.Result = new PagedList <StopDTO>(StopMapper.ConvertEntityToModel(stops), stops.TotalCount, stops.CurrentPage, stops.PageSize);
            }

            return(result);
        }