Пример #1
0
        public HttpResponseMessage GetAdvertisementHtml(GetAdvertisementArgEntity arg)
        {
            BaseJson <string> resultMsg = new BaseJson <string> {
                Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null
            };

            Logger(typeof(AdvertisementController), arg.TryToJson(), "获取广告Html-GetAdvertisementHtml", () =>
            {
                if (!string.IsNullOrEmpty(arg.t))
                {
                    if (arg.t.CheckTimeStamp())
                    {
                        string html = Cache.Factory.CacheFactory.Cache().GetCache <string>("Advertisement_Html_" + arg.Which);
                        if (string.IsNullOrEmpty(html))
                        {
                            List <AdvertisementEntity> list = advertisementBll.GetList(a => a.CategoryId.Equals(arg.Which)).ToList();

                            //List<AdvertisementViewEntity> res = list.Select(n => new AdvertisementViewEntity
                            //{
                            //    Id = n.ID,
                            //    Title = n.Title,
                            //    Href = n.Href.ToLower().Contains("http://") || n.Href.ToLower().Contains("https://") ? n.Href : "http://" + n.Href,
                            //    Position = n.Position,
                            //    Which = n.CategoryId,
                            //    OverTime = n.TermOfValidity.TryToDateTimeToString("yyyy-MM-dd"),
                            //    IsEnable = n.IsEnable ?? false
                            //}).ToList();

                            //按位置排序
                            list = list.OrderBy(r => r.Position).ToList();

                            html = GetHtml(list, arg.Which);

                            Cache.Factory.CacheFactory.Cache().WriteCache(html, "Advertisement_Html_" + arg.Which, DateTimeHelper.Now.AddDays(10));
                        }
                        resultMsg = new BaseJson <string>
                        {
                            Status  = (int)JsonObjectStatus.Success,
                            Data    = html,
                            Message = JsonObjectStatus.Success.GetEnumText(),
                            BackUrl = null
                        };
                    }
                    else
                    {
                        resultMsg = new BaseJson <string>
                        {
                            Status  = (int)JsonObjectStatus.Fail,
                            Data    = null,
                            Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
                            BackUrl = null
                        };
                    }
                }
                else
                {
                    resultMsg = new BaseJson <string>
                    {
                        Status  = (int)JsonObjectStatus.Fail,
                        Data    = null,
                        Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
                        BackUrl = null
                    };
                }
            }, e =>
            {
                resultMsg = new BaseJson <string>
                {
                    Status  = (int)JsonObjectStatus.Exception,
                    Data    = null,
                    Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
                    BackUrl = null
                };
            });

            return(resultMsg.TryToJson().ToHttpResponseMessage());
        }
Пример #2
0
        public HttpResponseMessage GetAdvertisementList(GetAdvertisementArgEntity arg)
        {
            BaseJson <List <AdvertisementViewEntity> > resultMsg = new BaseJson <List <AdvertisementViewEntity> > {
                Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null
            };

            Logger(typeof(AdvertisementController), arg.TryToJson(), "获取广告列表-GetAdvertisementList", () =>
            {
                if (!string.IsNullOrEmpty(arg.t))
                {
                    if (arg.t.CheckTimeStamp())
                    {
                        List <AdvertisementEntity> list = advertisementBll.GetList(a => a.CategoryId.Equals(arg.Which) && a.Title != "" && a.TermOfValidity > DateTimeHelper.Now).ToList();

                        List <AdvertisementViewEntity> res = list.Select(n => new AdvertisementViewEntity
                        {
                            Id       = n.ID,
                            Title    = n.Title ?? "",
                            Href     = n.Href != null ? n.Href.ToLower().Contains("http://") || n.Href.ToLower().Contains("https://") ? n.Href : "http://" + n.Href : "",
                            Position = n.Position,
                            Which    = n.CategoryId,
                            OverTime = n.TermOfValidity.TryToDateTimeToString("yyyy-MM-dd"),
                            IsEnable = n.IsEnable ?? false,
                            IsExpire = n.TermOfValidity != null && n.TermOfValidity < DateTimeHelper.Now
                        }).ToList();

                        res = res.OrderBy(r => r.Position).ToList();

                        resultMsg = new BaseJson <List <AdvertisementViewEntity> >
                        {
                            Status  = (int)JsonObjectStatus.Success,
                            Data    = res,
                            Message = JsonObjectStatus.Success.GetEnumText(),
                            BackUrl = null
                        };
                    }
                    else
                    {
                        resultMsg = new BaseJson <List <AdvertisementViewEntity> >
                        {
                            Status  = (int)JsonObjectStatus.Fail,
                            Data    = null,
                            Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
                            BackUrl = null
                        };
                    }
                }
                else
                {
                    resultMsg = new BaseJson <List <AdvertisementViewEntity> >
                    {
                        Status  = (int)JsonObjectStatus.Fail,
                        Data    = null,
                        Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
                        BackUrl = null
                    };
                }
            }, e =>
            {
                resultMsg = new BaseJson <List <AdvertisementViewEntity> >
                {
                    Status  = (int)JsonObjectStatus.Exception,
                    Data    = null,
                    Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
                    BackUrl = null
                };
            });

            return(resultMsg.TryToJson().ToHttpResponseMessage());
        }