// GET: BlogPosts/Details/5

        public ActionResult Details(string Slug)
        {
            //This action checks the slug to see if it is valid
            //If the slug is not valide return a bad request
            if (String.IsNullOrWhiteSpace(Slug))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BlogDetailsViewModel   model    = new BlogDetailsViewModel();
            IEnumerable <BlogPost> blogList = db.Posts;

            //Getting ViewModel data
            BlogPost blog = db.Posts.FirstOrDefault(p => p.Slug == Slug);
            var      prev = GetPrevious(blogList, blog);
            var      next = GetNext(blogList, blog);

            //Adding Data to ViewModel
            model.CurrentBlog  = blog;
            model.PreviousBlog = prev;
            model.NextBlog     = next;

            //FirstOrDefault finds the first or default record that matches the slug that I am searching for
            //BlogPost blogPost = db.Posts.FirstOrDefault(p => p.Slug == Slug);

            if (blog == null)
            {
                return(HttpNotFound());
            }

            return(View(model));
        }
Example #2
0
        public async Task EditBlogAsync(BlogDetailsViewModel blogModel)
        {
            var wantedBlog = this.db.Blogs.FirstOrDefault(x => x.Id == blogModel.Id);

            wantedBlog.Title       = blogModel.Title;
            wantedBlog.ImageUrl    = blogModel.Image;
            wantedBlog.Description = blogModel.Description;
            await this.db.SaveChangesAsync();
        }
Example #3
0
        public IActionResult Blogs()
        {
            var Blogs = new List <BlogModel>
            {
                new BlogModel()
                {
                    AuthorName   = "Atakan",
                    BlogName     = ".NET Ögreniyorum",
                    BlogCategory = "Eğitim"
                },
                new BlogModel
                {
                    AuthorName   = "Eylül",
                    BlogName     = "Dapper ORM Nedir?",
                    BlogCategory = "Eğitim",
                },
            };
            var Readers = new List <ReaderModel>
            {
                new ReaderModel
                {
                    ReaderName        = "Zehra",
                    CheckinTime       = new DateTime(2020, 07, 25),
                    FavouriteCategory = "Physics"
                },
                new ReaderModel
                {
                    ReaderName        = "Bertan",
                    CheckinTime       = new DateTime(2021, 04, 06),
                    FavouriteCategory = "Video Games"
                },
                new ReaderModel
                {
                    ReaderName        = "Serbülent",
                    CheckinTime       = new DateTime(2019, 04, 08),
                    FavouriteCategory = "Theatre"
                },
                new ReaderModel
                {
                    ReaderName        = "Beyza",
                    CheckinTime       = new DateTime(2020, 11, 17),
                    FavouriteCategory = "Literature"
                },
            };
            BlogDetailsViewModel Model = new BlogDetailsViewModel();

            Model.Readers = Readers;
            Model.Blogs   = Blogs;
            return(View(Model));
        }
Example #4
0
        // GET: Blog/{slug}
        public async Task <IActionResult> Details(string slug)
        {
            /*
             * We check if the slug is null
             * If it is then we return not found
             */
            if (slug == null)
            {
                return(NotFound());
            }

            /*
             * Setup the blog details view model and assign appropriate values
             */
            BlogDetailsViewModel viewModel = new BlogDetailsViewModel()
            {
                /*
                 * Get the post from the database based on the slug
                 */
                Post = await _DB.Posts
                       .FirstOrDefaultAsync(m => m.UrlSlug == slug)
            };

            /*
             * Double check the post that we get from the database hasn't returned null
             * Otherwise return not found
             */
            if (viewModel.Post == null)
            {
                return(NotFound());
            }

            /*
             * We can convert the post modified to a long date string using a custom reusable function.
             * We can then save that to the view model for easier access.
             */
            viewModel.ModifiedDate = ConvertDateToLongDateString(Convert.ToDateTime(viewModel.Post.Modified));

            /*
             * We can also use the view model to save related posts and better access the data.
             * We do this below by getting all posts that do not have the same id as the main post from the database
             * Then we save this to the view model.
             */
            viewModel.RelatedPosts = await _DB.Posts.Where(m => m.Id != viewModel.Post.Id)
                                     .ToListAsync();

            return(View(viewModel));
        }
