public ActionResult Index(int page = 0, string authorId = null)
        {
            var authors = GetUsersByRoleName("author");

            var entities = authorId != null
                ? _postManager.Get(x => !x.IsBlocked && x.AuthorId == authorId).Reverse()
                : _postManager.Get(x => !x.IsBlocked);

            var mostViewedData = entities.OrderByDescending(x => x.UsersReadCount).Take(MOST_VIEWED).ToList();
            var mostViewed     = _mapper.Map <IList <PostViewModel> >(mostViewedData);

            var count = entities.Count();

            var data        = entities.Reverse().Skip(page * PAGE_SIZE).Take(PAGE_SIZE).ToList();
            var entitiesMap = _mapper.Map <IList <PostViewModel> >(data);
            var result      = new AllPostsViewModel
            {
                Posts      = entitiesMap,
                MostViewed = mostViewed,
                Authors    = authors,
                Page       = page,
                MaxPage    = (count / PAGE_SIZE) - (count % PAGE_SIZE == 0 ? 1 : 0),
                AuthorId   = authorId
            };

            return(View(result));
        }
Beispiel #2
0
        //[HttpPost]
        //public ActionResult Delete(int inquiryId)
        //{
        //    Response<Inquiry> r = _inquiryManager.Get(inquiryId);

        //    if (!r.Success)
        //    {
        //        SetErrorTempData(r.Message);
        //    }
        //    if (ModelState.IsValid)
        //    {
        //        var manager = new InquiryManager();
        //        manager.Delete(inquiryId);
        //        //Return View Needs to be Changed
        //        return View("ManageInquiry","");
        //    }
        //    //Also Needs to be changed
        //    return View("ManageInquiry");
        //}

        public ActionResult BlogPost(int id)
        {
            Response <Post> r = _postManager.Get(id);

            if (!r.Success)
            {
                SetErrorViewData(r.Message);
            }

            return(View(r.Data));
        }
        public IActionResult RemovePost(int id)
        {
            PostDto post = _postManager.Get(id);

            _postManager.Remove(id);

            var deleteObj = new
            {
                id,
                postStatus = "Deleted"
            };

            return(Json(deleteObj));
        }
Beispiel #4
0
 // GET: api/Post/5
 public PostDetailsModel Get(int id)
 {
     return(_postManager.Get(id));
 }
Beispiel #5
0
        public void ManagerCanGetPostById()
        {
            var actual = _postManager.Get(1);

            Assert.AreEqual(1, actual.Data.Id);
        }
Beispiel #6
0
        public async Task <PostDTO> Get(long id)
        {
            var post = await postManager.Get(id);

            return(mapper.Map <PostDTO>(post));
        }
Beispiel #7
0
 // GET: api/Post/5
 public Post Get(int id)
 {
     return(_postManager.Get(id).Data);
 }