Example #1
0
        public ActionResult MostRecent()
        {
            var db = new BlogDb(_connectionString);
            int id = db.GetMostRecentId();

            return(Redirect($"/home/viewblog?id={id}"));
        }
Example #2
0
        public ActionResult Index()
        {
            BlogDb dbhandle = new BlogDb();

            ModelState.Clear();
            return(View(dbhandle.GetAll()));
        }
Example #3
0
        public IActionResult Index(int page)
        {
            if (page <= 0)
            {
                page = 1;
            }
            int pageCount = 3;

            var db    = new BlogDb(_connectionString);
            var vm    = new HomePageViewModel();
            int total = db.GetPostsCount();

            if (page > 1)
            {
                vm.NextPage = page - 1;
            }
            int from = (page - 1) * pageCount;
            int to   = from + pageCount;

            if (to < total)
            {
                vm.PreviousPage = page + 1;
            }
            vm.Posts = db.GetPosts(from, pageCount);

            return(View(vm));
        }
Example #4
0
        public ActionResult MostRecent()
        {
            BlogDb db = new BlogDb(Properties.Settings.Default.ConStr);
            int    id = db.GetMostRecentId();

            return(Redirect($"/home/viewblog?id={id}"));
        }
Example #5
0
        public IActionResult AddPost(BlogPost post)
        {
            BlogDb db = new BlogDb();
            int    id = db.AddBlogPost(post);

            return(Redirect($"/home/displaypost?blogId={id}"));
        }
Example #6
0
        public ActionResult SubmitPost(BlogPost post)
        {
            BlogDb db = new BlogDb(_connectionString);

            post.DateCreated = DateTime.Now;
            db.AddPost(post);
            return(Redirect($"/home/viewblog?id={post.Id}"));
        }
Example #7
0
        public IActionResult AddComment(Comment comment, int blogId)
        {
            BlogDb db = new BlogDb();

            db.AddComment(comment, blogId);
            Response.Cookies.Append("commenterName", $"{comment.CommentAuthor}");
            return(Redirect($"/home/displaypost?blogid={blogId}"));
        }
Example #8
0
        public ActionResult AddComment(Comment comment)
        {
            BlogDb db = new BlogDb(Properties.Settings.Default.ConStr);

            comment.DateCreated = DateTime.Now;
            db.AddComment(comment);
            return(Redirect($"/home/viewblog?id={comment.PostId}"));
        }
Example #9
0
        public ActionResult SubmitPost(BlogPost post)
        {
            BlogDb db = new BlogDb(Properties.Settings.Default.ConStr);

            post.DateCreated = DateTime.Now;
            db.AddPost(post);
            return(Redirect($"/home/viewblog?id={post.Id}"));
        }
Example #10
0
        public ActionResult AddComment(Comment comment)
        {
            var db = new BlogDb(_connectionString);

            comment.DateCreated = DateTime.Now;
            db.AddComment(comment);
            Response.Cookies.Append("commenter-name", comment.Name);
            return(Redirect($"/home/viewblog?id={comment.PostId}"));
        }
Example #11
0
        public ActionResult AddComment(Comment comment)
        {
            BlogDb db = new BlogDb(Properties.Settings.Default.ConStr);

            comment.DateCreated = DateTime.Now;
            db.AddComment(comment);
            Response.Cookies.Add(new HttpCookie("commenter-name", comment.Name));
            return(Redirect($"/home/viewblog?id={comment.PostId}"));
        }
Example #12
0
        public ActionResult Post(int postId)
        {
            var db = new BlogDb(_connectionString);
            var vm = new BlogSingleViewModel();

            vm.Post     = db.GetPostById(postId);
            vm.Comments = db.GetCommentsForPost(postId);
            vm.Tags     = db.GetTagsForPost(postId);
            return(View(vm));
        }
