public ActionResult Create([Bind(Include = "PostID,Author,Title,PublishDate,Content,Website,City,Image,Video")] Post post)
 {
     if (ModelState.IsValid)
     {
         //Add the post to the database
         post.PublishDate = DateTime.Now;
         db.Posts.Add(post);
         db.SaveChanges();
         //Creating an object for the facebook page.
         FacebookClient app = new FacebookClient("EAAJO0xAYtwQBAIBjC9GtpUiKZBMNeakebrfsW8eGLDTr3HBpSVywia0CNJ4T9xq1hNmFAmujlkWu8YcT2QrseLbwkfd5kTq3O31hnADQpKppESFY7ioe0l9QZBVUG6ai1cfR3vpFAFFgmdirBTx0rAA1pjBC6PYgeeqbPafAZDZD");
         //Creating object with parameters of the post.
         dynamic messagePost = new ExpandoObject();
         messagePost.message = "Hi guys, Check out new post wrote by "; //" + post.Author + "!";
         //if image is available - post it too.
         if (post.Image != null)
         {
             messagePost.url = post.Image;
             //Try to post the information on the facebook page
             try
             {
                 var result = app.Post("/355852721418666/photos", messagePost);
             }
             //Log the Exception if an error occured.
             catch (FacebookOAuthException ex)
             {
                 string filePath = @"C:\Logs\FacebookLog.txt";
                 using (StreamWriter writer = new StreamWriter(filePath, true))
                 {
                     writer.WriteLine("Error Posting at Facebook about a new post with photo.");
                     writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                                      "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                     writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                 }
             }
         }
         else
         {
             //Try to post the information to facebook without the image
             try
             {
                 var result = app.Post("/355852721418666/feed", messagePost);
             }
             //Log the Exception if an error occured.
             catch (FacebookOAuthException ex)
             {
                 string filePath = @"C:\Logs\FacebookLog.txt";
                 using (StreamWriter writer = new StreamWriter(filePath, true))
                 {
                     writer.WriteLine("Error Posting at Facebook about a new post.");
                     writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                                      "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                     writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                 }
             }
         }
         return(RedirectToAction("Index"));
     }
     return(View(post));
 }
 public ActionResult Create(Fan Fan)
 {
     using (var context = new ShauliBlogContext())
     {
         context.Fans.Add(Fan);
         context.SaveChanges();
         return(RedirectToAction("ThankYou"));
     }
 }
 public ActionResult AddNewPost(Post Post)
 {
     using (var context = new ShauliBlogContext())
     {
         context.Posts.Add(Post);
         context.SaveChanges();
         return(RedirectToAction("ManagePosts"));
     }
 }
Example #4
0
 public ActionResult Create([Bind(Include = "FirstName,LastName,SexType,BirthDate,Seniority")] Fan fan)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Fans.Add(fan);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(fan));
 }
 public ActionResult Delete(int Id, Fan Fan)
 {
     using (var context = new ShauliBlogContext())
     {
         var _fan = context.Fans.Where(a => a.Id == Id).SingleOrDefault();
         context.Fans.Remove(_fan);
         context.SaveChanges();
         return(RedirectToAction("FansList"));
     }
 }
Example #6
0
 public ActionResult AddNewComment(int Id, Comment Comment)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post = context.Posts.Where(a => a.PostId == Id).SingleOrDefault();
         // Comment.Post = _post;
         _post.Comments.Add(Comment);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
 public ActionResult DeleteComment(int PostId, int CommentId)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post    = context.Posts.SingleOrDefault(a => (a.PostId == PostId));
         var _comment = _post.Comments.SingleOrDefault(a => a.CommentId == CommentId);
         _post.Comments.Remove(_comment);
         context.SaveChanges();
         return(RedirectToAction(String.Format("Blog/Posts/{0}/comments", PostId)));
     }
 }
