Beispiel #1
0
 public List <vwUser> UsersWhoLikedPost(vwPost post)
 {
     try
     {
         using (BetweenUsEntities context = new BetweenUsEntities())
         {
             List <int>    usersId = context.tblLikedPosts.Where(x => x.PostId == post.PostId).Select(x => x.UserId).ToList();
             List <vwUser> users   = new List <vwUser>();
             foreach (var item in usersId)
             {
                 vwUser user = context.vwUsers.Where(x => x.UserId == item).FirstOrDefault();
                 if (user != null)
                 {
                     users.Add(user);
                 }
             }
             return(users);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Beispiel #2
0
 /// <summary>
 /// This method adds post to DbSet and saves changes to database.
 /// </summary>
 /// <param name="postToAdd">Post to be added.</param>
 /// <returns>True if post is added, false if not.</returns>
 public bool CreatePost(vwPost postToAdd)
 {
     try
     {
         using (BetweenUsEntities context = new BetweenUsEntities())
         {
             tblPost newPost = new tblPost
             {
                 DateOfPost    = DateTime.Now.Date,
                 PostContent   = postToAdd.PostContent,
                 UserId        = postToAdd.UserId,
                 NumberOfLikes = 0
             };
             context.tblPosts.Add(newPost);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }