예제 #1
0
        public UserDetailViewModel(string id)
        {
            using (var entDB = new EntityDbContext())
            {
                user = entDB.AspNetUsers.Find(id);

                var selectedMessages = from m in entDB.UserMessages
                                       where m.posterId == id
                                       select m;
                userMessages = selectedMessages.ToList();
            }
        }
예제 #2
0
        public MessageDetailViewModel(string id)
        {
            int intId = Int32.Parse(id);

            using (var entDB = new EntityDbContext())
            {
                message = entDB.UserMessages.Find(intId);

                var messageComments = from uc in entDB.UserComments
                                      where uc.messageId == intId
                                      select uc;
                comments = messageComments.ToList();
            }
        }
예제 #3
0
        public UserComment addComment(int messageId, string userId, string commentText)
        {
            UserComment userComment = new UserComment();

            userComment.messageId   = messageId;
            userComment.commentText = commentText;
            userComment.commeterId  = userId;
            using (var entDb = new EntityDbContext())
            {
                entDb.UserComments.Add(userComment);
                entDb.SaveChanges();
            }
            return(userComment);
        }
예제 #4
0
        public UserMessage addMessage(string userId, string messageText)
        {
            UserMessage newMessage = new UserMessage();

            newMessage.messageText = messageText;
            newMessage.posterId    = userId;
            newMessage.postedDate  = DateTime.Now;


            using (var entDB = new EntityDbContext())
            {
                entDB.UserMessages.Add(newMessage);
                entDB.SaveChanges();
            }

            return(newMessage);
        }
예제 #5
0
        public UserIndexViewModel(string id)
        {
            usersFollowed = new List <AspNetUser>();
            userMessages  = new List <UserMessage>();

            List <string> followingIds = new List <string>();

            //user messages from those  I'm following
            using (var entDb = new EntityDbContext())
            {
                // get collection of users, the {id} user is following
                var following = from u in entDb.AspNetUsers
                                join ur in entDb.UserRelationShips on u.Id equals ur.followingId
                                where ur.followerId == id
                                select u;

                usersFollowed = following.ToList();

                //get messages posted by those user {id} is following
                foreach (AspNetUser followee in usersFollowed)
                {
                    List <UserMessage> tempMessages = (from um in entDb.UserMessages
                                                       where (um.posterId == followee.Id)
                                                       select um).Distinct().ToList();
                    userMessages.AddRange(tempMessages);
                }

                List <UserMessage> myMessages = (from um in entDb.UserMessages
                                                 where um.posterId == id
                                                 select um).ToList();

                //List <UserMessage> testList = (entDb.Database.SqlQuery<UserMessage>("select * from UserMessages where posterId =" + id)).ToList();

                userMessages.AddRange(myMessages);
            }
            //TODO: add some sane sort to messages in list
        }