示例#1
0
        public List <RequestFriendModel> GetRequestFriend(long UserId)
        {
            var ListRequestFriend = new List <RequestFriendModel>();
            var result            = (from c in context.Relationships
                                     join p1 in context.Users on c.UserSentID equals p1.ID into ps1
                                     from p1 in ps1.DefaultIfEmpty()
                                     join p2 in context.Groups on c.UserSentID equals p2.ID into ps2
                                     from p2 in ps2.DefaultIfEmpty()
                                     where c.UserReceiveID == UserId && c.Status == StatusRequestFriend.SENDING
                                     orderby c.CreatedTime descending
                                     select new RequestFriendModel
            {
                TargetId = p1 != null ? p1.ID : p2.ID,
                Avatar = p1 != null ? p1.Avatar : p2.Avatar,
                NickName = p1 != null ? p1.NickName : p2.GroupName,
                Type = p1 != null ? TypeRequestFriend.USER : TypeRequestFriend.GROUP,
                Id = c.ID
            }).ToList();

            foreach (var item in result)
            {
                var respone = AmazonS3Uploader.GetUrl(item.Avatar, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    item.Avatar = respone;
                }
            }
            return(result);
        }
示例#2
0
        public List <GroupModel> GetListGroup(long Id)
        {
            var result = (from c in context.GroupMembers
                          where c.Status == StatusMember.ACCEPT && c.UserId == Id
                          join p1 in context.Groups on c.GroupID equals p1.ID into ps1
                          from p1 in ps1.DefaultIfEmpty()
                          orderby c.CreatedTime descending
                          select new GroupModel
            {
                CreatedTime = c.CreatedTime,
                Avatar = p1.Avatar,
                GroupName = p1.GroupName,
                Banner = p1.Banner,
                ID = p1.ID,
                InfoId = p1.InfoId,
                CreatedUser = p1.CreatedUser,
                Status = p1.Status,
                TypeMember = c.Type
            }).ToList();

            foreach (var item in result)
            {
                var respone = AmazonS3Uploader.GetUrl(item.Avatar, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    item.Avatar = respone;
                }
                respone = AmazonS3Uploader.GetUrl(item.Banner, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    item.Banner = respone;
                }
            }
            return(result);
        }
示例#3
0
        public List <PostViewModel> GetListImage(long Id)
        {
            var result = (from c in context.Posts
                          where (c.TargetId != null && c.TargetId == Id) && c.TargetType == TypePost.USER && !string.IsNullOrEmpty(c.Images)
                          orderby c.CreatedTime descending
                          select new{ c }).Take(6).ToList();
            var PostView = new List <PostViewModel>();

            foreach (var item in result)
            {
                var Post = new PostViewModel();
                Post.Id     = item.c.ID;
                Post.Images = item.c.Images;
                if (!string.IsNullOrEmpty(item.c.Images))
                {
                    var data = item.c.Images.Split(',');
                    Post.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListImages.Add(respone);
                        }
                    }
                }
                PostView.Add(Post);
            }
            return(PostView);
        }
示例#4
0
        public List <FriendModel> SearchFriend(long UserId, string query)
        {
            var ListFriend = new List <FriendModel>();
            var result     = (from c in context.Users
                              where c.NickName.Contains(query) || c.SubName.Contains(query)
                              orderby c.NickName descending
                              select new { c }).Take(200).ToList();

            foreach (var item in result)
            {
                var Friend = new FriendModel();
                Friend.Avatar      = item.c.Avatar;
                Friend.NickName    = item.c.NickName;
                Friend.Id          = item.c.ID;
                Friend.Type        = TypeRequestFriend.USER;
                Friend.CreatedTime = item.c.CreatedTime;
                var respone = AmazonS3Uploader.GetUrl(item.c.Avatar, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    Friend.Avatar = respone;
                }
                ListFriend.Add(Friend);
            }
            return(ListFriend);
        }
示例#5
0
        public List <MemberModel> GetMemberSending(long UserId, string date)
        {
            DateTime createDate = DateTime.UtcNow;

            if (!string.IsNullOrEmpty(date))
            {
                createDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                createDate = createDate.AddMilliseconds(double.Parse(date)).ToLocalTime();
            }
            var result = (from c in context.GroupMembers
                          join p1 in context.Users on c.UserId equals p1.ID into ps1
                          from p1 in ps1.DefaultIfEmpty()
                          where c.CreatedTime < createDate && c.Status == StatusMember.SENDING && c.GroupID == UserId
                          orderby c.CreatedTime descending
                          select new MemberModel
            {
                CreatedTime = c.CreatedTime,
                Avatar = p1.Avatar,
                NickName = p1.NickName,
                Type = c.Type,
                Id = p1.ID
            }).Take(10).ToList();

            foreach (var item in result)
            {
                var respone = AmazonS3Uploader.GetUrl(item.Avatar, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    item.Avatar = respone;
                }
            }
            return(result);
        }
