Exemplo n.º 1
0
        public string FollowsAll()
        {
            ApiResult result = new ApiResult();

            try
            {
                var CreateUserNumber = ZNRequest.GetString("CreateUserNumber");
                if (string.IsNullOrWhiteSpace(CreateUserNumber))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }
                var CurrUserNumber = ZNRequest.GetString("CurrUserNumber");
                if (string.IsNullOrWhiteSpace(CurrUserNumber))
                {
                    CurrUserNumber = CreateUserNumber;
                }
                var pager       = new Pager();
                var query       = new SubSonic.Query.Select(provider).From <Fan>().Where <Fan>(x => x.CreateUserNumber == CreateUserNumber);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Fan>();
                var array     = list.Select(x => x.ToUserNumber).Distinct().ToList();
                var users     = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Signature", "Number").From <User>().Where <User>(x => x.Status == Enum_Status.Approved).And("Number").In(array.ToArray()).ExecuteTypedList <User>();
                var follows   = db.Find <Fan>(x => x.CreateUserNumber == CurrUserNumber).ToList();
                var newlist   = (from l in list
                                 join u in users on l.ToUserNumber equals u.Number
                                 select new
                {
                    ID = l.ID,
                    CreateDate = FormatTime(l.CreateDate),
                    UserID = u.ID,
                    Cover = u.Cover,
                    NickName = u.NickName,
                    Signature = u.Signature,
                    Avatar = u.Avatar,
                    Number = u.Number,
                    IsFollow = follows.Exists(x => x.ToUserNumber == u.Number) ? 1 : 0
                }).ToList();
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Fan_FollowsAll:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 2
0
        public string ToUser_1_3()
        {
            ApiResult result = new ApiResult();

            try
            {
                var UserNumber = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var query = new SubSonic.Query.Select(provider).From <Order>().Where <Order>(x => x.Status == Enum_Status.Approved);
                query = query.And("CreateUserNumber").IsEqualTo(UserNumber);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var pager                 = new Pager();
                var totalPage             = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list                  = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Order>();
                var userarray             = list.Select(x => x.ToUserNumber).Distinct().ToList();
                var allusers              = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number", "Cover").From <User>().And("Number").In(userarray.ToArray()).ExecuteTypedList <User>();
                List <OrdersJson> newlist = new List <OrdersJson>();
                list.ForEach(x =>
                {
                    var user = allusers.FirstOrDefault(y => y.Number == x.ToUserNumber);
                    if (user != null)
                    {
                        OrdersJson model = new OrdersJson();
                        model.ID         = x.ID;
                        model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd hh:mm:ss");
                        model.Price      = x.Price;
                        model.UserID     = user.ID;
                        model.UserNumber = user.Number;
                        model.UserAvatar = user.Avatar;
                        model.UserName   = user.NickName;
                        model.UserCover  = user.Cover;
                        newlist.Add(model);
                    }
                });

                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Order_ToUser_1_3:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 3
0
        public string LinkAll()
        {
            ApiResult result = new ApiResult();

            try
            {
                User user = GetUserInfo();
                if (user == null)
                {
                    result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin);
                    result.code    = Enum_ErrorCode.UnLogin;
                    return(JsonConvert.SerializeObject(result));
                }

                var pager = new Pager();
                var query = new SubSonic.Query.Select(provider, "ID", "Number", "Title", "Cover", "CreateUserNumber", "CreateDate", "ArticlePower", "ArticlePowerPwd").From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.Submission >= Enum_Submission.Approved);
                query = query.And("CreateUserNumber").IsEqualTo(user.Number);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;

                var sort = new string[] { "ID" };

                var list = query.Paged(pager.Index, pager.Size).OrderDesc(sort).ExecuteTypedList <Article>();

                var newlist = (from l in list
                               select new
                {
                    ID = l.ID,
                    Number = l.Number,
                    Title = l.Title,
                    Cover = l.Cover,
                    CreateDate = l.CreateDate.ToString("yyyy-MM-dd hh:mm:ss"),
                    ArticlePower = l.ArticlePower,
                    ArticlePowerPwd = l.ArticlePowerPwd
                });

                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Article_LinkAll:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 4
0
        public string All()
        {
            ApiResult result = new ApiResult();

            try
            {
                var CreateUserNumber = ZNRequest.GetString("CreateUserNumber");
                if (string.IsNullOrWhiteSpace(CreateUserNumber))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }
                var pager       = new Pager();
                var query       = new SubSonic.Query.Select(provider).From <Black>().Where <Black>(x => x.CreateUserNumber == CreateUserNumber);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var list  = query.OrderDesc("ID").ExecuteTypedList <Black>();
                var array = list.Select(x => x.ToUserNumber).ToArray();
                var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Signature", "Number", "Cover").From <User>().Where("Number").In(array).ExecuteTypedList <User>();

                var newlist = (from b in list
                               join u in users on b.ToUserNumber equals u.Number
                               select new BlackJson
                {
                    ID = b.ID,
                    CreateDate = b.CreateDate.ToString("yyyy-MM-dd"),
                    UserID = u.ID,
                    Number = u.Number,
                    NickName = u.NickName,
                    Avatar = u.Avatar,
                    Signature = u.Signature,
                    Cover = u.Cover
                }).ToList();
                result.result  = true;
                result.message = new
                {
                    currpage  = 1,
                    records   = newlist.Count,
                    totalpage = 1,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Black_All:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 5
0
        public string Search()
        {
            ApiResult result = new ApiResult();

            try
            {
                var pager = new Pager();
                var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.ArticlePower == Enum_ArticlePower.Public && x.Submission >= Enum_Submission.Approved);

                var title = SqlFilter(ZNRequest.GetString("Title"));
                if (!string.IsNullOrWhiteSpace(title))
                {
                    query.And("Title").IsNotNull().And("Title").Like("%" + title + "%");
                }

                var UserNumber = ZNRequest.GetString("UserNumber");
                if (!string.IsNullOrWhiteSpace(UserNumber))
                {
                    var black = db.Find <Black>(x => x.CreateUserNumber == UserNumber);
                    if (black.Count > 0)
                    {
                        var userids = black.Select(x => x.ToUserNumber).ToArray();
                        query = query.And("CreateUserNumber").NotIn(userids);
                    }
                }
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.result  = true;
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc(new string[] { "Recommend", "Views" }).ExecuteTypedList <Article>();
                List <ArticleJson> newlist = ArticleListInfo(list, UserNumber);
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Article_Search:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 6
0
        public string Article()
        {
            ApiResult result = new ApiResult();

            try
            {
                var UserNumber = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }

                var fans = db.Find <Fan>(x => x.CreateUserNumber == UserNumber).ToList();
                if (fans.Count == 0)
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }

                var pager = new Pager();
                var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved);
                query = query.And("ArticlePower").In(new int[] { Enum_ArticlePower.Public, Enum_ArticlePower.Password });
                query.And("CreateUserNumber").In(fans.Select(x => x.ToUserNumber).ToArray());
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc(new string[] { "ID" }).ExecuteTypedList <Article>();
                List <ArticleJson> newlist = ArticleListInfo(list, UserNumber);
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Fan_Article:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 7
0
        public string Apply_1_3()
        {
            ApiResult result = new ApiResult();

            try
            {
                var UserNumber = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var query = new SubSonic.Query.Select(provider).From <ApplyMoney>().Where <ApplyMoney>(x => x.Status == Enum_Status.Approved);
                query = query.And("CreateUserNumber").IsEqualTo(UserNumber);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var pager                 = new Pager();
                var totalPage             = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list                  = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <ApplyMoney>();
                List <OrdersJson> newlist = new List <OrdersJson>();
                list.ForEach(x =>
                {
                    OrdersJson model = new OrdersJson();
                    model.ID         = x.ID;
                    model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd hh:mm:ss");
                    model.Price      = Tools.SafeInt(System.Configuration.ConfigurationManager.AppSettings["applymoney"]) * 100;
                    newlist.Add(model);
                });

                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Order_Apply_1_3:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 8
0
        public string All()
        {
            ApiResult result = new ApiResult();

            try
            {
                var CreateUserNumber = ZNRequest.GetString("CreateUserNumber");
                if (string.IsNullOrWhiteSpace(CreateUserNumber))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }
                var CurrUserNumber = ZNRequest.GetString("CurrUserNumber");
                if (string.IsNullOrWhiteSpace(CurrUserNumber))
                {
                    CurrUserNumber = CreateUserNumber;
                }

                var pager       = new Pager();
                var query       = new SubSonic.Query.Select(provider).From <Keep>().Where <Keep>(x => x.CreateUserNumber == CreateUserNumber);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Keep>();
                var articles  = new SubSonic.Query.Select(provider, "ID", "Number", "Title", "TypeID", "Cover", "Views", "Goods", "CreateUserNumber", "CreateDate", "ArticlePower", "ArticlePowerPwd", "Recommend", "City", "Province", "Submission").From <Article>().Where("Number").In(list.Select(x => x.ArticleNumber).ToArray()).And("Status").IsNotEqualTo(Enum_Status.Audit).OrderDesc(new string[] { "Recommend", "ID" }).ExecuteTypedList <Article>();

                List <ArticleJson> newlist = ArticleListInfo(articles, CurrUserNumber);
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Keep_All:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 9
0
        public string ToMe_1_4()
        {
            ApiResult result = new ApiResult();

            try
            {
                var UserNumber = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var query       = new SubSonic.Query.Select(provider).From <Red>().Where <Red>(x => x.ToUserNumber == UserNumber);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var pager     = new Pager();
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Red>();
                list.ForEach(x =>
                {
                    x.RedTypeText    = EnumBase.GetDescription(typeof(Enum_RedType), x.RedType);
                    x.CreateDateText = x.CreateDate.ToString("yyyy-MM-dd hh:mm:ss");
                });
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = list
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Red_ToMe_1_3:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 10
0
        public string Pic()
        {
            ApiResult result = new ApiResult();

            try
            {
                var Number     = ZNRequest.GetString("Number");
                var UserNumber = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var pager = new Pager();
                var query = new SubSonic.Query.Select(provider).From <ArticlePart>().Where <ArticlePart>(x => x.Types == Enum_ArticlePart.Pic && x.Status != Enum_Status.Delete && x.Status != Enum_Status.DeleteCompletely);
                if (Number != UserNumber)
                {
                    query = query.And("Status").IsEqualTo(Enum_Status.Approved);
                }
                query = query.And("CreateUserNumber").IsEqualTo(UserNumber);
                var recordCount = query.GetRecordCount();
                var totalPage   = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list        = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <ArticlePart>();

                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = list
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_User_Pic:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 11
0
        public string DeleteAll()
        {
            ApiResult result = new ApiResult();

            try
            {
                var pager      = new Pager();
                var UserNumber = ZNRequest.GetString("CreateUserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Delete && x.CreateUserNumber == UserNumber);

                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc(new string[] { "UpdateDate" }).ExecuteTypedList <Article>();
                List <ArticleJson> newlist = ArticleListInfo(list, UserNumber);
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Article_DeleteAll:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 12
0
        public string Search()
        {
            ApiResult result = new ApiResult();

            try
            {
                var UserNumber = ZNRequest.GetString("UserNumber");
                var nickname   = ZNRequest.GetString("NickName");
                var pager      = new Pager();
                var query      = new SubSonic.Query.Select(provider).From <User>().Where <User>(x => x.Status == Enum_Status.Approved);

                if (!string.IsNullOrWhiteSpace(nickname))
                {
                    query.And("NickName").IsNotNull().And("NickName").Like("%" + nickname + "%");
                }

                if (!string.IsNullOrWhiteSpace(UserNumber))
                {
                    var black = db.Find <Black>(x => x.CreateUserNumber == UserNumber);
                    if (black.Count > 0)
                    {
                        var userids = black.Select(x => x.ToUserNumber).ToArray();
                        query = query.And("Number").NotIn(userids);
                    }
                }

                var recordCount = query.GetRecordCount();

                if (recordCount == 0)
                {
                    result.result  = true;
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc("LoginTimes").ExecuteTypedList <User>();

                var follows = db.Find <Fan>(x => x.CreateUserNumber == UserNumber).ToList();

                var newlist = (from l in list
                               select new
                {
                    ID = l.ID,
                    NickName = l.NickName,
                    Signature = l.Signature,
                    Avatar = l.Avatar,
                    Cover = l.Cover,
                    Number = l.Number,
                    IsFollow = follows.Exists(x => x.ToUserNumber == l.Number) ? 1 : 0
                }).ToList();

                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api/User/Search:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 13
0
        public string ToUser()
        {
            ApiResult result = new ApiResult();

            try
            {
                var UserNumber = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }
                var pager       = new Pager();
                var query       = new SubSonic.Query.Select(provider).From <ArticleZan>().Where <ArticleZan>(x => x.CreateUserNumber == UserNumber);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }

                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <ArticleZan>();

                var articles = new SubSonic.Query.Select(provider, "ID", "Number", "Cover", "ArticlePower", "CreateUserNumber", "Status", "Title").From <Article>().Where("Number").In(list.Select(x => x.ArticleNumber).ToArray()).ExecuteTypedList <Article>();
                var users    = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number", "Cover").From <User>().Where("Number").In(list.Select(x => x.ArticleUserNumber).ToArray()).ExecuteTypedList <User>();

                List <ZanJson> newlist = new List <ZanJson>();
                list.ForEach(x =>
                {
                    var article = articles.FirstOrDefault(y => y.Number == x.ArticleNumber);
                    var user    = users.FirstOrDefault(y => y.Number == x.ArticleUserNumber);
                    if (article != null && user != null)
                    {
                        ZanJson model          = new ZanJson();
                        model.ID               = x.ID;
                        model.CreateDate       = x.CreateDate.ToString("yyyy-MM-dd");
                        model.ArticleID        = article.ID;
                        model.Title            = article.Title;
                        model.Number           = article.Number;
                        model.Cover            = article.Cover;
                        model.ArticlePower     = article.ArticlePower;
                        model.CreateUserNumber = article.CreateUserNumber;
                        model.NickName         = user.NickName;
                        model.Avatar           = user.Avatar;
                        model.UserNumber       = user.Number;
                        model.UserCover        = user.Cover;
                        newlist.Add(model);
                    }
                });
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Zan_ToUser:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 列表
        /// </summary>
        public ActionResult All()
        {
            try
            {
                var pager            = new Pager();
                var query            = new SubSonic.Query.Select(provider).From <Order>().Where <Order>(x => x.Status == Enum_Status.Approved);
                var CreateUserNumber = ZNRequest.GetString("CreateUserNumber");
                var ToUserNumber     = ZNRequest.GetString("ToUserNumber");
                if (!string.IsNullOrWhiteSpace(CreateUserNumber))
                {
                    query = query.And("CreateUserNumber").IsEqualTo(CreateUserNumber);
                }
                if (!string.IsNullOrWhiteSpace(ToUserNumber))
                {
                    query = query.And("ToUserNumber").IsEqualTo(ToUserNumber);
                }
                var recordCount = query.GetRecordCount();

                if (recordCount == 0)
                {
                    return(Json(new
                    {
                        currpage = pager.Index,
                        records = recordCount,
                        totalpage = 1,
                        list = string.Empty
                    }, JsonRequestBehavior.AllowGet));
                }

                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Order>();

                var fromarray = list.Select(x => x.CreateUserNumber).Distinct().ToList();
                var toarray   = list.Select(x => x.ToUserNumber).Distinct().ToList();
                fromarray.AddRange(toarray);
                var allusers = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number", "Cover").From <User>().And("Number").In(fromarray.ToArray()).ExecuteTypedList <User>();

                List <OrderJson> newlist = new List <OrderJson>();
                list.ForEach(x =>
                {
                    var fromUser     = allusers.FirstOrDefault(y => y.Number == x.CreateUserNumber);
                    var toUser       = allusers.FirstOrDefault(y => y.Number == x.ToUserNumber);
                    OrderJson model  = new OrderJson();
                    model.ID         = x.ID;
                    model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd");
                    model.Price      = x.Price;
                    if (fromUser != null)
                    {
                        model.FromUserID     = fromUser.ID;
                        model.FromUserNumber = fromUser.Number;
                        model.FromUserAvatar = fromUser.Avatar;
                        model.FromUserName   = fromUser.NickName;
                        model.FromUserCover  = fromUser.Cover;
                    }
                    if (toUser != null)
                    {
                        model.ToUserID     = toUser.ID;
                        model.ToUserNumber = toUser.Number;
                        model.ToUserAvatar = toUser.Avatar;
                        model.ToUserName   = toUser.NickName;
                        model.ToUserCover  = toUser.Cover;
                    }
                    newlist.Add(model);
                });
                var result = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("OrderController_All:" + ex.Message);
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 15
0
        public string All()
        {
            ApiResult result = new ApiResult();

            try
            {
                var pager = new Pager();
                var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved);

                //昵称
                var title = SqlFilter(ZNRequest.GetString("Title"));
                if (!string.IsNullOrWhiteSpace(title))
                {
                    query.And("Title").Like("%" + title + "%");
                }
                var CreateUserNumber = ZNRequest.GetString("CreateUserNumber");
                if (!string.IsNullOrWhiteSpace(CreateUserNumber))
                {
                    query = query.And("CreateUserNumber").IsEqualTo(CreateUserNumber);
                }

                //其他用户的文章
                var CurrUserNumber = ZNRequest.GetString("CurrUserNumber");
                if (CreateUserNumber != CurrUserNumber || string.IsNullOrWhiteSpace(CreateUserNumber))
                {
                    query = query.And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public);
                    query = query.And("Submission").IsGreaterThan(Enum_Submission.Audit);
                }

                //文章类型
                var TypeID = ZNRequest.GetInt("TypeID");
                if (TypeID > 0)
                {
                    query = query.And("TypeIDList").Like("%-0-" + TypeID.ToString() + "-%");
                }

                //过滤黑名单
                if (!string.IsNullOrWhiteSpace(CurrUserNumber))
                {
                    var black = db.Find <Black>(x => x.CreateUserNumber == CurrUserNumber);
                    if (black.Count > 0)
                    {
                        var userids = black.Select(x => x.ToUserNumber).ToArray();
                        query = query.And("CreateUserNumber").NotIn(userids);
                    }
                }
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;

                var sort = new string[] { "Recommend", "ID" };
                if (CreateUserNumber == CurrUserNumber)
                {
                    sort = new string[] { "ID" };
                }
                var Source = ZNRequest.GetString("Source");
                if (!string.IsNullOrWhiteSpace(Source))
                {
                    sort = new string[] { "Views" };
                }

                var list = query.Paged(pager.Index, pager.Size).OrderDesc(sort).ExecuteTypedList <Article>();
                List <ArticleJson> newlist = ArticleListInfo(list, CurrUserNumber);
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Article_All:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 16
0
        public string SubComment()
        {
            ApiResult result = new ApiResult();

            try
            {
                var pager  = new Pager();
                var Number = ZNRequest.GetString("Number");
                if (string.IsNullOrWhiteSpace(Number))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }
                var UserNumber = ZNRequest.GetString("UserNumber");

                var query       = new SubSonic.Query.Select(provider).From <Comment>().Where <Comment>(x => x.ParentCommentNumber == Number);
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.result  = true;
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }

                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;

                var list                   = query.Paged(pager.Index, pager.Size).OrderAsc("ID").ExecuteTypedList <Comment>();
                var users                  = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number").From <User>().Where("Number").In(list.Select(x => x.CreateUserNumber).Distinct().ToArray()).ExecuteTypedList <User>();
                var parentComments         = new SubSonic.Query.Select(provider, "ID", "ParentCommentNumber", "Number", "CreateUserNumber").From <Comment>().Where("ParentCommentNumber").In(list.Select(x => x.Number).ToArray()).ExecuteTypedList <Comment>();
                var zans                   = db.Find <CommentZan>(x => x.CreateUserNumber == UserNumber).ToList();
                List <CommentJson> newlist = new List <CommentJson>();
                list.ForEach(x =>
                {
                    CommentJson model = new CommentJson();
                    var user          = users.FirstOrDefault(y => y.Number == x.CreateUserNumber);
                    if (user == null)
                    {
                        return;
                    }
                    model.ID             = x.ID;
                    model.Summary        = x.Summary;
                    model.Goods          = x.Goods;
                    model.Number         = x.Number;
                    model.CreateDateText = x.CreateDate.ToString("yyyy-MM-dd");
                    model.ShowPosition   = x.ShowPosition;
                    model.City           = x.City;
                    if (string.IsNullOrWhiteSpace(model.City))
                    {
                        model.ShowPosition = 0;
                    }
                    model.UserID          = user.ID;
                    model.UserNumber      = user.Number;
                    model.NickName        = user.NickName;
                    model.Avatar          = user.Avatar;
                    model.SubCommentCount = parentComments.Count(y => y.ParentCommentNumber == x.Number);
                    if (model.SubCommentCount == 1)
                    {
                        var subuser = db.Single <User>(y => y.Number == parentComments[0].CreateUserNumber);
                        var comment = db.Single <Comment>(y => y.Number == parentComments[0].Number);
                        if (subuser == null && comment == null)
                        {
                            model.SubCommentCount = 0;
                        }
                        if (subuser != null)
                        {
                            model.SubUserName = subuser.NickName;
                        }
                        if (comment != null)
                        {
                            model.SubSummary = comment.Summary;
                        }
                    }
                    model.ArticleNumber = x.ArticleNumber;
                    model.IsZan         = zans.Count(y => y.CommentNumber == x.Number);
                    newlist.Add(model);
                });
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_Comment_SubComment:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 17
0
        public string List()
        {
            ApiResult result = new ApiResult();

            try
            {
                var ActionID   = ZNRequest.GetInt("ActionID");
                var UserNumber = ZNRequest.GetString("UserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = "参数异常";
                    return(JsonConvert.SerializeObject(result));
                }

                //我的关注
                var follows = db.Find <Fan>(x => x.CreateUserNumber == UserNumber).ToList();
                if (follows.Count == 0)
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }

                var pager = new Pager();
                var query = new SubSonic.Query.Select(provider).From <UserAction>().Where("CreateUserNumber").In(follows.Select(x => x.ToUserNumber).ToArray());
                //if (ActionID > 0)
                //{
                //    query = query.And("ID").IsLessThan(ActionID);
                //}
                var recordCount = query.GetRecordCount();
                if (recordCount == 0)
                {
                    result.message = new { records = recordCount, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }

                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                var list      = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <UserAction>();

                var like     = Enum_ActionType.Like;
                var follow   = Enum_ActionType.Follow;
                var keep     = Enum_ActionType.Keep;
                var userList = new List <string>();
                list.ForEach(x =>
                {
                    userList.Add(x.CreateUserNumber);
                });
                var newlist = new List <UserActionJson>();
                if (list.Count > 0)
                {
                    var allUser = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Number").From <User>().Where <User>(y => y.Status == Enum_Status.Approved).And("Number").In(userList.Distinct().ToArray()).ExecuteTypedList <User>();
                    list.ForEach(x =>
                    {
                        var userModel = allUser.FirstOrDefault(y => y.Number == x.CreateUserNumber);
                        if (userModel != null)
                        {
                            UserActionJson action  = new UserActionJson();
                            action.ID              = x.ID;
                            action.Number          = x.CreateUserNumber;
                            action.NickName        = userModel.NickName;
                            action.Avatar          = userModel.Avatar;
                            action.Cover           = userModel.Cover;
                            action.CreateTime      = FormatTime(x.CreateTime);
                            action.ActionType      = x.ActionType;
                            action.ArticleInfoJson = new List <ArticleInfoJson>();
                            action.UserInfoJson    = new List <UserInfoJson>();
                            //喜欢、收藏
                            if (x.ActionType == like || x.ActionType == keep)
                            {
                                var articles = new SubSonic.Query.Select(provider, "ID", "Number", "Cover", "ArticlePower", "CreateUserNumber", "Status", "Title").From <Article>().Where("Number").In(x.ActionInfo.Split(',')).And("Status").IsEqualTo(Enum_Status.Approved).And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public).And("Submission").IsGreaterThan(Enum_Submission.Audit).ExecuteTypedList <Article>();
                                if (articles.Count > 0)
                                {
                                    articles.ForEach(y =>
                                    {
                                        ArticleInfoJson article = new ArticleInfoJson();
                                        article.ID           = y.ID;
                                        article.Title        = y.Title;
                                        article.Number       = y.Number;
                                        article.Cover        = y.Cover;
                                        article.ArticlePower = y.ArticlePower;
                                        action.ArticleInfoJson.Add(article);
                                    });

                                    action.ArticleInfoJson.Reverse();

                                    newlist.Add(action);
                                }
                            }
                            //关注
                            if (x.ActionType == follow)
                            {
                                var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Number").From <User>().Where <User>(y => y.Status == Enum_Status.Approved).And("Number").In(x.ActionInfo.Split(',')).ExecuteTypedList <User>();
                                if (users.Count > 0)
                                {
                                    users.ForEach(y =>
                                    {
                                        UserInfoJson user = new UserInfoJson();
                                        user.ID           = y.ID;
                                        user.NickName     = y.NickName;
                                        user.Number       = y.Number;
                                        user.Avatar       = y.Avatar;
                                        user.Cover        = y.Cover;
                                        action.UserInfoJson.Add(user);
                                    });

                                    action.ArticleInfoJson.Reverse();

                                    newlist.Add(action);
                                }
                            }
                        }
                    });
                }
                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api/UserAction/List:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }
Exemplo n.º 18
0
        public string Article_1_3()
        {
            ApiResult result = new ApiResult();

            try
            {
                var UserNumber     = ZNRequest.GetString("UserNumber");
                var CurrUserNumber = ZNRequest.GetString("CurrUserNumber");
                if (string.IsNullOrWhiteSpace(UserNumber))
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var pager = new Pager();
                //日期分组
                var datequery = new SubSonic.Query.Select(provider, "ID", "CreateDate", "ArticlePower").From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.CreateUserNumber == UserNumber);
                if (UserNumber != CurrUserNumber)
                {
                    datequery = datequery.And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public);
                    datequery = datequery.And("Submission").IsGreaterThan(Enum_Submission.Audit);
                }
                var datelist    = datequery.ExecuteTypedList <Article>();
                var newdatelist = new List <DateTime>();
                datelist.OrderByDescending(x => x.ID).GroupBy(x => x.CreateDate.ToString("yyyy-MM")).ToList().ForEach(x =>
                {
                    newdatelist.Add(x.FirstOrDefault().CreateDate);
                });

                var recordCount = newdatelist.Count();
                if (recordCount == 0)
                {
                    result.message = new { records = 0, totalpage = 1 };
                    return(JsonConvert.SerializeObject(result));
                }
                var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1;
                newdatelist = newdatelist.Skip((pager.Index - 1) * pager.Size).Take(pager.Size).ToList();

                //获取数据
                var query = new SubSonic.Query.Select(provider, "ID", "Number", "CreateUserNumber", "Cover", "ArticlePower", "Status", "CreateDate").From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.CreateUserNumber == UserNumber);
                if (UserNumber != CurrUserNumber)
                {
                    query = query.And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public);
                    query = query.And("Submission").IsGreaterThan(Enum_Submission.Audit);
                }

                recordCount = query.GetRecordCount();

                query.And("CreateDate").IsGreaterThanOrEqualTo(newdatelist[newdatelist.Count - 1].ToString("yyyy-MM-01 00:00:00"));
                var day = DateTime.DaysInMonth(newdatelist[0].Year, newdatelist[0].Month);;

                query.And("CreateDate").IsLessThanOrEqualTo(newdatelist[0].ToString("yyyy-MM-" + day + " 23:59:59"));
                var list = query.ExecuteTypedList <Article>();

                var newlist = new List <UserArticleJson>();

                //组织输出
                newdatelist.ForEach(x =>
                {
                    UserArticleJson model = new UserArticleJson();
                    model.List            = new List <UserArticleSubJson>();
                    var items             = list.FindAll(y => y.CreateDate.Year == x.Year && y.CreateDate.Month == x.Month);
                    items.ForEach(y =>
                    {
                        UserArticleSubJson item = new UserArticleSubJson();
                        item.ID               = y.ID;
                        item.Number           = y.Number;
                        item.CreateUserNumber = y.CreateUserNumber;
                        item.Cover            = y.Cover;
                        item.ArticlePower     = y.ArticlePower;
                        model.List.Add(item);
                    });
                    model.CreateDate = x.Year + "年" + x.Month + "月";
                    model.Count      = model.List.Count;
                    newlist.Add(model);
                });

                result.result  = true;
                result.message = new
                {
                    currpage  = pager.Index,
                    records   = recordCount,
                    totalpage = totalPage,
                    list      = newlist
                };
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("Api_User_Article_1_3:" + ex.Message);
                result.message = ex.Message;
            }
            return(JsonConvert.SerializeObject(result));
        }