Exemplo n.º 1
0
        public ActionResult Comments([Deserialize] commentVars model, int?commentPage)
        {
            int        TotalRows = 0;
            SqlCommand outputCommand;

            int pageNumber = commentPage ?? 1;
            int pageSize   = 20;

            List <SqlParameter> prams = new List <SqlParameter>();

            //var totlRes = new SqlParameter("TotalRows", SqlDbType.Int, 50);
            //totlRes.Direction = ParameterDirection.Output;
            //prams.Add(totlRes);

            if (commentPage == null)
            {
                prams.Add(new SqlParameter("pageSize", 2));
            }
            else
            {
                prams.Add(new SqlParameter("PagNum", pageNumber));
            }
            prams.Add(new SqlParameter("elemId", model.elemId));
            prams.Add(new SqlParameter("typ", model.typ));
            prams.Add(new SqlParameter("TBL", model.typ.ToString()));

            var reader = unitOfWork.ReaderRepository.GetSPDataReader("Comments", prams, out outputCommand);
            List <CommentEach> comms = new List <CommentEach>();

            while (reader.Read())
            {
                CommentEach comm = new CommentEach();
                comm.cmtID   = reader.GetInt32(0);
                comm.comment = reader[1] as string;
                comm.date    = reader.GetDateTime(2);
                comm.likes   = reader.GetInt32(9);

                ActiveUser commenter = new ActiveUser();
                commenter.UserId      = reader.GetInt32(3);
                commenter.firstName   = reader[4] as string;
                commenter.firstNameEN = reader[5] as string;
                commenter.lastName    = reader[6] as string;
                commenter.lastNameEN  = reader[7] as string;
                commenter.image       = reader[8] as string;

                comm.CommenterUser = commenter;

                comms.Add(comm);
            }
            ViewData["finalPage"] = !reader.HasRows;
            reader.Close();

            //TotalRows = (int)outputCommand.Parameters["TotalRows"].Value;

            ViewData["pageNum"] = pageNumber;

            if (commentPage == null)
            {
                return(PartialView(new CommentViewModel
                {
                    Comments = comms,
                    prams = model
                }));
            }
            else
            {
                return(PartialView("NextComments", new CommentViewModel
                {
                    Comments = comms,
                    prams = model
                }));
            }
        }
Exemplo n.º 2
0
        //[AjaxRequestOnly]
        //[HostControl]
        public ActionResult CommentInsert([Deserialize] commentVars model, string comment)
        {
            if (!ModelState.IsValid)
            {
                throw new ModelStateException(this.ModelState);
            }
            var reader = unitOfWork.ReaderRepository.GetSPDataReader(
                "CommentInsert",
                new SqlParameter("U", WebSecurity.CurrentUserId),
                new SqlParameter("elemId", model.elemId),
                new SqlParameter("TBL", model.typ.ToString()),
                new SqlParameter("text", comment)
                );

            CommentEach cmt = new CommentEach();

            if (reader.Read())
            {
                cmt.cmtID   = reader.GetInt32(0);
                cmt.comment = reader[1] as string;
                cmt.date    = reader.GetDateTime(2);
                ActiveUser us = new ActiveUser();
                us.UserId         = reader.GetInt32(3);
                us.firstName      = reader[4] as string;
                us.firstNameEN    = reader[5] as string;
                us.lastName       = reader[6] as string;
                us.lastNameEN     = reader[7] as string;
                cmt.CommenterUser = us;

                ViewData["typ"] = model.typ;
            }

            NotificationType notiftyp = NotificationType.PostLike;
            FeedType         feedtyp  = FeedType.PostLike;

            switch (model.typ)
            {
            case CommentType.CommentPost:
                notiftyp = NotificationType.PostComment;
                feedtyp  = FeedType.PostComment;
                break;

            case CommentType.CommentQuestion:
                notiftyp = NotificationType.QuestionComment;
                feedtyp  = FeedType.QuestionComment;
                break;

            case CommentType.CommentAnswer:
                notiftyp = NotificationType.AnswerComment;
                feedtyp  = FeedType.AnswerComment;
                break;

            case CommentType.CommentProduct:
                notiftyp = NotificationType.ProductComment;
                feedtyp  = FeedType.ProductComment;
                break;

            case CommentType.CommentService:
                notiftyp = NotificationType.ServiceComment;
                feedtyp  = FeedType.ServiceComment;
                break;

            case CommentType.CommentGSO:
                notiftyp = NotificationType.SessionOfferComment;
                feedtyp  = FeedType.SessionOfferComment;
                break;
            }
            NotificationHelper.NotificationInsert(notiftyp, elemId: model.elemId);
            FeedHelper.FeedInsert(feedtyp, model.elemId, WebSecurity.CurrentUserId);


            return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "NewInsertedComment", cmt) }));
        }