示例#6
0
        public MemberModel GetMemberGroupByID(long id, long groupId)
        {
            var result = (from c in context.GroupMembers
                          join p1 in context.Users on c.UserId equals p1.ID into ps1
                          from p1 in ps1.DefaultIfEmpty()
                          where c.Status == StatusMember.ACCEPT && c.GroupID == groupId && c.UserId == id
                          orderby c.CreatedTime descending
                          select new MemberModel
            {
                CreatedTime = c.CreatedTime,
                Avatar = p1.Avatar,
                NickName = p1.NickName,
                Type = c.Type,
                Id = p1.ID
            }).FirstOrDefault();

            if (!string.IsNullOrEmpty(result?.Avatar))
            {
                var respone = AmazonS3Uploader.GetUrl(result.Avatar, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    result.Avatar = respone;
                }
            }
            return(result);
        }
示例#7
0
        public ActionResult CreatedAudio(HttpPostedFileBase file)
        {
            var url     = string.Empty;
            var respons = AmazonS3Uploader.UploadFileStream(file.InputStream, TypeUpload.AUDIO);

            if (!string.IsNullOrEmpty(respons))
            {
                url = AmazonS3Uploader.GetUrl(respons);
            }
            Response.StatusCode = (int)HttpStatusCode.OK;
            return(Json(new { result = Constant.SUCCESS, data = url, key = respons }));
        }
示例#8
0
        public Group GetLastGroups()
        {
            var result  = context.Groups.OrderByDescending(x => x.CreatedTime).FirstOrDefault();
            var respone = AmazonS3Uploader.GetUrl(result.Avatar, 0);

            if (!string.IsNullOrEmpty(respone))
            {
                result.Avatar = respone;
            }
            respone = AmazonS3Uploader.GetUrl(result.Banner, 0);
            if (!string.IsNullOrEmpty(respone))
            {
                result.Banner = respone;
            }
            return(result);
        }
示例#9
0
        public Group GetGroupByID(long id)
        {
            var result  = context.Groups.Find(id);
            var respone = AmazonS3Uploader.GetUrl(result.Avatar, 0);

            if (!string.IsNullOrEmpty(respone))
            {
                result.Avatar = respone;
            }
            respone = AmazonS3Uploader.GetUrl(result.Banner, 0);
            if (!string.IsNullOrEmpty(respone))
            {
                result.Banner = respone;
            }
            return(result);
        }
示例#10
0
        public User GetUserByID(long id)
        {
            var result  = context.Users.Find(id);
            var respone = AmazonS3Uploader.GetUrl(result.Avatar, 0);

            if (!string.IsNullOrEmpty(respone))
            {
                result.Avatar = respone;
            }
            respone = AmazonS3Uploader.GetUrl(result.BackGround, 0);
            if (!string.IsNullOrEmpty(respone))
            {
                result.BackGround = respone;
            }
            return(result);
        }
示例#11
0
        public User GetUserByName(string UserName)
        {
            var result  = context.Users.Where(x => x.UserName == UserName).FirstOrDefault();
            var respone = AmazonS3Uploader.GetUrl(result.Avatar, 0);

            if (!string.IsNullOrEmpty(respone))
            {
                result.Avatar = respone;
            }
            respone = AmazonS3Uploader.GetUrl(result.BackGround, 0);
            if (!string.IsNullOrEmpty(respone))
            {
                result.BackGround = respone;
            }
            return(result);
        }
示例#12
0
        public List <FriendModel> GetFriend(long UserId)
        {
            var ListFriend = new List <FriendModel>();
            var result     = (from c in context.Relationships
                              join p1 in context.Users on c.UserReceiveID equals p1.ID into ps1
                              from p1 in ps1.DefaultIfEmpty()
                              join p2 in context.Users on c.UserSentID equals p2.ID into ps2
                              from p2 in ps2.DefaultIfEmpty()
                              where (c.UserReceiveID == UserId || c.UserSentID == UserId) && c.Status == StatusRequestFriend.ACCEPT
                              orderby c.CreatedTime descending
                              select new { c, p1, p2 }).ToList();

            foreach (var item in result)
            {
                var Friend = new FriendModel();
                if (item.p1.ID == UserId)
                {
                    Friend.Avatar      = item.p2.Avatar;
                    Friend.NickName    = item.p2.NickName;
                    Friend.Id          = item.p2.ID;
                    Friend.CreatedTime = item.c.CreatedTime;
                    var respone = AmazonS3Uploader.GetUrl(item.p2.Avatar, 0);
                    if (!string.IsNullOrEmpty(respone))
                    {
                        Friend.Avatar = respone;
                    }
                }
                else
                {
                    Friend.Avatar      = item.p1.Avatar;
                    Friend.NickName    = item.p1.NickName;
                    Friend.Id          = item.p1.ID;
                    Friend.CreatedTime = item.c.CreatedTime;
                    var respone = AmazonS3Uploader.GetUrl(item.p1.Avatar, 0);
                    if (!string.IsNullOrEmpty(respone))
                    {
                        Friend.Avatar = respone;
                    }
                }
                ListFriend.Add(Friend);
            }
            return(ListFriend);
        }
