コード例 #1
0
        public async Task <ActionResult <OperationResult <IPagedList <TViewModel> > > > GetPaged([FromQuery] TQueryParams queryParams)
        {
            var accessRights = ValidateQueryParams(queryParams);

            if (!accessRights.IsOk)
            {
                var adminRights = await AccountService.IsInRolesAsync(new[] { AppData.SystemAdministratorRoleName });

                if (adminRights == null || !adminRights.IsOk)
                {
                    return(OperationResultError <IPagedList <TViewModel> >(null, accessRights.ToString()));
                }
            }

            ApplyDefaultSettings(queryParams);
            var properName = OrderByPropertyName();

            if (!string.IsNullOrEmpty(properName))
            {
                _orderBy = GetOrderBy(properName, queryParams.SortDirection.ToString());
            }

            var includes  = GetIncludes();
            var predicate = PredicateBuilder.True <TEntity>();

            predicate = FilterItems(predicate, queryParams);
            var items  = Repository.GetPagedList(predicate: predicate, orderBy: _orderBy, include: includes, pageIndex: queryParams.PageIndex, pageSize: queryParams.PageSize);
            var mapped = CurrentMapper.Map <IPagedList <TViewModel> >(items);

            return(OperationResultSuccess(mapped, $"Total count: {items.TotalCount}"));
        }
コード例 #2
0
        public async Task <ActionResult <OperationResult <TViewModel> > > GetAsync(Guid id)
        {
            var includes = GetIncludes();
            var entity   = Repository.GetFirstOrDefault(predicate: x => x.Id == id, include: includes);

            if (entity == null)
            {
                return(OperationResultError <TViewModel>(null, AppData.Exceptions.NotFoundException));
            }

            var accessRights = ValidateUserRolesAndRights(entity);

            if (!accessRights.IsOk)
            {
                var adminRights = await AccountService.IsInRolesAsync(new[] { AppData.SystemAdministratorRoleName });

                if (adminRights == null || !adminRights.IsOk)
                {
                    return(OperationResultError <TViewModel>(null, accessRights.ToString()));
                }
            }

            var mapped = CurrentMapper.Map <TEntity, TViewModel>(entity);

            return(OperationResultSuccess(mapped));
        }
コード例 #3
0
        public virtual async Task <ActionResult <OperationResult <TViewModel> > > GetById(Guid id)
        {
            var operation = OperationResult.CreateResult <TViewModel>();
            var includes  = GetIncludes();
            var entity    = await Repository.GetFirstOrDefaultAsync(predicate : x => x.Id == id, include : includes);

            if (entity == null)
            {
                operation.AddError(new MicroserviceNotFoundException());
                return(OperationResultBeforeReturn(operation));
            }

            var accessRights = ValidateUserAccessRights(entity);

            if (!accessRights.IsOk)
            {
                operation.AddError(new MicroserviceUnauthorizedException(accessRights.ToString()));
                return(OperationResultBeforeReturn(operation));
            }

            var mapped = CurrentMapper.Map <TEntity, TViewModel>(entity);

            operation.Result = mapped;
            return(OperationResultBeforeReturn(operation));
        }
