Beispiel #1
0
        public IActionResult NewBlogAction([FromBody] ManageNewBlogActionDto manageNewBlogActionDto)
        {
            if (HttpContext.Session.GetInt32("userId") == null)
            {
                return(Unauthorized());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest("bad boy"));
            }
            Data.Models.Blog blog = new Data.Models.Blog()
            {
                CategoryId = manageNewBlogActionDto.CategoryId,
                CreateDate = DateTime.UtcNow,
                Content    = manageNewBlogActionDto.Content,
                Title      = manageNewBlogActionDto.Title,
                Hit        = 0,
                Deleted    = false,
                UserId     = HttpContext.Session.GetInt32("userId").Value
            };

            _blogContext.Blogs.Add(blog);
            _blogContext.SaveChanges();
            return(new JsonResult(blog));
        }
 public IActionResult Detail(int id)//blogun ıdsi olacak
 {
     Data.Models.Blog blog = _blogContext.Blogs
                             .Include(a => a.User)
                             .Include(a => a.Comments)
                             .SingleOrDefault(a => a.Id == id);
     ViewData["Title"] = blog.Title;
     return(View(blog));
 }
Beispiel #3
0
        public IActionResult ManageBlog(int id)
        {
            if (HttpContext.Session.GetInt32("userId") == null)
            {
                return(RedirectToAction("Login", "Manage"));
            }
            Data.Models.Blog blogModel = new Data.Models.Blog();

            if (id != 0)
            {
                blogModel = _blogContext.Blogs.Find(id);
            }

            List <Category> categories = _blogContext.Categories.ToList();

            var resultTuple = new Tuple <int, List <Category>, Blog.Data.Models.Blog>(id, categories, blogModel);

            return(View(resultTuple));
        }
Beispiel #4
0
        public IActionResult ManageBlog(int id)
        {
            if (HttpContext.Session.GetInt32("userId") == null)
            {
                return(RedirectToAction("Login", "Manage"));
            }

            Data.Models.Blog blogModel = new Data.Models.Blog();


            if (id != 0)// var olan blog yazısını  düzenlemek için 0 dan farklı olanı getiriyor
            {
                blogModel = _blogContext.Blogs.Find(id);
            }

            List <Category> categories = _blogContext.Categories.ToList();

            var resultTuple = new  Tuple <int, List <Category>, Data.Models.Blog> (id, categories, blogModel);

            return(View(resultTuple));
        }