Пример #1
0
        public UserLoggedInVM FindUser(LoginAttempVM attempt)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            UserLoggedInVM       user = db.Users.Where(u => u.UserName == attempt.UsernameAttempt && u.Password == attempt.PasswordAttempt).Select(u => new UserLoggedInVM {
                Id        = u.Id,
                FirstName = u.FirstName,
                LastName  = u.LastName,
                UserName  = u.UserName,
                Followers = db.Followers.Where(f => f.UserId == u.Id).Select(f => new FollowerVM
                {
                    Id        = f.theFollowed.Id,
                    UserName  = f.theFollowed.UserName,
                    FirstName = f.theFollowed.FirstName
                }).ToList()
            }).FirstOrDefault();


            user.Tweets = db.Tweets.Where(t => t.AuthorId == user.Id).ToList();
            foreach (FollowerVM follower in user.Followers)
            {
                follower.Tweets = db.Tweets.Where(t => t.AuthorId == follower.Id).ToList();
                user.Tweets.AddRange(follower.Tweets);
                user.Tweets.Sort((x, y) => DateTime.Compare(x.Created, y.Created));
                user.Tweets.Reverse();
            }

            return(user);
        }
Пример #2
0
        public List <Tweet> GetTweets(int Authorid)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            UserLoggedInVM       user = db.Users.Where(u => u.Id == Authorid).Select(u => new UserLoggedInVM
            {
                Id = u.Id,
                //FirstName = u.FirstName,
                //LastName = u.LastName,
                //UserName = u.UserName,
                Followers = db.Followers.Where(f => f.UserId == u.Id).Select(f => new FollowerVM
                {
                    Id = f.theFollowed.Id,
                    //UserName = f.theFollowed.UserName,
                    //FirstName = f.theFollowed.FirstName
                }).ToList()
            }).FirstOrDefault();

            user.Tweets = db.Tweets.Where(t => t.AuthorId == user.Id).ToList();
            foreach (FollowerVM follower in user.Followers)
            {
                follower.Tweets = db.Tweets.Where(t => t.AuthorId == follower.Id).ToList();
                user.Tweets.AddRange(follower.Tweets);
            }

            List <Tweet> tweets = user.Tweets;

            tweets.Sort((x, y) => DateTime.Compare(x.Created, y.Created));
            tweets.Reverse();
            return(tweets);
        }
Пример #3
0
        public IHttpActionResult Post(LoginAttempVM attempt)
        {
            UserLoggedInVM user = _adapter.FindUser(attempt);

            return(Ok(user));
        }