예제 #1
0
        public async Task <IActionResult> LockPost(int blogId, int id)
        {
            BlogPost bp = bprepository.GetBlogPost(id);
            Blog     b  = brepository.get(blogId);
            //bp.Author = await userManager.FindByIdAsync(bp.AuthorId);
            var isAuthorized = await auth.AuthorizeAsync(
                User, bp.Author, UserOperations.UserRole);

            var isA = await auth.AuthorizeAsync(
                User, b.User, UserOperations.UserRole);

            if (!isAuthorized.Succeeded)
            {
                if (!isA.Succeeded)
                {
                    return(View("Ingentilgang"));
                }
                return(View("Ingentilgang"));
            }


            bprepository.Lock(id);
            if (bp.IsLocked == 0)
            {
                TempData["message"] = "Blogg låst";
            }
            else
            {
                TempData["message"] = "Blogg åpnet";
            }

            return(RedirectToAction("BlogPost", new { @blogId = blogId, @id = id }));
        }
예제 #2
0
        public ActionResult Edit(int id)
        {
            var model = PopulatedCategorySelectListItem();

            model.BlogPost          = _blogPostRepo.GetBlogPost(id);
            model.TagString         = string.Join(" ", model.BlogPost.AssignedTags.Select(assignedTag => assignedTag.TagName));
            model.BlogPost.EditDate = DateTime.UtcNow;

            return(View(model));
        }
예제 #3
0
 public IActionResult Comment(CommentViewModel model)
 {
     if (ModelState.IsValid)
     {
         var Comment = new BlogComments()
         {
             UserName      = model.UserName,
             UserId        = userManager.GetUserId(User),
             BlogPostId    = model.PostId,
             Body          = model.Comment,
             TimeOfComment = DateTime.Now,
             UserPicture   = model.ProfilePicture,
         };
         _commentRepository.Comment(Comment);
         _blogPostRepository.GetBlogPost(model.PostId).NumberOfComments = context.BlogComments.Where(x => x.BlogPostId == model.PostId).Count();
         context.SaveChanges();
         return(RedirectToAction("Details", new { id = Comment.BlogPostId }));
     }
     return(View());
 }
예제 #4
0
        public ViewResult AddOrEditBlogPost(int?id)
        {
            var model = new AdminBlogFull();

            //pass empty model to view for new post
            if (id == null)
            {
                model.Date = DateTime.Now.ToString("d");
                return(View(model));
            }

            //otherwise, pass current blog data to be edited
            var post = _blogRepo.GetBlogPost((int)id);

            model.Date      = post.Date.ToString("d");
            model.Id        = post.Id;
            model.Text      = post.Text;
            model.Title     = post.Title;
            model.RouteName = post.RouteName;
            return(View(model));
        }
예제 #5
0
        public async Task <IActionResult> GetBlogPost(int id)
        {
            var blogPost = await _repo.GetBlogPost(id);

            return(Ok(blogPost));
        }
예제 #6
0
 public Task <BlogPost> GetBlogPost(int blogpost_id)
 {
     return(blogPostRepository.GetBlogPost(blogpost_id));
 }
예제 #7
0
 public BlogPost GetBlogPost(int blogID)
 {
     return(_blogPostRepo.GetBlogPost(blogID));
 }
예제 #8
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var blogPost = repo.GetBlogPost();

            return(View(blogPost));
        }
예제 #9
0
        public IActionResult Posts(int postID)
        {
            var post = blogPostRepository.GetBlogPost(postID);

            return(View(post));
        }