Beispiel #1
0
        public void SendRequest(tblUser sendUser, tblUser recieveUser)
        {
            try
            {
                using (SocialNetworkDbEntities context = new SocialNetworkDbEntities())
                {
                    tblUser sendUserInDb = (from u in context.tblUsers
                                            where u.UserID == sendUser.UserID
                                            select u).First();

                    tblUser recieveUserInDb = (from u in context.tblUsers
                                               where u.UserID == recieveUser.UserID
                                               select u).First();

                    recieveUserInDb.tblUsers.Add(sendUserInDb);
                    //recieveUserInDb.tblUsers.Add(sendUserInDb);


                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
        public void LikePost(tblPost post, tblUser user)
        {
            try
            {
                using (SocialNetworkDbEntities context = new SocialNetworkDbEntities())
                {
                    tblPost postInDB = (from x in context.tblPosts
                                        where x.PostID == post.PostID

                                        select x).First();

                    tblUser userInDb = (from x in context.tblUsers
                                        where x.UserID == user.UserID

                                        select x).First();

                    if (postInDB.NumberOfLikes == null)
                    {
                        postInDB.NumberOfLikes = 1;
                    }
                    else
                    {
                        postInDB.NumberOfLikes += 1;
                    }
                    postInDB.tblUsers.Add(userInDb);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
Beispiel #3
0
        public tblUser AddUser(tblUser user)
        {
            try
            {
                using (SocialNetworkDbEntities context = new SocialNetworkDbEntities())
                {
                    tblUser newUser = new tblUser();
                    newUser.FirstName   = user.FirstName;
                    newUser.LastName    = user.LastName;
                    newUser.Email       = user.Email;
                    newUser.Gender      = user.Gender;
                    newUser.Location    = user.Location;
                    newUser.DateOfBirth = user.DateOfBirth;
                    newUser.Username    = user.Username;
                    newUser.Password    = user.Password;

                    context.tblUsers.Add(newUser);
                    context.SaveChanges();

                    return(newUser);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public tblPost AddPost(tblPost post)
        {
            try
            {
                using (SocialNetworkDbEntities context = new SocialNetworkDbEntities())
                {
                    tblPost newPost = new tblPost();
                    newPost.PostText   = post.PostText;
                    newPost.DateOfPost = DateTime.Now;
                    newPost.UserID     = post.UserID;

                    context.tblPosts.Add(newPost);
                    context.SaveChanges();

                    return(newPost);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }