Esempio n. 1
0
        public JsonResult Post(string content, int profile_Owner_ID)
        {
            content = content.Trim();
            int poster_ID = 0;

            poster_ID = (int)Session["CurrentUserID"];
            bool returnValue = false;

            if (!string.IsNullOrEmpty(content) && poster_ID != 0 && profile_Owner_ID != 0 && !string.IsNullOrWhiteSpace(content))
            {
                returnValue = postManager.CreatePost(new POST()
                {
                    CONTENT          = content,
                    POSTER_ID        = poster_ID,
                    PROFILE_OWNER_ID = profile_Owner_ID
                });
            }

            return(Json(new { Status = returnValue }, JsonRequestBehavior.AllowGet));
        }
 public bool CreatePost(string url, double geoposition, double azimut, int idCreator)
 {
     PostManager.CreatePost(url, geoposition, azimut, idCreator);
     return(true);
 }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            UserManager userManager = UserManager.GetInstance();

            userManager.AddUser("user1", "1234");
            userManager.AddUser("user2", "2345");
            PostManager postManager = PostManager.GetInstance();

            //postManager.AddPost(new Post("User1 Post", "This is my First Post", "user1",12345689));
            //postManager.AddPost(new Post("User1 Post", "This is my Second Post", "user1", 12345689));
            //postManager.AddPost(new Post("User2 Post", "This is my first Post", "user2", 234567890));
            while (true)
            {
                Console.Write("Username : "******"Password : "******"User: "******" has login.");
                }
                while (userManager.CurrentUser != null)
                {
                    Console.WriteLine("\n\nPress 1 to view all post\nPress 2 to view my post\nPress 3 to Create a post\nPress 4 To Add Comment\nPress 5 to add reply\nPress 6 to like a post\nPress 7 to remove a post\nPress 8 to logout\n");
                    Console.WriteLine("\nChoose your option ");
                    int         choice = Convert.ToInt32(Console.ReadLine());
                    List <Post> _posts;
                    Post        post;
                    int         innerchoice = 0;
                    switch (choice)
                    {
                    case 1:
                        Console.WriteLine("All Post");
                        _posts = postManager.ViewAllPost();
                        if (_posts.Count != 0)
                        {
                            count = 0;
                            _posts.ForEach(singlepost => DisplayPost(singlepost));
                            break;
                        }
                        else
                        {
                            Console.WriteLine("NO post found");
                            break;
                        }

                    case 2:
                        Console.WriteLine("Users Post");
                        _posts = postManager.ViewMyPost(userManager.CurrentUser.UserId);
                        if (_posts.Count != 0)
                        {
                            count = 0;
                            _posts.ForEach(singlepost => DisplayPost(singlepost));
                            break;
                        }
                        else
                        {
                            Console.WriteLine("NO post found from {0}", userManager.CurrentUser.UserName);
                            break;
                        }

                    case 3:
                        Console.Write("Enter Title : ");
                        string title = Console.ReadLine();
                        Console.Write("Enter Content : ");
                        string content = Console.ReadLine();
                        postManager.CreatePost(new Post(title, content, userManager.CurrentUser.UserName, userManager.CurrentUser.UserId));
                        break;

                    case 4:
                        _posts = postManager.ViewAllPost();
                        count  = 0;
                        if (_posts.Count != 0)
                        {
                            _posts.ForEach(singlepost => DisplayPost(singlepost));
                            Console.Write("choose which post you want comment : ");
                            innerchoice = Convert.ToInt32(Console.ReadLine());
                            post        = _posts.ElementAt(innerchoice);
                            long postid = post.PostId;
                            Console.Write("Enter your Comment : ");
                            string Commentcontent = Console.ReadLine();
                            postManager.AddComment(post, new Comment(postid, Commentcontent, userManager.CurrentUser.UserName, userManager.CurrentUser.UserId, null));
                            break;
                        }
                        else
                        {
                            Console.WriteLine("No post to comment");
                            break;
                        }

                    case 5:
                        _posts = postManager.ViewAllPost();
                        count  = 0;
                        _posts.ForEach(singlepost => DisplayPost(singlepost));
                        if (_posts.Count == 0)
                        {
                            Console.WriteLine("No post is available");
                            break;
                        }
                        count = 0;
                        Console.Write("Choose which post you want comment : ");
                        innerchoice = Convert.ToInt32(Console.ReadLine());
                        post        = _posts.ElementAt(innerchoice);
                        DisplayPost(post);
                        if (post.Comments.Count != 0)
                        {
                            Console.Write("which comment you want reply : ");
                            int     choiceOfComment = Convert.ToInt32(Console.ReadLine());
                            Comment comment         = postManager.ViewPostComment(post, post.PostId).ElementAt(choiceOfComment);
                            Console.Write("Enter your reply : ");
                            string replyComment = Console.ReadLine();
                            postManager.AddReply(post, comment.CommentId, new Comment(post.PostId, replyComment, userManager.CurrentUser.UserName, userManager.CurrentUser.UserId, comment.CommentId));
                            break;
                        }
                        else
                        {
                            Console.WriteLine("No comment to reply ");
                            break;
                        }

                    case 6:
                        _posts = postManager.ViewAllPost();
                        count  = 0;
                        _posts.ForEach(singlepost => DisplayPost(singlepost));
                        if (_posts.Count != 0)
                        {
                            count = 0;
                            Console.Write("Choose which post you want like : ");
                            innerchoice = Convert.ToInt32(Console.ReadLine());
                            post        = _posts.ElementAt(innerchoice);
                            postManager.LikePost(post, userManager.CurrentUser);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("no post is there to like");
                            break;
                        }

                    case 7:
                        _posts = postManager.ViewMyPost(userManager.CurrentUser.UserId);
                        if (_posts.Count == 0)
                        {
                            Console.WriteLine("no post is available from user");
                            break;
                        }
                        _posts.ForEach(singlepost => DisplayPost(singlepost));
                        Console.Write("which post you want  remove : ");
                        innerchoice = Convert.ToInt32(Console.ReadLine());
                        postManager.DeletePost(_posts.ElementAt(innerchoice));
                        Console.WriteLine("Post is removed ");
                        break;

                    case 8:
                        userManager.Logout();
                        Console.WriteLine("User: "******" has logout.");
                        break;
                    }
                }
            }
        }
        public bool HandleRequest(Client client, HttpListenerContext context, params string[] args)
        {
            if (!UserManager.Connected(client))
            {
                context.Send("not connected");
                return(true);
            }

            User user = UserManager.GetUser(UserManager.GetUserID(client));

            if (user == null)
            {
                context.Send("user not found");
                return(true);
            }

            if (context.Request.HttpMethod == "GET")
            {
                if (args.Length == 0)
                {
                    Post[] posts = PostManager.GetHomeFeedPosts(user);

                    string output = JsonConvert.SerializeObject(posts.ToResponse());

                    context.Send(output);

                    return(true);
                }

                int postId = 0;

                if (int.TryParse(args[0], out postId))
                {
                    Post post = PostManager.GetPost(postId);

                    if (post == null)
                    {
                        return(true);
                    }

                    if (args.Length == 1)
                    {
                        context.Send(JsonConvert.SerializeObject(new Post[] { post }.ToResponse()));
                    }
                    else
                    {
                        switch (args[1])
                        {
                        case "delete":
                            if (post.UserId == user.Id)
                            {
                                PostManager.DeletePost(post);
                            }
                            break;
                        }

                        context.Redirect(context.Request.UrlReferrer.AbsoluteUri);
                    }
                }
            }

            if (context.Request.HttpMethod == "POST")
            {
                if (args.Length == 0)
                {
                    string data = string.Empty;

                    using (StreamReader reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding))
                    {
                        data = reader.ReadToEnd();
                    }

                    Dictionary <string, string> formData = WebHelper.ParsePostData(data);

                    if (formData.ContainsKey("data") && !string.IsNullOrEmpty(formData["data"]))
                    {
                        PostManager.CreatePost(user, formData["data"]);
                    }

                    context.Redirect(context.Request.UrlReferrer.AbsoluteUri);

                    return(true);
                }

                int postId = 0;

                if (int.TryParse(args[0], out postId))
                {
                    Post post = PostManager.GetPost(postId);

                    string data = string.Empty;

                    using (StreamReader reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding))
                    {
                        data = reader.ReadToEnd();
                    }

                    Dictionary <string, string> formData = WebHelper.ParsePostData(data);

                    if (formData.ContainsKey("data") && !string.IsNullOrEmpty(formData["data"]))
                    {
                        post.Data = formData["data"];

                        if (user.Id == post.UserId)
                        {
                            PostManager.UpdatePost(post);
                        }
                    }
                    // context.Response.StatusCode = 204; // prevent page refresh by returning no content code
                    context.Redirect(context.Request.UrlReferrer.AbsoluteUri);
                }
            }

            return(true);
        }
Esempio n. 5
0
 public string CreatePost(string url, double geoposition, double azimut, int idCreator)
 {
     PostManager.CreatePost(url, geoposition, azimut, idCreator);
     return(JsonConvert.SerializeObject(true));
 }