示例#13
0
        public List <CommentViewModel> LoadCommentsPost(string PostIds, string date, int quantity, long LoginUser)
        {
            DateTime createDate = DateTime.UtcNow;

            if (!string.IsNullOrEmpty(date))
            {
                createDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                createDate = createDate.AddMilliseconds(double.Parse(date)).ToLocalTime();
            }
            var CommentView = new List <CommentViewModel>();

            if (String.IsNullOrEmpty(PostIds))
            {
                return(CommentView);
            }
            List <string> LPostsId = PostIds.Split(',').ToList();

            for (var i = 0; i < LPostsId.Count; i++)
            {
                var resultMost = new List <CommentViewModel>();
                var result     = new List <CommentViewModel>();
                var PostId     = Int64.Parse(LPostsId[i]);
                if (string.IsNullOrEmpty(date))
                {
                    resultMost = (from c in context.Comments
                                  join p4 in context.Users on c.UserId equals p4.ID into ps4
                                  from p4 in ps4.DefaultIfEmpty()
                                  join p5 in context.Comments on new { a1 = c.ID, a2 = TypeComment.COMMENT } equals new { a1 = p5.TargetId, a2 = p5.TargetType.Value } into ps5
                                  join p6 in context.Emotions on new { t1 = LoginUser, t2 = c.ID } equals new { t1 = p6.UserId.Value, t2 = p6.TargetId.Value } into ps6
                                  from p6 in ps6.DefaultIfEmpty()
                                  let countEmotions = (from E in context.Emotions where E.TargetId == c.ID select E).Count()
                                                      where PostId == c.TargetId && c.CreatedTime < createDate && c.TargetType == TypeComment.POST && countEmotions > 100
                                                      orderby countEmotions ascending
                                                      select new CommentViewModel
                    {
                        Id = c.ID,
                        Audios = c.Audios,
                        TargetId = c.TargetId,
                        CreatedTime = c.CreatedTime,
                        Images = c.Images,
                        Tags = c.Tags,
                        TagsUser = c.TagsUser,
                        Content = c.Content,
                        UserId = c.UserId,
                        Avatar = p4.Avatar,
                        NickName = p4.NickName,
                        CountReply = ps5.Count(),
                        CountEmotions = countEmotions,
                        StatusEmotion = p6 == null ? (byte)0 : p6.Status
                    }).Take(quantity + 1).ToList();
                }
                if (resultMost.Count == 0)
                {
                    result = (from c in context.Comments
                              join p4 in context.Users on c.UserId equals p4.ID into ps4
                              from p4 in ps4.DefaultIfEmpty()
                              join p5 in context.Comments on new { a1 = c.ID, a2 = TypeComment.COMMENT } equals new { a1 = p5.TargetId, a2 = p5.TargetType.Value } into ps5
                              join p6 in context.Emotions on new { t1 = LoginUser, t2 = c.ID } equals new { t1 = p6.UserId.Value, t2 = p6.TargetId.Value } into ps6
                              from p6 in ps6.DefaultIfEmpty()
                              let countEmotions = (from E in context.Emotions where E.TargetId == c.ID select E).Count()
                                                  where PostId == c.TargetId && c.CreatedTime < createDate && c.TargetType == TypeComment.POST
                                                  orderby c.CreatedTime descending
                                                  select new CommentViewModel
                    {
                        Id = c.ID,
                        Audios = c.Audios,
                        TargetId = c.TargetId,
                        CreatedTime = c.CreatedTime,
                        Images = c.Images,
                        Tags = c.Tags,
                        TagsUser = c.TagsUser,
                        Content = c.Content,
                        UserId = c.UserId,
                        Avatar = p4.Avatar,
                        NickName = p4.NickName,
                        CountReply = ps5.Count(),
                        CountEmotions = countEmotions,
                        StatusEmotion = p6 == null ? (byte)0 : p6.Status
                    }).Take(quantity + 1).ToList();
                    if (result.Count > quantity)
                    {
                        result[result.Count - 2].MoreComment = true;
                        result.RemoveAt(result.Count - 1);
                    }
                }
                else
                {
                    if (result.Count > quantity)
                    {
                        result[result.Count - 2].MoreComment = true;
                        result.RemoveAt(result.Count - 1);
                    }
                    else
                    {
                        result[result.Count - 1].MoreComment = true;
                    }
                }
                CommentView = CommentView.Union(result).ToList();
            }
            foreach (var item in CommentView)
            {
                var responeImage = AmazonS3Uploader.GetUrl(item.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    item.Avatar = responeImage;
                }
                if (!string.IsNullOrEmpty(item.Images))
                {
                    var data = item.Images.Split(',');
                    item.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            item.ListImages.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.Audios))
                {
                    var data = item.Audios.Split(',');
                    item.ListAudios = new List <string>();
                    foreach (string audio in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(audio);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            item.ListAudios.Add(respone);
                        }
                    }
                }
            }
            return(CommentView);
        }
示例#14
0
        public List <MessageViewModel> LoadMessages(string date, long UserId, long TargetId)
        {
            DateTime createDate = DateTime.UtcNow;

            if (!string.IsNullOrEmpty(date))
            {
                createDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                createDate = createDate.AddMilliseconds(double.Parse(date)).ToLocalTime();
            }
            var result = (from c in context.Messages
                          join p1 in context.Users on UserId equals p1.ID into ps1
                          from p1 in ps1.DefaultIfEmpty()
                          join p2 in context.Users on TargetId equals p2.ID into ps2
                          from p2 in ps2.DefaultIfEmpty()
                          where c.CreatedTime < createDate && ((c.TargetUser == TargetId && c.UserID == UserId) || (c.TargetUser == UserId && c.UserID == TargetId))
                          orderby c.CreatedTime descending
                          select new { c, p1, p2 }).Take(10).ToList();
            var MessageView = new List <MessageViewModel>();

            foreach (var item in result)
            {
                var Message = new MessageViewModel();
                Message.Id      = item.c.ID;
                Message.Audios  = item.c.Audios;
                Message.Content = item.c.Content;
                Message.Image   = item.c.Image;
                if (!string.IsNullOrEmpty(item.c.Image))
                {
                    var data = item.c.Image.Split(',');
                    Message.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Message.ListImages.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.c.Audios))
                {
                    var data = item.c.Audios.Split(',');
                    Message.ListAudios = new List <string>();
                    foreach (string audio in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(audio);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Message.ListAudios.Add(respone);
                        }
                    }
                }
                Message.Other       = item.c.Other;
                Message.Seen        = item.c.Seen;
                Message.TargetUser  = item.c.TargetUser;
                Message.UserId      = item.c.UserID;
                Message.CreatedTime = item.c.CreatedTime;
                var responeImage = AmazonS3Uploader.GetUrl(item.p2?.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Message.AvataTarget = responeImage;
                }
                responeImage = AmazonS3Uploader.GetUrl(item.p1?.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Message.AvataUser = responeImage;
                }
                Message.NickNameTarget = item.p2?.NickName;
                Message.NickNameUser   = item.p1?.NickName;
                MessageView.Add(Message);
            }
            return(MessageView);
        }
示例#15
0
        public CommentViewModel GetCommentByID(long id, long LoginUser)
        {
            var CommentView = new CommentViewModel();
            var result      = (from c in context.Comments
                               join p4 in context.Users on c.UserId equals p4.ID into ps4
                               from p4 in ps4.DefaultIfEmpty()
                               join p5 in context.Comments on new { a1 = c.ID, a2 = TypeComment.COMMENT } equals new { a1 = p5.TargetId, a2 = p5.TargetType.Value } into ps5
                               join p6 in context.Emotions on new { t1 = LoginUser, t2 = c.ID } equals new { t1 = p6.UserId.Value, t2 = p6.TargetId.Value } into ps6
                               from p6 in ps6.DefaultIfEmpty()
                               let countEmotions = (from E in context.Emotions where E.TargetId == c.ID select E).Count()
                                                   where id == c.ID
                                                   orderby c.CreatedTime descending
                                                   select new CommentViewModel
            {
                Id = c.ID,
                Audios = c.Audios,
                TargetId = c.TargetId,
                CreatedTime = c.CreatedTime,
                Images = c.Images,
                Tags = c.Tags,
                TagsUser = c.TagsUser,
                Content = c.Content,
                UserId = c.UserId,
                Avatar = p4.Avatar,
                NickName = p4.NickName,
                CountReply = ps5.Count(),
                CountEmotions = countEmotions,
                StatusEmotion = p6 == null ? (byte)0 : p6.Status
            }).FirstOrDefault();

            CommentView = result;
            var responeImage = AmazonS3Uploader.GetUrl(CommentView.Avatar, 0);

            if (!string.IsNullOrEmpty(responeImage))
            {
                CommentView.Avatar = responeImage;
            }
            if (!string.IsNullOrEmpty(CommentView.Images))
            {
                var data = CommentView.Images.Split(',');
                CommentView.ListImages = new List <string>();
                foreach (string image in data)
                {
                    var respone = AmazonS3Uploader.GetUrl(image);
                    if (!string.IsNullOrEmpty(respone))
                    {
                        CommentView.ListImages.Add(respone);
                    }
                }
            }
            if (!string.IsNullOrEmpty(CommentView.Audios))
            {
                var data = CommentView.Audios.Split(',');
                CommentView.ListAudios = new List <string>();
                foreach (string audio in data)
                {
                    var respone = AmazonS3Uploader.GetUrl(audio);
                    if (!string.IsNullOrEmpty(respone))
                    {
                        CommentView.ListAudios.Add(respone);
                    }
                }
            }
            return(CommentView);
        }
