예제 #1
0
    public News[] GetNewsList(string username, string password)
    {
        GetNewsListRequest inValue = new GetNewsListRequest();

        inValue.Body          = new GetNewsListRequestBody();
        inValue.Body.username = username;
        inValue.Body.password = password;
        GetNewsListResponse retVal = ((IV2Soap)(this)).GetNewsList(inValue);

        return(retVal.Body.GetNewsListResult);
    }
        public Task <GetNewsListResponse> GetNewsListAsync(GetNewsList dto)
        {
            return(Task.Run(() =>
            {
                string sqlWhere = "";
                switch (dto.hot_type)
                {
                case Community.Contact.Enum.HotEnum.All:
                    break;

                case Community.Contact.Enum.HotEnum.Hot:
                    sqlWhere += string.Format(SELECT_NEWS_WHERE_HOT, 1);
                    break;

                case Community.Contact.Enum.HotEnum.UnHot:
                    sqlWhere += string.Format(SELECT_NEWS_WHERE_HOT, 0);
                    break;

                default:
                    break;
                }
                switch (dto.off_line)
                {
                case Community.Contact.Enum.OffLineEnum.All:
                    break;

                case Community.Contact.Enum.OffLineEnum.OffLine:
                    if (sqlWhere.Length < 1)
                    {
                        sqlWhere += string.Format(SELECT_NEWS_WHERE_OFFLINE, 1);
                    }
                    else
                    {
                        sqlWhere += " and ";
                        sqlWhere += string.Format(SELECT_NEWS_WHERE_OFFLINE, 1);
                    }
                    break;

                case Community.Contact.Enum.OffLineEnum.UnOffLine:
                    if (sqlWhere.Length < 1)
                    {
                        sqlWhere += string.Format(SELECT_NEWS_WHERE_OFFLINE, 0);
                    }
                    else
                    {
                        sqlWhere += " and ";
                        sqlWhere += string.Format(SELECT_NEWS_WHERE_OFFLINE, 0);
                    }
                    break;

                default:
                    break;
                }
                if (sqlWhere.Length > 1)
                {
                    sqlWhere = " where " + sqlWhere;
                }
                List <SearchNewsModel> data = new List <SearchNewsModel>();
                int count = 0;
                string sqlData = "";
                string sqlCount = "";
                if (string.IsNullOrEmpty(dto.type))
                {
                    sqlData = string.Format(SELECT_NEWS_FROM, SELECT_NEWS_SELECT, sqlWhere, string.Format("LIMIT {0},{1}", dto.start, dto.length));
                    sqlCount = string.Format(SELECT_NEWS_FROM, SELECT_NEWS_COUNT, sqlWhere, "");
                }
                else
                {
                    string[] typeidList = dto.type.Split(',');
                    var builder = new StringBuilder();
                    for (int i = 0; i < typeidList.Length; i++)
                    {
                        builder.Append("category_id= " + typeidList[i]);
                        if (i != typeidList.Length - 1)
                        {
                            builder.Append("||");
                        }
                    }
                    if (sqlWhere.Length > 0)
                    {
                        sqlWhere = sqlWhere + " and " + string.Format(SELECT_NEWS_WHERE_CAT, builder.ToString(), typeidList.Count() - 1);
                    }
                    else
                    {
                        sqlWhere = sqlWhere + " where " + string.Format(SELECT_NEWS_WHERE_CAT, builder.ToString(), typeidList.Count() - 1);
                    }
                    sqlData = string.Format(SELECT_NEWS_FROM, SELECT_NEWS_SELECT, sqlWhere, string.Format("LIMIT {0},{1}", dto.start, dto.length));

                    sqlCount = string.Format(SELECT_NEWS_FROM, SELECT_NEWS_COUNT, sqlWhere, "");
                }
                data = _dapperRepository.Query <SearchNewsModel>(sqlData).ToList();
                if (data != null && data.Count() > 0)
                {
                    count = _dapperRepository.QuerySingleOrDefault <int>(sqlCount);
                }
                GetNewsListResponse resp = new GetNewsListResponse();
                resp.data = Mapper.Map <List <NewsIntro> >(data);
                resp.total = count;
                return resp;
            }));
        }