Example #13
0
        public IActionResult MostRecent()
        {
            BlogDb   db   = new BlogDb();
            BlogPost post = db.GetBlogs().FirstOrDefault();

            if (post == null)
            {
                return(Redirect("/home/index"));
            }
            return(Redirect($"/home/displaypost?blogid={post.Id}"));
        }
Example #14
0
        public ActionResult EditBlog(int editableBlogId)
        {
            using (var BlogDb = new BlogDb())
            {
                var editableBlog = BlogDb.BlogProfiles.First(Blog => Blog.BlogID == editableBlogId);

                BlogDb.SaveChanges();

                return(View("EditBlog", editableBlog));
            }
        }
Example #15
0
        // GET: Blog
        public ActionResult Index()
        {
            using (var blogDb = new BlogDb())
            {
                //iegūt blogu sarakstu no blogu datu bāzes tabulas
                var blogListFromDb = blogDb.BlogProfiles.ToList();

                //iegūst skatu ar blogiem no tabulas
                return(View(blogListFromDb));
            }
        }
Example #16
0
 public ActionResult Edit(int id, BlogModel bmodel)
 {
     try
     {
         BlogDb sdb = new BlogDb();
         sdb.Update(bmodel);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Example #17
0
        public ActionResult ViewBlog(int?id)
        {
            if (!id.HasValue)
            {
                return(Redirect("/")); //if no id was sent in, redirect to home page
            }
            BlogDb            db = new BlogDb(Properties.Settings.Default.ConStr);
            ViewBlogViewModel vm = new ViewBlogViewModel();

            vm.Post     = db.GetPost(id.Value);
            vm.Comments = db.GetComments(id.Value);
            return(View(vm));
        }
Example #18
0
        //
        public ActionResult EditBlog(Blog blogs)
        {
            if (ModelState.IsValid == false)
            {
                return(View(blogs));
            }
            using (var BlogDb = new BlogDb())
            {
                BlogDb.Entry(blogs).State = EntityState.Modified;
                BlogDb.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Example #19
0
        public ActionResult AddBlog(Blog userCreatedBlog)
        {
            if (ModelState.IsValid == false)
            {
                return(View(userCreatedBlog));
            }

            using (var BlogDb = new BlogDb())
            {
                BlogDb.BlogProfiles.Add(userCreatedBlog);
                BlogDb.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
Example #20
0
        public ActionResult Index()
        {
            var db        = new BlogDb(_connectionString);
            var viewModel = new BlogsIndexViewModel
            {
                Posts = db.GetLastFive()
            };

            foreach (Post p in viewModel.Posts)
            {
                p.Text = StripTagsRegex(p.Text).Substring(0, 300) + "...";
            }
            return(View(viewModel));
        }
Example #21
0
        public ActionResult Comment(string name, string text, int postId)
        {
            var     db      = new BlogDb(_connectionString);
            Comment comment = new Comment
            {
                Date   = DateTime.Now,
                Name   = name,
                Text   = text,
                PostId = postId
            };

            db.AddComment(comment);
            return(RedirectToAction("Post", new { postId = postId }));
        }
Example #22
0
 public BlogWebAppUnitOfWork(BlogDb db, IGenericRepository <Article> articles,
                             IGenericRepository <Questionare> authors,
                             IGenericRepository <Feedback> feedbacks,
                             IGenericRepository <Tag> tags,
                             IGenericRepository <ArticleAndTag> articlesAndTags,
                             IGenericRepository <User> users)
 {
     Db              = db;
     Articles        = articles;
     Authors         = authors;
     Feedbacks       = feedbacks;
     Tags            = tags;
     ArticlesAndTags = articlesAndTags;
     Users           = users;
 }
        public ActionResult Login(Login lg)
        {
            var dbhandle = new BlogDb();

            if (dbhandle.Login(lg))
            {
                Session["User"] = lg;
                return(RedirectToAction("Index", "Blog"));
            }
            else
            {
                ViewBag.Message = "Invalid Credential!!!";
            }
            return(View());
        }
Example #24
0
        public IActionResult DisplayPost(int blogId)
        {
            BlogDb   db       = new BlogDb();
            BlogPost blogpost = db.GetPostToDisplay(blogId);

            if (blogpost.BlogText == null)
            {
                return(Redirect("/home/index"));  //if either '0', or an id that doesn't exist was sent it, redirects
            }
            DisplayPostViewModel vm = new DisplayPostViewModel();

            vm.BlogPost      = blogpost;
            vm.CommenterName = Request.Cookies["commenterName"];
            return(View(vm));
        }
Example #25
0
        public ActionResult DeleteBlog(int deletableBlogId)
        {
            using (var BlogDb = new BlogDb())
            {
                //atrast blogu ar konkreto Id numuru
                var removableBlog = BlogDb.BlogProfiles.First(BlogProfiles => BlogProfiles.BlogID == deletableBlogId);

                //izdzēst šo blogu no tabulas
                BlogDb.BlogProfiles.Remove(removableBlog);

                //saglabat veiktās izmaiņas datu bāzē
                BlogDb.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Example #26
0
 public ActionResult Delete(int id)
 {
     try
     {
         BlogDb sdb = new BlogDb();
         if (sdb.Delete(id))
         {
             ViewBag.AlertMsg = "Blog Deleted Successfully!!!";
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Example #27
0
        public ActionResult ViewBlog(int id)
        {
            if (id == 0)
            {
                return(Redirect("/")); //if no id was sent in, redirect to home page
            }
            BlogDb            db = new BlogDb(_connectionString);
            ViewBlogViewModel vm = new ViewBlogViewModel();

            vm.Post     = db.GetPost(id);
            vm.Comments = db.GetComments(id);
            if (Request.Cookies["commenter-name"] != null)
            {
                vm.CommenterName = Request.Cookies["commenter-name"];
            }
            return(View(vm));
        }
Example #28
0
        public IActionResult Index(int pagetodisplay)
        {
            IndexViewModel vm         = new IndexViewModel();        //to be used in all scopes here, returned in the View at the end
            BlogDb         db         = new BlogDb();
            decimal        totalBlogs = db.GetPostsCount();          //this gives me total number of posts

            vm.TotalPages = (int)Math.Ceiling(totalBlogs / 5);       //this gives the amount of valid pages
            if (pagetodisplay <= 1 || pagetodisplay > vm.TotalPages) //this sets if the query string was for an invalid page or no query, it'll go do default
            {
                vm.Posts = db.GetBlogs().Take(5).ToList();           //the currentpage is defaulted to one whether user selected pg one, went to home, or invalid query
            }
            else //if valid query string came in, it should skip all previous page contents and take the current page's
            {
                vm.CurrentPage = pagetodisplay;
                pagetodisplay--;
                vm.Posts = db.GetBlogs().Skip(pagetodisplay * 5).Take(5).ToList();
            }
            return(View(vm));
        }
Example #29
0
 public ActionResult Create(BlogModel bmodel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             BlogDb sdb = new BlogDb();
             if (sdb.Add(bmodel))
             {
                 ViewBag.Message = "Blog Details Added Successfully";
                 ModelState.Clear();
             }
         }
         return(View());
     }
     catch
     {
         return(View());
     }
 }
Example #30
0
        public ActionResult AddPost(string title, string text, string tags)
        {
            var db   = new BlogDb(_connectionString);
            var post = new Post {
                Date = DateTime.Now, Text = text, Title = title
            };

            db.AddPost(post);
            IEnumerable <Tag> postTags = tags.Split(',').Select(t =>
            {
                int tagId = db.AddTag(t);
                return(new Tag
                {
                    Id = tagId,
                    Name = t
                });
            });

            db.AddTagsToPost(post, postTags);
            return(RedirectToAction("Index", "Blog"));
        }