示例#16
0
        public List <CommentViewModel> LoadCommentsReply(string CommentId, string date, int quantity, string createdUser)
        {
            long UserId = 0;

            if (!string.IsNullOrEmpty(createdUser))
            {
                UserId = long.Parse(createdUser);
            }
            DateTime createDate = DateTime.UtcNow;

            if (!string.IsNullOrEmpty(date))
            {
                createDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                createDate = createDate.AddMilliseconds(double.Parse(date)).ToLocalTime();
            }
            var CommentView = new List <CommentViewModel>();

            if (String.IsNullOrEmpty(CommentId))
            {
                return(CommentView);
            }

            var CommentIdI = Int64.Parse(CommentId);
            var result     = (from c in context.Comments
                              join p4 in context.Users on c.UserId equals p4.ID into ps4
                              from p4 in ps4.DefaultIfEmpty()
                              join p5 in context.Comments on new { a1 = c.ID, a2 = TypeComment.COMMENT } equals new { a1 = p5.TargetId, a2 = p5.TargetType.Value } into ps5
                              let countEmotions = (from E in context.Emotions where E.TargetId == c.ID select E).Count()
                                                  where CommentIdI == c.TargetId && c.CreatedTime < createDate && (UserId == 0 || UserId == c.UserId) && c.TargetType == TypeComment.COMMENT
                                                  orderby c.CreatedTime descending
                                                  select new CommentViewModel
            {
                Id = c.ID,
                Audios = c.Audios,
                TargetId = c.TargetId,
                CreatedTime = c.CreatedTime,
                Images = c.Images,
                Tags = c.Tags,
                TagsUser = c.TagsUser,
                Content = c.Content,
                UserId = c.UserId,
                Avatar = p4.Avatar,
                NickName = p4.NickName,
                CountReply = ps5.Count(),
                CountEmotions = countEmotions,
            }).Take(quantity + 1).ToList();

            if (result.Count > quantity)
            {
                result[result.Count - 2].MoreComment = true;
                result.RemoveAt(result.Count - 1);
            }
            CommentView = CommentView.Union(result).ToList();

            foreach (var item in CommentView)
            {
                var responeImage = AmazonS3Uploader.GetUrl(item.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    item.Avatar = responeImage;
                }
                if (!string.IsNullOrEmpty(item.Images))
                {
                    var data = item.Images.Split(',');
                    item.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            item.ListImages.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.Audios))
                {
                    var data = item.Audios.Split(',');
                    item.ListAudios = new List <string>();
                    foreach (string audio in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(audio);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            item.ListAudios.Add(respone);
                        }
                    }
                }
            }
            return(CommentView);
        }
示例#17
0
        public List <FriendModel> GetSuggestFriend(long UserId, string query, bool?location, string category)
        {
            var List = new List <string>();

            if (!string.IsNullOrEmpty(category))
            {
                List = category.Split(',').ToList();
            }
            var User       = (from c in context.Users where c.ID == UserId select c).FirstOrDefault();
            var ListFriend = new List <FriendModel>();

            var result1 = (from c in context.Users
                           from t2 in context.Relationships.Where(tt2 => (c.ID == tt2.UserReceiveID && UserId == tt2.UserSentID) || (UserId == tt2.UserReceiveID && c.ID == tt2.UserSentID)).DefaultIfEmpty()
                           where (string.IsNullOrEmpty(query) || (c.NickName.Contains(query) || c.SubName.Contains(query))) &&
                           (c.Lat != null && c.Lng != null) &&
                           c.ID != UserId &&
                           (t2.ID == 0 || t2.Status != StatusRequestFriend.ACCEPT || t2.Type != TypeRequestFriend.USER)
                           orderby c.NickName descending
                           select new { c, distance = (c.Lat.Value - User.Lat.Value) * (c.Lat.Value - User.Lat.Value) + (c.Lng - User.Lng.Value) * (c.Lng.Value - User.Lng.Value) }).OrderBy(x => x.distance).Take(10000).OrderBy(x => Guid.NewGuid()).Take(50).ToList();

            foreach (var item in result1)
            {
                var Friend = new FriendModel();
                Friend.Avatar      = item.c.Avatar;
                Friend.NickName    = item.c.NickName;
                Friend.Id          = item.c.ID;
                Friend.Type        = TypeRequestFriend.USER;
                Friend.CreatedTime = item.c.CreatedTime;
                Friend.Suggest     = TypeSuggest.LOCATION;
                var respone = AmazonS3Uploader.GetUrl(item.c.Avatar, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    Friend.Avatar = respone;
                }
                ListFriend.Add(Friend);
            }

            var result2 = (from c in context.Users
                           from t2 in context.Relationships.Where(tt2 => (c.ID == tt2.UserReceiveID && UserId == tt2.UserSentID) || (UserId == tt2.UserReceiveID && c.ID == tt2.UserSentID)).DefaultIfEmpty()
                           where (string.IsNullOrEmpty(query) || (c.NickName.Contains(query) || c.SubName.Contains(query))) &&
                           c.ID != UserId &&
                           List.Any(x => c.Category.Contains(x)) &&
                           (t2.ID == 0 || t2.Status != StatusRequestFriend.ACCEPT || t2.Type != TypeRequestFriend.USER)
                           orderby c.NickName descending
                           select new { c }).OrderBy(x => Guid.NewGuid()).Take(50).ToList();

            foreach (var item in result2)
            {
                var Friend = new FriendModel();
                Friend.Avatar      = item.c.Avatar;
                Friend.NickName    = item.c.NickName;
                Friend.Id          = item.c.ID;
                Friend.Type        = TypeRequestFriend.USER;
                Friend.CreatedTime = item.c.CreatedTime;
                Friend.Suggest     = TypeSuggest.CATEGORY;
                var respone = AmazonS3Uploader.GetUrl(item.c.Avatar, 0);
                if (!string.IsNullOrEmpty(respone))
                {
                    Friend.Avatar = respone;
                }
                var same = ListFriend.Where(x => x.Id == Friend.Id).ToList();

                if (same.Count == 0)
                {
                    ListFriend.Add(Friend);
                }
                else
                {
                    ListFriend.Where(x => x.Id == Friend.Id).FirstOrDefault().Suggest = TypeSuggest.BOTH;
                }
            }
            ListFriend.OrderBy(a => Guid.NewGuid()).ToList();
            return(ListFriend);
        }