Example #5
0
        public async Task <IActionResult> OnGet()
        {
            if (Id == Guid.Empty)
            {
                TempData["Warning"] = "An Id for selected Blog was not provided";
                return(RedirectToPage("/Admin/Blogs"));
            }

            var blog = await _blogService.GetBlogAsync(Id);

            ViewModel      = new BlogDetailsViewModel();
            ViewModel.Blog = new Blog();
            ViewModel.Blog = blog;

            return(Page());
        }
Example #6
0
        public ActionResult Details(int id)
        {
            GetBlogDetailsByIdQueryResult result = Query.For <GetBlogDetailsByIdQueryResult>().ById(id);

            if (!result.IsFound)
            {
                return(RedirectToAction("Index"));
            }

            BlogDetailsViewModel vm = new BlogDetailsViewModel
            {
                Blog      = result.Blog,
                LastBlogs = result.LastBlogs
            };

            return(View(vm));
        }
Example #7
0
        public ActionResult Details(string id)
        {
            using (var context = new BlogContext())
            {
                var korisnik = context.Korisniks.FirstOrDefault(k => k.KorisnickoIme == User.Identity.Name);

                var blogID = Convert.ToInt32(id);
                var blog   = context.Blogs.Find(blogID);
                if (blog.Odobren)
                {
                    var blogViewModel = new BlogDetailsViewModel()
                    {
                        BlogId                = blog.BlogId,
                        DatumPutovanja        = blog.DatumPutovanja,
                        Drzava                = blog.Drzava.Naziv,
                        Autor                 = blog.Korisnik.Ime + " " + blog.Korisnik.Prezime,
                        DatumKreiranja        = blog.DatumKreiranja,
                        Naslov                = blog.Naslov,
                        NaslovnaSlikaLink     = blog.NaslovnaSlikaLink,
                        Sadrzaj               = blog.Sadrzaj,
                        DozvolaDodavanjaSlika = (korisnik == null ? false : (korisnik.KorisnikId == blog.KorisnikId) ? true : false),
                        DaLiMiSeSvidjaBlog    = (korisnik == null ? false : korisnik.Blogs1.FirstOrDefault(b => b.BlogId == blog.BlogId) == null ? false : true)//(korisnik.Blogs1.FirstOrDefault(b => b.BlogId == blog.BlogId) != null?true:false)
                    };

                    ViewBag.Slike = blog.Slikas
                                    .Select(s => new SlikaViewModel
                    {
                        Link = s.Link
                    }).ToList();

                    ViewBag.Komentari = blog.Komentars
                                        .Select(k => new KomentarViewModel()
                    {
                        Komentar       = k.Sadrzaj,
                        Autor          = k.Korisnik.Ime + " " + k.Korisnik.Prezime,
                        DatumKreiranje = k.DatumKreiranja
                    }).ToList();

                    return(View(blogViewModel));
                }
                else
                {
                    return(RedirectToAction("Index", "Pocetna"));
                }
            }
        }
Example #8
0
        public ActionResult Blog(int id)
        {
            var blog = _unitOfWork.Blog.GetBlogById(id);

            var model = new BlogDetailsViewModel()
            {
                BlogType        = blog.BlogType.Name,
                Caption         = blog.Caption,
                Date            = blog.Date,
                Id              = blog.Id,
                Image           = blog.ImagePath + "/" + blog.ImageName,
                MetaDescription = blog.MetaDescription,
                MetaKeywords    = blog.MetaKeywords,
                Tags            = blog.Tags,
                Text            = blog.Text
            };

            ViewBag.TopImage = "/" + model.Image;
            ViewBag.Headline = model.Caption;

            return(View(model));
        }
Example #9
0
        public async Task <IActionResult> Edit(BlogDetailsViewModel blogModel)
        {
            await this.blogService.EditBlogAsync(blogModel);

            return(Ok("Done"));
        }