Example #8
0
        public ActionResult Register([Bind(Include = "ID,UserName,Password")] Manager manager)
        {
            if (ModelState.IsValid)
            {
                db.Managers.Add(manager);
                db.SaveChanges();

                Session["Name"] = manager.UserName;
                return(RedirectToAction("Index", "Blog"));
            }

            return(View(manager));
        }
        public ActionResult Create([Bind(Include = "ID,firstName,lastName,gender,birthDate,City,Latitude,Longitude,seniority")] Fan fan)
        {
            if (ModelState.IsValid)
            {
                //Add Fan to the database
                db.Fans.Add(fan);
                db.SaveChanges();

                //Crate an object with all parameters for the post
                dynamic messagePost = new ExpandoObject();
                messagePost.message = "Hi all, Lets congratulate " + fan.firstName + " for joining our awesome fan club!";

                //Open a session to the facebook page
                FacebookClient app = new FacebookClient("EAAJO0xAYtwQBAIBjC9GtpUiKZBMNeakebrfsW8eGLDTr3HBpSVywia0CNJ4T9xq1hNmFAmujlkWu8YcT2QrseLbwkfd5kTq3O31hnADQpKppESFY7ioe0l9QZBVUG6ai1cfR3vpFAFFgmdirBTx0rAA1pjBC6PYgeeqbPafAZDZD");

                //Try to post the information to the facebook page
                try
                {
                    var result = app.Post("/355852721418666/feed", messagePost);
                }

                //Log the Exception if an error occured
                catch (FacebookOAuthException ex)
                {
                    string filePath = @"C:\Logs\FacebookLog.txt";
                    using (StreamWriter writer = new StreamWriter(filePath, true))
                    {
                        writer.WriteLine("Error Posting at Facebook about new fan.");
                        writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                                         "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                        writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(fan));
        }
 public ActionResult Update(int Id, Fan Fan)
 {
     using (var context = new ShauliBlogContext())
     {
         var _fan = context.Fans.Where(a => a.Id == Id).SingleOrDefault();
         _fan.FirstName   = Fan.FirstName;
         _fan.LastName    = Fan.LastName;
         _fan.Birthday    = Fan.Birthday;
         _fan.Gender      = Fan.Gender;
         _fan.YearsInClub = Fan.YearsInClub;
         _fan.FanLocation = Fan.FanLocation;
         context.SaveChanges();
         return(RedirectToAction("FansList"));
     }
 }
 public ActionResult EditPost(int Id, Post Post)
 {
     using (var context = new ShauliBlogContext())
     {
         var _post = context.Posts.SingleOrDefault(a => a.PostId == Id);
         _post.ImageUrl          = Post.ImageUrl;
         _post.VideoUrl          = Post.VideoUrl;
         _post.Author            = Post.Author;
         _post.AuthorSiteAddress = Post.AuthorSiteAddress;
         _post.PostContent       = Post.PostContent;
         _post.PostTitle         = Post.PostTitle;
         context.SaveChanges();
         return(RedirectToAction("ManagePosts"));
     }
 }
        public ActionResult DeletePost(int Id, Post Post)
        {
            using (var context = new ShauliBlogContext())
            {
                var _post = context.Posts.SingleOrDefault(a => a.PostId == Id);

                //first remove comments of the selected post
                _post.Comments.RemoveRange(0, _post.Comments.Count);

                //then remove post it self
                context.Posts.Remove(_post);
                context.SaveChanges();
                return(RedirectToAction("ManagePosts"));
            }
        }
Example #13
0
        public ActionResult AddComment(Comment comment)
        {
            //Find the Post related to the comment
            Post post = db.Posts.SingleOrDefault(p => p.PostID == comment.PostID);

            if (post == null)
            {
                return(BlogView("", "", "", -1));
            }

            //Add the comment to the database
            post.Comments.Add(comment);
            db.SaveChanges();
            return(Redirect("/"));
        }
Example #14
0
        public ActionResult Index(int postID, string title, string author, string website, string comment)
        {
            Comment commentObj = new Comment()
            {
                PostID = postID, Title = title, Author = author, Website = website, Content = comment
            };

            db.Comments.Add(commentObj);
            db.SaveChanges();

            return(View(db.Posts.ToList()));
        }