Exemplo n.º 1
0
        /// <summary>
        /// 获取消息
        /// </summary>
        /// <param name="messageType">消息分类</param>
        /// <param name="action">消息动作</param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static PageSetVM MessageQuery(int UserId, EnumAid.MessageType?messageType, int?action, int page = 1)
        {
            using (var db = new ContextBase())
            {
                var query = from a in db.UserMessage
                            join b in db.UserInfo on a.UmTriggerUid equals b.UserId into bg
                            from b1 in bg.DefaultIfEmpty()
                            orderby a.UmCreateTime descending
                            where a.Uid == UserId
                            select new
                {
                    a,
                    b1.Nickname,
                    b1.UserPhoto
                };
                if (messageType.HasValue)
                {
                    query = query.Where(x => x.a.UmType == messageType.ToString());
                }
                if (action.HasValue)
                {
                    query = query.Where(x => x.a.UmAction == action);
                }

                var pag = new PaginationVM
                {
                    PageNumber = Math.Max(page, 1),
                    PageSize   = 10
                };

                pag.Total = query.Count();
                var list = query.Skip((pag.PageNumber - 1) * pag.PageSize).Take(pag.PageSize).ToList();

                if (list.Count > 0)
                {
                    //分类:根据ID查询对应的标题
                    var listUwId = list.Where(x => x.a.UmType == EnumAid.MessageType.UserWriting.ToString()).Select(x => Convert.ToInt32(x.a.UmTargetId)).ToList();
                    var listUw   = db.UserWriting.Where(x => listUwId.Contains(x.UwId)).Select(x => new { x.UwId, x.UwTitle }).ToList();

                    foreach (var item in list)
                    {
                        item.a.Spare1 = item.Nickname;
                        item.a.Spare2 = item.UserPhoto;
                        item.a.Spare3 = listUw.FirstOrDefault(x => x.UwId.ToString() == item.a.UmTargetId)?.UwTitle;
                    }
                }

                var data = list.Select(x => x.a).ToList();

                PageSetVM pageSet = new PageSetVM()
                {
                    Rows = data,
                    Pag  = pag
                };

                return(pageSet);
            }
        }
