/// <summary>
 /// This method increment number of likes of post.
 /// </summary>
 /// <param name="post">Post to be liked.</param>
 public void LikePost(vwFriendPost post, vwUser userWhoLikePost)
 {
     try
     {
         using (BetweenUsEntities context = new BetweenUsEntities())
         {
             int     id         = context.vwFriendPosts.Where(x => x.PostId == post.PostId).Select(x => x.PostId).FirstOrDefault();
             tblPost postToLike = context.tblPosts.Where(x => x.PostId == id).FirstOrDefault();
             if (postToLike != null)
             {
                 postToLike.NumberOfLikes++;
                 context.SaveChanges();
             }
             tblLikedPost likedPost = new tblLikedPost
             {
                 UserId = userWhoLikePost.UserId,
                 PostId = postToLike.PostId
             };
             context.tblLikedPosts.Add(likedPost);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
 /// <summary>
 /// This method adds user to DbSet and saves changes to database.
 /// </summary>
 /// <param name="userToAdd">User to add.</param>
 /// <param name="id">User id.</param>
 /// <returns>True if added, false if not.</returns>
 public bool CreateUser(vwUser userToAdd, out int id)
 {
     try
     {
         using (BetweenUsEntities context = new BetweenUsEntities())
         {
             tblUser newUser = new tblUser
             {
                 DateOfBirth    = userToAdd.DateOfBirth,
                 FirstName      = userToAdd.FirstName,
                 LastName       = userToAdd.LastName,
                 Gender         = userToAdd.Gender,
                 Location       = userToAdd.Location,
                 MarriageStatus = userToAdd.MarriageStatus,
                 Password       = Encryption.EncryptPassword(userToAdd.Password),
                 PhoneNumber    = userToAdd.PhoneNumber,
                 Profession     = userToAdd.Profession,
                 Username       = userToAdd.Username
             };
             context.tblUsers.Add(newUser);
             context.SaveChanges();
             id = newUser.UserId;
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         id = 0;
         return(false);
     }
 }
Exemple #3
0
 /// <summary>
 /// This method changes status of request to declined.
 /// </summary>
 /// <param name="requestToDecline">Request to decline.</param>
 /// <returns>True if declined, false if not.</returns>
 public bool DeclineRequest(vwRequest requestToDecline)
 {
     try
     {
         using (BetweenUsEntities context = new BetweenUsEntities())
         {
             var request = context.tblRequests.Where(x => x.RequestId == requestToDecline.RequestId).FirstOrDefault();
             if (request != null)
             {
                 request.Status = "Declined";
                 context.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemple #4
0
 /// <summary>
 /// This method adds request to DbSet and saves changes to database.
 /// </summary>
 /// <param name="sender">Sender of request.</param>
 /// <param name="recipient">Recipient of request.</param>
 /// <returns>True if added, false if not.</returns>
 public bool SendRequest(vwUser sender, vwUser recipient)
 {
     try
     {
         using (BetweenUsEntities context = new BetweenUsEntities())
         {
             tblRequest request = new tblRequest
             {
                 RecipientId = recipient.UserId,
                 SenderId    = sender.UserId,
                 Status      = "Pending"
             };
             context.tblRequests.Add(request);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemple #5
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);
     }
 }