Exemple #1
0
        //==============Posts=============

        public ActionResult AdminPosts()
        {
            //authorize admin
            if (acl.AuthorizeAdmin(User.Identity.GetUserId()) == false)
            {
                return(HttpNotFound());
            }

            var userID = (string)null;
            var posts  = amposts.AdminPostListAll(userID);
            var mo     = new List <ShowPostViewModel>();

            foreach (var post in posts)
            {
                var temp = new ShowPostViewModel()
                {
                    PostId          = post.Id,
                    Title           = post.Title,
                    Email           = db.Users.Find(post.Owner).Email,
                    AreaName        = db.Areas.Find(post.AreaId).Name,
                    LocaleName      = db.Locales.Find(post.LocaleId).Name,
                    CategoryName    = db.Categories.Find(post.CategoryId).Name,
                    SubcategoryName = db.Subcategories.Find(post.SubcategoryId).Name,
                };
                mo.Add(temp);
            }

            return(View(mo));
        }
Exemple #2
0
        public ActionResult Show(int id, string slug, CommentViewModel commentViewModel)
        {
            var post = db.Posts.Find(id);

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

            if (post.Slug != slug)
            {
                return(RedirectToAction("Show", new { id = id, slug = post.Slug }));
            }

            if (ModelState.IsValid)
            {
                //yorumu ekleyeceğim kısım
                var comment = new Comment
                {
                    AuthorId         = User.Identity.GetUserId(),
                    Content          = commentViewModel.Content,
                    ParentId         = commentViewModel.ParentId,
                    CreationTime     = DateTime.Now,
                    ModificationTime = DateTime.Now,
                    State            = Enums.CommentState.Approved,
                    PostId           = id
                };

                db.Comments.Add(comment);
                db.SaveChanges();
                return(Redirect(Url.RouteUrl(
                                    new {
                    controller = "Post",
                    action = "Show",
                    id = id,
                    slug = slug,
                    commentSuccess = true
                }) + "#leave-a-comment"));
                //return RedirectToAction("Show", new { id = id, slug = slug, commentSuccess= true });
            }

            var vm = new ShowPostViewModel
            {
                Post             = post,
                CommentViewModel = commentViewModel
            };

            return(View(vm));
        }
Exemple #3
0
        // GET: Post/Delete/5
        public ActionResult PostDelete(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            var  userId = User.Identity.GetUserId();
            Post post   = db.Posts.Find((int)id);

            if (post.Hidden == true)
            {
                return(HttpNotFound());
            }
            if (acl.AuthorizeAdmin(userId) != true)
            {
                if (!acl.CheckPostLegal(userId, (int)id))
                {
                    return(HttpNotFound());
                }
            }

            if (!postl.CheckNotExpire((int)id))
            {
                TempData["Expire"] = "The post has expired, cannot Delete!";
                return(RedirectToAction("PostDetails", new { id = (int)id }));
            }


            var showpostmodel = new ShowPostViewModel();

            showpostmodel.Email      = db.Users.Find(post.Owner).Email;
            showpostmodel.PostId     = (int)id;
            showpostmodel.Timestamp  = post.Timestamp;
            showpostmodel.Expiration = post.Expiration;
            showpostmodel.Title      = post.Title;
            showpostmodel.Body       = post.Body;
            Area        area   = db.Areas.Find(post.AreaId);
            Locale      locale = db.Locales.Find(post.LocaleId);
            Category    cate   = db.Categories.Find(post.CategoryId);
            Subcategory sub    = db.Subcategories.Find(post.SubcategoryId);

            showpostmodel.AreaName        = area.Name;
            showpostmodel.LocaleName      = locale.Name;
            showpostmodel.CategoryName    = cate.Name;
            showpostmodel.SubcategoryName = sub.Name;

            return(View(showpostmodel));
        }
Exemple #4
0
        public ActionResult Show(int id, string slug)
        {
            var post = db.Posts.Find(id);

            if (post == null)
            {
                return(HttpNotFound());
            }
            if (post.Slug != slug)
            {
                return(RedirectToAction("Show", new { id = id, slug = post.Slug }));
            }
            var vm = new ShowPostViewModel
            {
                Post             = post,
                commentViewModel = new CommentViewModel()
            };

            return(View(vm));
        }
Exemple #5
0
        public IActionResult PostDetails(int postId)
        {
            var model = new ShowPostViewModel();

            var post = _postService.GetPost(postId);


            var categories = _categoryService.GetCategoryNamesByPostId(postId);
            var photosUrl  = _photoService.GetPhotosByPostId(postId);
            var mainPhoto  = _photoService.GetMainPhoto(postId);
            var comments   = _postService.GetComments(postId);

            var comm = new List <CommentViewModel>();

            for (int i = 0; i < comments.Count; i++)
            {
                comm.Add(new CommentViewModel
                {
                    Id          = comments[i].Id,
                    Content     = comments[i].Content,
                    Username    = _userService.GetUsernameByUserId(comments[i].UserId),
                    PublishDate = (DateTime)comments[i].Date
                });
            }

            model.Id               = postId;
            model.Title            = post.Title;
            model.ShortDescription = post.ShortDescription;
            model.LongDescription  = post.LongDescription;
            //model.Username = post.User.UserName;
            model.UserId        = post.UserId;
            model.PublishDate   = post.PublishDate;
            model.CategoryNames = categories;
            model.photosUrl     = photosUrl;
            model.MainPhoto     = mainPhoto;
            model.Comments      = comm;


            return(View(model));
        }
Exemple #6
0
        //GET
        public ActionResult Details(int?id, string returnUrl = null)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Post temp             = db.Posts.Find(id);
            ShowPostViewModel cur = new ShowPostViewModel
            {
                PostId          = (int)id,
                Title           = temp.Title,
                AreaName        = db.Areas.Find(temp.AreaId).Name,
                LocaleName      = db.Locales.Find(temp.LocaleId).Name,
                CategoryName    = db.Categories.Find(temp.CategoryId).Name,
                SubcategoryName = db.Subcategories.Find(temp.SubcategoryId).Name,
                Body            = temp.Body,
                Email           = db.Users.Find(temp.Owner).Email,
                Timestamp       = temp.Timestamp,
                ReturnUrl       = returnUrl == null?Request.UrlReferrer.ToString() : returnUrl
            };

            return(View(cur));
        }