示例#18
0
        public PostViewModel LoadPostById(long?id, long?CommentId)
        {
            var Post = new PostViewModel();

            if (id == null && CommentId != null)
            {
                var checkLoad = false;
                var index     = 0;
                while (!checkLoad && index < 100)
                {
                    var comment = context.Comments.Find(CommentId.Value);
                    if (comment.TargetType == TypeComment.COMMENT)
                    {
                        CommentId = comment.TargetId;
                    }
                    else
                    {
                        checkLoad = true;
                        id        = comment.TargetId;
                    }
                    index++;
                }
            }
            if (id != null)
            {
                var result = (from c in context.Posts
                              join p4 in context.Users on c.UserId equals p4.ID into ps4
                              from p4 in ps4.DefaultIfEmpty()
                              join p6 in context.Groups on new { t1 = c.TargetType.Value, t2 = c.TargetId.Value } equals new { t1 = TypePost.GROUP, t2 = p6.ID }  into ps6
                              from p6 in ps6.DefaultIfEmpty()
                              join p7 in context.Users on new { t1 = c.TargetType.Value, t2 = c.TargetId.Value } equals new { t1 = TypePost.USER, t2 = p7.ID }  into ps7
                              from p7 in ps7.DefaultIfEmpty()
                              let countEmotions = (from E in context.Emotions where E.TargetId == c.ID select E).Count()
                                                  let countComments = (from C in context.Comments where C.TargetId == c.ID select C).Count()
                                                                      where c.ID == id.Value
                                                                      select new{ c, p4, countEmotions, countComments, p6, p7 }).FirstOrDefault();

                Post.Id      = result.c.ID;
                Post.Audios  = result.c.Audios;
                Post.Content = result.c.Content;
                Post.Images  = result.c.Images;
                if (!string.IsNullOrEmpty(result.c.Images))
                {
                    var data = result.c.Images.Split(',');
                    Post.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListImages.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(result.c.Videos))
                {
                    var data = result.c.Videos.Split(',');
                    Post.ListVideos = new List <string>();
                    foreach (string video in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(video);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListVideos.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(result.c.Audios))
                {
                    var data = result.c.Audios.Split(',');
                    Post.ListAudios = new List <string>();
                    foreach (string audio in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(audio);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListAudios.Add(respone);
                        }
                    }
                }
                Post.Tags        = result.c.Tags;
                Post.TagsUser    = result.c.TagsUser;
                Post.TargetId    = result.c.TargetId;
                Post.TargetType  = result.c.TargetType;
                Post.Type        = result.c.Type;
                Post.CreatedTime = result.c.CreatedTime;
                Post.UpdateTime  = result.c.UpdateTime;
                Post.UserId      = result.c.UserId;
                var responeImage = AmazonS3Uploader.GetUrl(result.p4?.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Post.Avatar = responeImage;
                }
                responeImage = AmazonS3Uploader.GetUrl(result.p6 == null ? result.p7.Avatar :  result.p6.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Post.TargetAvatar = responeImage;
                }
                Post.NickName       = result.p4?.NickName;
                Post.TargetNickName = result.p6 == null ? result.p7.NickName :  result.p6.GroupName;
                Post.TargetUrl      = result.p6 == null ? "profile" :  "group";
                Post.CountEmotions  = result.countEmotions;
                Post.CountComments  = result.countComments;
                Post.ShowTarget     = Post.UserId != Post.TargetId && result.c.TargetType == TypePost.USER ? "" : "hidden";
            }
            return(Post);
        }
