Esempio n. 1
0
        public ActionResult Details(int id, int pageindex = 1)
        {
            List <Comment> list;
            List <Comment> hotlist = new List <Comment>();

            using (ICommentBusiness iComment = new CommentBusiness(new JustSayEntities()))
            {
                list = (iComment.LoadPageEntities(10, pageindex, c => c.FunnyID == id, c => c.Time));

                if (Request.IsAjaxRequest())
                {
                    ViewBag.FunnyID = id;
                    return(PartialView("~/Views/Comment/FunnyComment.cshtml", list));
                }
                if (pageindex == 1 && iComment.Count(c => c.FunnyID == id) > 20)
                {
                    hotlist = iComment.LoadEntities(c => c.FunnyID == id).OrderByDescending(c => c.Up).Take(5).ToList();
                    ViewData["IsHasHot"] = true;
                }
                Funny funny = iFunny.GetDetail(id);
                ViewData["list"]    = list;
                ViewData["hotlist"] = hotlist;

                return(View(funny));
            }
        }
Esempio n. 2
0
        public ActionResult Details(int id, int pageindex = 1)
        {
            List<Comment> list;
            List<Comment> hotlist = new List<Comment>();
            using (ICommentBusiness iComment = new CommentBusiness(new JustSayEntities()))
            {
                list=(iComment.LoadPageEntities(10, pageindex, c => c.FunnyID == id, c => c.Time));

                if (Request.IsAjaxRequest())
                {
                    ViewBag.FunnyID = id;
                    return PartialView("~/Views/Comment/FunnyComment.cshtml", list);

                }
                if (pageindex == 1 && iComment.Count(c => c.FunnyID == id) > 20)
                {
                    hotlist=iComment.LoadEntities(c => c.FunnyID == id).OrderByDescending(c => c.Up).Take(5).ToList();
                    ViewData["IsHasHot"] = true;
                }
                Funny funny = iFunny.GetDetail(id);
                ViewData["list"] = list;
                ViewData["hotlist"] = hotlist;
               
                return View(funny);
            }
            
        }
Esempio n. 3
0
        /// <summary>
        /// Mocks the DB context that it contains the entries given as paramether.
        /// </summary>
        /// <param name="dataList">The list of all the entries that should be in the database</param>
        /// <exception cref="NotImplementedException">Thrown then context.Entry function is called</exception>
        public void getDbContext(List <Comment> dataList)
        {
            var data = dataList.AsQueryable();

            mockSet = new Mock <DbSet <Comment> >();

            mockSet.As <IQueryable <Comment> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Comment> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Comment> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Comment> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            mockContext = new Mock <DBContext>();
            mockContext.Setup(x => x.Comments).Returns(mockSet.Object);
            mockContext.Setup(x => x.Entry(It.IsAny <Comment>())).Throws(new NotImplementedException());

            db = new CommentBusiness(mockContext.Object);
        }
Esempio n. 4
0
 public JsonResult LoadAllComments(int blogId)
 {
     try
     {
         if (blogId != 0)
         {
             var result   = CommentBusiness.LoadAllComments(blogId);
             var response = new ApiRespnoseWrapper {
                 Status = ApiRespnoseStatus.Success, Results = new ArrayList()
                 {
                     result
                 }
             };
             return(new JsonResult {
                 Data = response
             });
         }
         else
         {
             var response = new ApiRespnoseWrapper {
                 Status = ApiRespnoseStatus.Failed, Results = new ArrayList()
                 {
                     "No Blog found"
                 }
             };
             return(new JsonResult {
                 Data = response
             });
         }
     }
     catch (Exception ex)
     {
         CommonFunctions.LogDetails(ex, null);
         return(CommonBusiness.GetErrorResponse());
     }
 }
Esempio n. 5
0
 public JsonResult AddNewComment(CommentModelDTO model)
 {
     try
     {
         var addStatus = CommentBusiness.AddNewComment(model);
         if (addStatus == "Success")
         {
             var response = new ApiRespnoseWrapper {
                 Status = ApiRespnoseStatus.Success, Results = new ArrayList()
                 {
                     addStatus
                 }
             };
             return(new JsonResult {
                 Data = response
             });
         }
         else
         {
             var response = new ApiRespnoseWrapper {
                 Status = ApiRespnoseStatus.Failed, Results = new ArrayList()
                 {
                     addStatus
                 }
             };
             return(new JsonResult {
                 Data = response
             });
         }
     }
     catch (Exception ex)
     {
         CommonFunctions.LogDetails(ex, null);
         return(CommonBusiness.GetErrorResponse());
     }
 }
Esempio n. 6
0
        public async Task <IActionResult> Delete(int id)
        {
            await CommentBusiness.Delete(id, User.Account());

            return(NoContent());
        }
Esempio n. 7
0
        public async Task <ActionResult <CommentResponse> > Update([FromBody] CommentUpdateRequest comment)
        {
            var response = await CommentBusiness.Update((Comment)comment, User.Account());

            return((CommentResponse)response);
        }
Esempio n. 8
0
        public async Task <ActionResult <CommentResponse> > Create([FromBody] CommentCreateRequest comment)
        {
            var response = await CommentBusiness.Add((Comment)comment, User.Account());

            return(CreatedAtAction(nameof(Create), (CommentResponse)response));
        }
Esempio n. 9
0
 public ActionResult <CommentResponse> Item(int id) => (CommentResponse)CommentBusiness.Get(id);
Esempio n. 10
0
        public CommentController()
        {
            ShipperHNDBcontext shipperHndBcontext = new ShipperHNDBcontext();

            _commentBusiness = new CommentBusiness(shipperHndBcontext);
        }