Exemplo n.º 2
0
        public IActionResult List(int page = 1)
        {
            if (int.TryParse(RouteData.Values["Id"]?.ToString(), out int wid))
            {
                var uwo = Func.Common.UserWritingOneQuery(wid);
                if (uwo == null)
                {
                    return(Redirect("/"));
                }

                var pag = new PaginationVM
                {
                    PageNumber = Math.Max(page, 1),
                    PageSize   = 10
                };

                var vm = new PageSetVM()
                {
                    Rows  = Func.Common.ReplyOneQuery(Func.EnumAid.ReplyType.UserWriting, wid.ToString(), pag),
                    Pag   = pag,
                    Temp  = uwo,
                    Route = "/home/list/" + wid.ToString()
                };


                if (User.Identity.IsAuthenticated)
                {
                    var uinfo = new Func.UserAuthAid(HttpContext).Get();
                    using (var db = new ContextBase())
                    {
                        var listuc = db.UserConnection.Where(x => x.Uid == uinfo.UserId && x.UconnTargetType == Func.EnumAid.ConnectionType.UserWriting.ToString() && x.UconnTargetId == wid.ToString()).ToList();

                        ViewData["uca1"] = listuc.Any(x => x.UconnAction == 1) ? "yes" : "";
                        ViewData["uca2"] = listuc.Any(x => x.UconnAction == 2) ? "yes" : "";
                    }
                }

                return(View(vm));
            }
            else
            {
                return(Redirect("/"));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draw查询
        /// </summary>
        /// <param name="q">搜索</param>
        /// <param name="OwnerId">所属用户</param>
        /// <param name="UserId">登录用户</param>
        /// <param name="page">页码</param>
        /// <returns></returns>
        public static PageSetVM DrawQuery(string q, int OwnerId = 0, int UserId = 0, int page = 1)
        {
            using (var db = new ContextBase())
            {
                var query = from a in db.Draw
                            join b in db.UserInfo on a.Uid equals b.UserId
                            where a.DrStatus == 1
                            orderby a.DrCreateTime descending
                            select new Draw
                {
                    DrId         = a.DrId,
                    Uid          = a.Uid,
                    DrType       = a.DrType,
                    DrName       = a.DrName,
                    DrRemark     = a.DrRemark,
                    DrCategory   = a.DrCategory,
                    DrOrder      = a.DrOrder,
                    DrCreateTime = a.DrCreateTime,
                    DrStatus     = a.DrStatus,
                    DrOpen       = a.DrOpen,

                    Spare3 = b.Nickname
                };

                //所属用户
                if (OwnerId != 0)
                {
                    query = query.Where(x => x.Uid == OwnerId);
                }

                //未登录
                if (UserId == 0)
                {
                    query = query.Where(x => x.DrOpen == 1);
                }
                else
                {
                    //已登录:公开&登录用户的所有
                    query = query.Where(x => x.DrOpen == 1 || x.Uid == UserId);
                }

                if (!string.IsNullOrWhiteSpace(q))
                {
                    query = query.Where(x => x.DrName.Contains(q) || x.DrRemark.Contains(q));
                }

                var pag = new PaginationVM
                {
                    PageNumber = Math.Max(page, 1),
                    PageSize   = 20
                };

                var dicQs = new Dictionary <string, string>
                {
                    { "q", q }
                };

                pag.Total = query.Count();
                var list = query.Skip((pag.PageNumber - 1) * pag.PageSize).Take(pag.PageSize).ToList();

                PageSetVM pageSet = new PageSetVM()
                {
                    Rows        = list,
                    Pag         = pag,
                    QueryString = dicQs
                };

                return(pageSet);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gist查询,按列权重排序
        /// </summary>
        /// <param name="q">搜索</param>
        /// <param name="lang">语言</param>
        /// <param name="OwnerId">所属用户</param>
        /// <param name="UserId">登录用户</param>
        /// <param name="page">页码</param>
        /// <returns></returns>
        public static PageSetVM GistQuery(string q, string lang, int OwnerId = 0, int UserId = 0, int page = 1)
        {
            using (var db = new ContextBase())
            {
                var query1 = from a in db.Gist
                             join b in db.UserInfo on a.Uid equals b.UserId
                             where a.GistStatus == 1
                             orderby a.GistCreateTime descending
                             select new
                {
                    a,
                    b.Nickname
                };

                if (!string.IsNullOrWhiteSpace(lang))
                {
                    query1 = query1.Where(x => x.a.GistLanguage == lang);
                }

                if (!string.IsNullOrWhiteSpace(q))
                {
                    query1 = query1.Where(x => x.a.GistFilename.Contains(q) || x.a.GistContent.Contains(q) || x.a.GistRemark.Contains(q));
                }

                //所属用户
                if (OwnerId != 0)
                {
                    query1 = query1.Where(x => x.a.Uid == OwnerId);
                }

                //未登录
                if (UserId == 0)
                {
                    query1 = query1.Where(x => x.a.GistOpen == 1);
                }
                else
                {
                    //已登录:公开&登录用户的所有
                    query1 = query1.Where(x => x.a.GistOpen == 1 || x.a.Uid == UserId);
                }

                var query2 = query1.Select(x => new
                {
                    SearchOrder = (x.a.GistFilename.Contains(q) ? 4 : 0) + (x.a.GistContent.Contains(q) ? 2 : 0) + (x.a.GistRemark.Contains(q) ? 1 : 0),
                    x.Nickname,
                    x.a
                });

                var query = query2.OrderByDescending(x => x.SearchOrder).Select(x => new Gist
                {
                    GistCode           = x.a.GistCode,
                    GistContentPreview = x.a.GistContentPreview,
                    GistCreateTime     = x.a.GistCreateTime,
                    GistFilename       = x.a.GistFilename,
                    GistId             = x.a.GistId,
                    GistLanguage       = x.a.GistLanguage,
                    GistRemark         = x.a.GistRemark,
                    GistRow            = x.a.GistRow,
                    GistTags           = x.a.GistTags,
                    GistTheme          = x.a.GistTheme,
                    Uid = x.a.Uid,

                    Spare3 = x.Nickname
                });

                var pag = new PaginationVM
                {
                    PageNumber = Math.Max(page, 1),
                    PageSize   = 10
                };

                var dicQs = new Dictionary <string, string>
                {
                    { "q", q }
                };

                pag.Total = query.Count();
                var list = query.Skip((pag.PageNumber - 1) * pag.PageSize).Take(pag.PageSize).ToList();

                PageSetVM pageSet = new PageSetVM()
                {
                    Rows        = list,
                    Pag         = pag,
                    QueryString = dicQs
                };

                return(pageSet);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取关联的文章列表
        /// </summary>
        /// <param name="OwnerId">所属用户关联</param>
        /// <param name="connectionType">关联分类</param>
        /// <param name="action">动作</param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static PageSetVM UserConnWritingQuery(int OwnerId, EnumAid.ConnectionType connectionType, int action, int page)
        {
            var pag = new PaginationVM
            {
                PageNumber = Math.Max(page, 1),
                PageSize   = 20
            };

            using (var db = new ContextBase())
            {
                IQueryable <UserWriting> query = null;

                switch (connectionType)
                {
                case EnumAid.ConnectionType.UserWriting:
                {
                    query = from a in db.UserConnection
                            join b in db.UserWriting on a.UconnTargetId equals b.UwId.ToString()
                                where a.Uid == OwnerId && a.UconnTargetType == connectionType.ToString() && a.UconnAction == action
                            orderby a.UconnCreateTime descending
                            select b;
                }
                break;
                }

                if (query == null)
                {
                    return(null);
                }

                pag.Total = query.Count();

                query = query.Skip((pag.PageNumber - 1) * pag.PageSize).Take(pag.PageSize);

                var list = query.ToList();

                //文章ID
                var listUwId = list.Select(x => x.UwId).ToList();

                //文章的所有的标签
                var listUwTags = (from a in db.Tags
                                  join b in db.UserWritingTags on a.TagName equals b.TagName
                                  where listUwId.Contains(b.UwId)
                                  select new
                {
                    b.UwId,
                    b.TagName,
                    a.TagIcon
                }).ToList();

                //文章人员ID
                var listUwUid = list.Select(x => x.UwLastUid).Concat(list.Select(x => x.Uid)).Distinct();

                //文章人员ID对应的信息
                var listUwUserInfo = db.UserInfo.Where(x => listUwUid.Contains(x.UserId)).Select(x => new { x.UserId, x.Nickname }).ToList();

                //把信息赋值到文章表的备用字段上
                foreach (var item in list)
                {
                    //标签
                    item.Spare1 = listUwTags.Where(x => x.UwId == item.UwId).Select(x => new { x.TagName, x.TagIcon }).ToJson();

                    if (item.UwLastUid > 0)
                    {
                        item.Spare2 = listUwUserInfo.FirstOrDefault(x => x.UserId == item.UwLastUid)?.Nickname;
                        item.Spare3 = item.UwLastUid.ToString();
                    }
                    if (string.IsNullOrWhiteSpace(item.Spare2))
                    {
                        item.Spare2 = listUwUserInfo.FirstOrDefault(x => x.UserId == item.Uid)?.Nickname;
                        item.Spare3 = item.Uid.ToString();
                    }
                }

                var vm = new PageSetVM()
                {
                    Rows = list,
                    Pag  = pag
                };

                return(vm);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取文章列表
        /// </summary>
        /// <param name="KeyWords"></param>
        /// <param name="page"></param>
        /// <param name="TagName"></param>
        /// <returns></returns>
        public static PageSetVM UserWritingQuery(string KeyWords, int page, string TagName = "")
        {
            KeyWords = KeyWords ?? "";

            var pag = new PaginationVM
            {
                PageNumber = Math.Max(page, 1),
                PageSize   = 20
            };

            var dicQs = new Dictionary <string, string>
            {
                { "k", KeyWords }
            };

            using (var db = new ContextBase())
            {
                IQueryable <UserWriting> query;

                if (!string.IsNullOrWhiteSpace(TagName))
                {
                    query = from a in db.UserWritingTags.Where(x => x.TagName == TagName)
                            join b in db.UserWriting on a.UwId equals b.UwId
                            select b;
                    query = query.Distinct();
                }
                else
                {
                    query = from a in db.UserWriting select a;
                }

                query = query.Where(x => x.UwOpen == 1 && x.UwStatus == 1);

                if (!string.IsNullOrWhiteSpace(KeyWords))
                {
                    query = query.Where(x => x.UwTitle.Contains(KeyWords));
                }

                pag.Total = query.Count();

                query = query.OrderByDescending(x => x.UwId).Skip((pag.PageNumber - 1) * pag.PageSize).Take(pag.PageSize);

                var list = query.ToList();

                //文章ID
                var listUwId = list.Select(x => x.UwId).ToList();

                //文章的所有的标签
                var listUwTags = (from a in db.Tags
                                  join b in db.UserWritingTags on a.TagName equals b.TagName into bg
                                  from b in bg.DefaultIfEmpty()
                                  where listUwId.Contains(b.UwId) || a.TagName == TagName
                                  select new
                {
                    UwId = b == null ? 0 : b.UwId,
                    TagName = b == null ? TagName : b.TagName,
                    a.TagIcon
                }).ToList();

                //文章人员ID
                var listUwUid = list.Select(x => x.UwLastUid).Concat(list.Select(x => x.Uid)).Distinct();

                //文章人员ID对应的信息
                var listUwUserInfo = db.UserInfo.Where(x => listUwUid.Contains(x.UserId)).Select(x => new { x.UserId, x.Nickname }).ToList();

                //把信息赋值到文章表的备用字段上
                foreach (var item in list)
                {
                    //标签
                    item.Spare1 = listUwTags.Where(x => x.UwId == item.UwId).Select(x => new { x.TagName, x.TagIcon }).ToJson();

                    if (item.UwLastUid > 0)
                    {
                        item.Spare2 = listUwUserInfo.FirstOrDefault(x => x.UserId == item.UwLastUid)?.Nickname;
                        item.Spare3 = item.UwLastUid.ToString();
                    }
                    if (string.IsNullOrWhiteSpace(item.Spare2))
                    {
                        item.Spare2 = listUwUserInfo.FirstOrDefault(x => x.UserId == item.Uid)?.Nickname;
                        item.Spare3 = item.Uid.ToString();
                    }
                }

                var vm = new PageSetVM()
                {
                    Rows        = list,
                    Pag         = pag,
                    QueryString = dicQs
                };

                if (!string.IsNullOrWhiteSpace(TagName))
                {
                    try
                    {
                        var jt = KeyValuesQuery(new List <string> {
                            TagName
                        }).FirstOrDefault().KeyValue.ToJObject();

                        var tags = new List <object>
                        {
                            new
                            {
                                TagName,
                                listUwTags.FirstOrDefault(x => x.TagName == TagName)?.TagIcon
                            }
                        };

                        vm.Temp = new
                        {
                            abs = new List <string>
                            {
                                jt["abstract"].ToString(),
                                jt["url"].ToString()
                            },
                            tags
                        }.ToJson();
                    }
                    catch (Exception)
                    {
                    }
                }

                return(vm);
            }
        }