示例#19
0
        public List <PostViewModel> LoadPostsHome(string date, long UserId)
        {
            DateTime createDate = DateTime.UtcNow;

            if (!string.IsNullOrEmpty(date))
            {
                createDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                createDate = createDate.AddMilliseconds(double.Parse(date)).ToLocalTime();
            }
            var result = (from c in context.Posts
                          join p1 in context.Relationships on new { t1 = UserId, t2 = c.TargetId.Value } equals new { t1 = p1.UserSentID, t2 = p1.UserReceiveID }  into ps1
                          from p1 in ps1.DefaultIfEmpty()
                          join p2 in context.Relationships on new { t1 = UserId, t2 = c.TargetId.Value } equals new { t1 = p2.UserReceiveID, t2 = p2.UserSentID }  into ps2
                          from p2 in ps2.DefaultIfEmpty()
                          join p3 in context.GroupMembers on new { t1 = UserId, t2 = c.TargetId.Value } equals new { t1 = p3.UserId, t2 = p3.GroupID }  into ps3
                          from p3 in ps3.DefaultIfEmpty()
                          join p4 in context.Users on c.UserId equals p4.ID into ps4
                          from p4 in ps4.DefaultIfEmpty()
                          join p5 in context.Emotions on new { t1 = UserId, t2 = c.ID } equals new { t1 = p5.UserId.Value, t2 = p5.TargetId.Value }  into ps5
                          from p5 in ps5.DefaultIfEmpty()
                          join p6 in context.Groups on new { t1 = c.TargetType.Value, t2 = c.TargetId.Value } equals new { t1 = TypePost.GROUP, t2 = p6.ID }  into ps6
                          from p6 in ps6.DefaultIfEmpty()
                          join p7 in context.Users on new { t1 = c.TargetType.Value, t2 = c.TargetId.Value } equals new { t1 = TypePost.USER, t2 = p7.ID }  into ps7
                          from p7 in ps7.DefaultIfEmpty()
                          let countEmotions = (from E in context.Emotions where E.TargetId == c.ID select E).Count()
                                              let countComments = (from C in context.Comments where C.TargetId == c.ID select C).Count()
                                                                  where c.CreatedTime < createDate && (((c.TargetId == p1.UserReceiveID || c.TargetId == UserId || c.TargetId == p2.UserSentID) && c.TargetType == TypePost.USER) || (c.TargetId == p3.GroupID && c.TargetType == TypePost.GROUP) || (c.UserId == c.TargetId && c.UserId == 21 && c.TargetType == TypePost.USER))
                                                                  orderby c.CreatedTime descending
                                                                  select new{ c, p1, p2, p3, p4, countEmotions, p5, countComments, p6, p7 }).Take(10).ToList();
            var PostView = new List <PostViewModel>();

            foreach (var item in result)
            {
                if (createDate == item.c.CreatedTime)
                {
                    continue;
                }
                var Post = new PostViewModel();
                Post.Id      = item.c.ID;
                Post.Audios  = item.c.Audios;
                Post.Content = item.c.Content;
                Post.Images  = item.c.Images;
                if (!string.IsNullOrEmpty(item.c.Images))
                {
                    var data = item.c.Images.Split(',');
                    Post.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListImages.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.c.Videos))
                {
                    var data = item.c.Videos.Split(',');
                    Post.ListVideos = new List <string>();
                    foreach (string video in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(video);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListVideos.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.c.Audios))
                {
                    var data = item.c.Audios.Split(',');
                    Post.ListAudios = new List <string>();
                    foreach (string audio in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(audio);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListAudios.Add(respone);
                        }
                    }
                }
                Post.Tags        = item.c.Tags;
                Post.TagsUser    = item.c.TagsUser;
                Post.TargetId    = item.c.TargetId;
                Post.TargetType  = item.c.TargetType;
                Post.Type        = item.c.Type;
                Post.CreatedTime = item.c.CreatedTime;
                Post.UpdateTime  = item.c.UpdateTime;
                Post.UserId      = item.c.UserId;
                var responeImage = AmazonS3Uploader.GetUrl(item.p4?.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Post.Avatar = responeImage;
                }
                responeImage = AmazonS3Uploader.GetUrl(item.p6 == null ? item.p7.Avatar :  item.p6.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Post.TargetAvatar = responeImage;
                }
                Post.NickName       = item.p4?.NickName;
                Post.TargetNickName = item.p6 == null ? item.p7.NickName :  item.p6.GroupName;
                Post.TargetUrl      = item.p6 == null ? "profile" :  "group";
                Post.CountEmotions  = item.countEmotions;
                Post.CountComments  = item.countComments;
                Post.StatusEmotion  = item.p5 == null ? (byte)0: item.p5.Status;
                Post.ShowTarget     = Post.UserId != Post.TargetId || item.c.TargetType != TypePost.USER ? "" : "hidden";
                PostView.Add(Post);
            }
            return(PostView);
        }
