コード例 #1
0
        public void Then_The_Url_Is_Correctly_Built()
        {
            //Act
            var actual = new GetBannerRequest();

            //Assert
            actual.GetUrl.Should().Be("entries?content_type=banner");
        }
コード例 #2
0
        /// <summary>
        /// 获取Banner数据
        /// </summary>
        /// <returns>Task&lt;Response&lt;GetBannerResponse&gt;&gt;.</returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task <Response <GetBannerResponse[]> > GetBanner(GetBannerRequest request)
        {
            if (request.CityId == 0)
            {
                request.CityId = 860571;//默认为杭州市
            }


            var bannerInfo = await(this.strokeContext.Ad.Where(x => x.CityId == request.CityId && x.Type == ADType.Banner)
                                   .Select(x => new GetBannerResponse
            {
                Id         = x.Id,
                Type       = x.Type,
                Title      = x.Title,
                CityId     = x.CityId,
                Content    = x.Content,
                StrokeId   = x.StrokeId,
                Link       = x.Link,
                ImageUrl   = x.ImageUrl,
                ImageThumb = x.ImageThumb
            })).ToArrayAsync();

            if (bannerInfo.Count() == 0)
            {
                bannerInfo = await(this.strokeContext.Ad.Where(x => x.CityId == 860571 && x.Type == ADType.Banner)
                                   .Select(x => new GetBannerResponse
                {
                    Id         = x.Id,
                    Type       = x.Type,
                    Title      = x.Title,
                    CityId     = x.CityId,
                    StrokeId   = x.StrokeId,
                    Link       = x.Link,
                    Content    = x.Content,
                    ImageUrl   = x.ImageUrl,
                    ImageThumb = x.ImageThumb
                })).ToArrayAsync();
            }
            return(new Response <GetBannerResponse[]>
            {
                Data = bannerInfo
            });
        }
コード例 #3
0
 public Task <Response <GetBannerResponse[]> > GetBanner([FromBody] GetBannerRequest request)
 {
     return(this.strokeService.GetBanner(request));
 }
コード例 #4
0
        public GetBannerResponse GetBanner(GetBannerRequest request)
        {
            GetBannerResponse response = new GetBannerResponse();

            try
            {
                switch (request.user_type)
                {
                case (int)UserType.SuperUser:
                    if (!SuperUserServices.CheckSuperUser(request.user_id, request.auth_token, response))
                    {
                        response.message = MessagesSource.GetMessage("invalid.super.user");
                        return(response);
                    }
                    break;

                case (int)UserType.AgentBoss:
                    if (!AgentBossServices.CheckAgentBoss(request.user_id, request.auth_token, response))
                    {
                        return(response);
                    }
                    break;

                case (int)UserType.AgentAdmin:
                    if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                    {
                        return(response);
                    }
                    break;

                case (int)UserType.Driver:
                    if (!DriverServices.CheckAuthDriver(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                    break;

                case (int)UserType.Consumer:
                    if (!_userServices.CheckAuthUser(request.user_id, request.auth_token))
                    {
                        _userServices.MakeNouserResponse(response);
                        return(response);
                    }
                    break;

                default:
                {
                    response.has_resource = 0;
                    response.code         = 1;
                    response.message      = MessagesSource.GetMessage("invalid.user.type");
                    return(response);
                }
                }

                using (PromoDao dao = new PromoDao())
                {
                    GetBannerResponse dto   = new GetBannerResponse();
                    PromoBanner       promo = dao.FindByCategoty(request.category);
                    if (promo == null)
                    {
                        response.has_resource = 1;
                        response.code         = 0;
                        response.message      = MessagesSource.GetMessage("promo.banner.not.found");
                        return(response);
                    }
                    if (promo != null)
                    {
                        PromoHelper.CopyFromEntity(dto, promo);
                    }
                    response              = dto;
                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("promo.banner.found");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
コード例 #5
0
 public static void CopyToEntity(PromoBanner promo, GetBannerRequest request)
 {
     promo.Category = request.category; // auth_token
 }
コード例 #6
0
        public NegotiatedContentResult <GetBannerResponse> GetBanner([FromBody] GetBannerRequest request)
        {
            GetBannerResponse resp = _promoServices.GetBanner(request);

            return(Content(HttpStatusCode.OK, resp));
        }