コード例 #4
0
        public virtual ActionResult <OperationResult <IPagedList <TViewModel> > > GetPaged([FromQuery] TQueryParams queryParams, bool disabledDefaultIncludes = false)
        {
            var operation        = OperationResult.CreateResult <IPagedList <TViewModel> >();
            var validationResult = ValidateQueryParams(queryParams);

            if (!validationResult.IsOk)
            {
                operation.AddError(validationResult.ToString()).AddData(validationResult.Errors);
                return(OperationResultBeforeReturn(operation));
            }

            var properName = GetPropertyNameForOrderBy();

            if (!string.IsNullOrEmpty(properName))
            {
                _orderBy = GetOrderBy(properName, queryParams.SortDirection.ToString());
            }
            else
            {
            }

            var includes  = disabledDefaultIncludes ? null : GetIncludes();
            var predicate = PredicateBuilder.True <TEntity>();

            predicate = FilterItems(predicate, queryParams);
            var pagedList = Repository.GetPagedList(predicate: predicate, orderBy: _orderBy, include: includes, pageIndex: queryParams.PageIndex, pageSize: queryParams.PageSize);

            if (pagedList == null)
            {
                operation.Result = PagedList.Empty <TViewModel>();
                return(OperationResultBeforeReturn(operation));
            }

            if (pagedList.PageIndex >= pagedList.TotalPages)
            {
                pagedList = Repository.GetPagedList(predicate: predicate, orderBy: _orderBy, include: includes, pageIndex: 0, pageSize: queryParams.PageSize);
            }

            foreach (var item in pagedList.Items)
            {
                var accessRights = ValidateUserAccessRights(item);
                if (!accessRights.IsOk)
                {
                    operation.Result = CurrentMapper.Map <IPagedList <TViewModel> >(pagedList);
                    operation.AddInfo($"$_TOTAL_COUNT_$: {pagedList.TotalCount}");
                    return(OperationResultBeforeReturn(operation));
                }
            }
            var mapped = CurrentMapper.Map <IPagedList <TViewModel> >(pagedList);

            operation.Result = mapped;
            operation.AddInfo($"$_TOTAL_COUNT_$: {pagedList.TotalCount}");
            return(OperationResultBeforeReturn(operation));
        }
コード例 #5
0
        public ActionResult <OperationResult <List <ReviewViewModel> > > GetReviewForProductId(Guid productId)
        {
            var operation = OperationResult.CreateResult <List <ReviewViewModel> >();
            var items     = UnitOfWork.GetRepository <Review>().GetAll().Where(x => x.ProductId == productId);

            if (!items.Any())
            {
                operation.AddInfo($"No reviews found for product with ID {productId}");
                return(operation);
            }

            var mapped = CurrentMapper.Map <List <ReviewViewModel> >(items);

            operation.Result = mapped;
            return(Ok(operation));
        }
コード例 #6
0
        public void GivenRoadStatusResponseShouldMapToRoadStatusResponseDto()
        {
            var input = new RoadStatusResponse
            {
                Type = "Tfl.Api.Presentation.Entities.RoadCorridor, Tfl.Api.Presentation.Entities",
                Id = "a2",
                DisplayName = "A2",
                StatusSeverity = "Good",
                StatusSeverityDescription = "No Exceptional Delays",
                Bounds = "[[-0.0857,51.44091],[0.17118,51.49438]]",
                Envelope = "[[-0.0857,51.44091],[-0.0857,51.49438],[0.17118,51.49438],[0.17118,51.44091],[-0.0857,51.44091]]",
                Url = "/Road/a2"
            };

            var outPutRoadStatusResponseDto = CurrentMapper.Map<RoadStatusResponseDto>(input);

            Assert.Equal(input.DisplayName, outPutRoadStatusResponseDto.DisplayName);
            Assert.Equal(input.StatusSeverity, outPutRoadStatusResponseDto.StatusSeverity);
            Assert.Equal(input.StatusSeverityDescription, outPutRoadStatusResponseDto.StatusSeverityDescription);
        }
コード例 #7
0
ファイル: Map.cs プロジェクト: afonsof/nes-hd
 public void WritePrg(ushort address, byte value)
 {
     CurrentMapper.Write(address, value);
 }
コード例 #8
0
ファイル: Map.cs プロジェクト: afonsof/nes-hd
 public void TickCycleTimer()
 {
     CurrentMapper.TickCycleTimer();
 }
コード例 #9
0
ファイル: Map.cs プロジェクト: afonsof/nes-hd
 public void TickScanlineTimer()
 {
     CurrentMapper.TickScanlineTimer();
 }