示例#20
0
        public List <PostViewModel> LoadPostsGroup(string date, long UserId, long UserLogin)
        {
            DateTime createDate = DateTime.UtcNow;

            if (!string.IsNullOrEmpty(date))
            {
                createDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                createDate = createDate.AddMilliseconds(double.Parse(date)).ToLocalTime();
            }
            var result = (from c in context.Posts
                          join p4 in context.Users on c.UserId equals p4.ID into ps4
                          from p4 in ps4.DefaultIfEmpty()
                          join p5 in context.Emotions on new { t1 = UserLogin, t2 = c.ID } equals new { t1 = p5.UserId.Value, t2 = p5.TargetId.Value }  into ps5
                          from p5 in ps5.DefaultIfEmpty()
                          let countEmotions = (from E in context.Emotions where E.TargetId == c.ID select E).Count()
                                              let countComments = (from C in context.Comments where C.TargetId == c.ID select C).Count()
                                                                  where c.CreatedTime < createDate && (c.TargetId != null && c.TargetId == UserId) && c.TargetType == TypePost.GROUP
                                                                  orderby c.CreatedTime descending
                                                                  select new{ c, p4, countEmotions, p5, countComments }).Take(10).ToList();
            var PostView = new List <PostViewModel>();

            foreach (var item in result)
            {
                if (createDate == item.c.CreatedTime)
                {
                    continue;
                }
                var Post = new PostViewModel();
                Post.Id      = item.c.ID;
                Post.Audios  = item.c.Audios;
                Post.Content = item.c.Content;
                Post.Images  = item.c.Images;
                if (!string.IsNullOrEmpty(item.c.Images))
                {
                    var data = item.c.Images.Split(',');
                    Post.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListImages.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.c.Videos))
                {
                    var data = item.c.Videos.Split(',');
                    Post.ListVideos = new List <string>();
                    foreach (string video in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(video);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListVideos.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.c.Audios))
                {
                    var data = item.c.Audios.Split(',');
                    Post.ListAudios = new List <string>();
                    foreach (string audio in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(audio);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Post.ListAudios.Add(respone);
                        }
                    }
                }
                Post.Tags        = item.c.Tags;
                Post.TagsUser    = item.c.TagsUser;
                Post.TargetId    = item.c.TargetId;
                Post.TargetType  = item.c.TargetType;
                Post.Type        = item.c.Type;
                Post.CreatedTime = item.c.CreatedTime;
                Post.UpdateTime  = item.c.UpdateTime;
                Post.UserId      = item.c.UserId;
                Post.NickName    = item.p4?.NickName;
                var responeImage = AmazonS3Uploader.GetUrl(item.p4?.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Post.Avatar = responeImage;
                }
                Post.CountEmotions = item.countEmotions;
                Post.CountComments = item.countComments;
                Post.StatusEmotion = item.p5 == null ? (byte)0: item.p5.Status;
                Post.ShowTarget    = "hidden";
                PostView.Add(Post);
            }
            return(PostView);
        }
示例#21
0
        public List <MessageViewModel> LoadMessagesNotifi(long UserId)
        {
            var result = (from c in context.Messages
                          join p2 in context.Users on c.UserID equals p2.ID into ps2
                          from p2 in ps2.DefaultIfEmpty()
                          where (c.TargetUser == UserId) && c.Seen != true
                          orderby c.CreatedTime descending
                          select new { c, p2 })
                         .GroupBy(x => x.c.UserID).Select(r => new
            {
                c  = r.FirstOrDefault().c,
                p2 = r.FirstOrDefault().p2
            }).Take(10).ToList();
            var MessageView = new List <MessageViewModel>();

            foreach (var item in result)
            {
                var Message = new MessageViewModel();
                Message.Id      = item.c.ID;
                Message.Audios  = item.c.Audios;
                Message.Content = item.c.Content;
                Message.Image   = item.c.Image;
                if (!string.IsNullOrEmpty(item.c.Image))
                {
                    var data = item.c.Image.Split(',');
                    Message.ListImages = new List <string>();
                    foreach (string image in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(image);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Message.ListImages.Add(respone);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(item.c.Audios))
                {
                    var data = item.c.Audios.Split(',');
                    Message.ListAudios = new List <string>();
                    foreach (string audio in data)
                    {
                        var respone = AmazonS3Uploader.GetUrl(audio);
                        if (!string.IsNullOrEmpty(respone))
                        {
                            Message.ListAudios.Add(respone);
                        }
                    }
                }
                Message.Other       = item.c.Other;
                Message.Seen        = item.c.Seen;
                Message.TargetUser  = item.c.TargetUser;
                Message.UserId      = item.c.UserID;
                Message.CreatedTime = item.c.CreatedTime;
                var responeImage = AmazonS3Uploader.GetUrl(item.p2?.Avatar, 0);
                if (!string.IsNullOrEmpty(responeImage))
                {
                    Message.AvataTarget = responeImage;
                }
                Message.NickNameTarget = item.p2?.NickName;
                MessageView.Add(Message);
            }
            return(MessageView);
        }