Exemple #1
0
        public IActionResult GetLessonCommentList(int id, DataTableParametersViewData gridData)
        {
            UserSessionContext userContext = new UserSessionContext(this.HttpContext);

            int pageIndex = (gridData.iDisplayStart / gridData.iDisplayLength) + 1;

            pageIndex = pageIndex <= 0 ? 0 : pageIndex - 1;
            var pageSize = gridData.iDisplayLength;
            int totalCount;

            LessonBusiness lessonBusinessManager = new LessonBusiness(DbContext);

            var comments = lessonBusinessManager.GetLessonComments(id, userContext.CurrentUser, userContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator, out totalCount);

            if (comments == null)
            {
                return(Json(null));
            }

            List <object> result = new List <object>();

            foreach (var comment in comments)
            {
                Dictionary <string, string> commentData = new Dictionary <string, string>();
                commentData.Add("Enabled", comment.Enabled.ToString());
                commentData.Add("Id", comment.Id.ToString());
                commentData.Add("Date", comment.CreateDate.ToDisplayDate());
                commentData.Add("User", HttpUtility.HtmlEncode(comment.CreateUser));
                commentData.Add("Type", comment.CommentType.Name + (comment.Enabled == true ? "" : " (Deleted)"));
                commentData.Add("Comment", HttpUtility.HtmlEncode(comment.Content));
                //@Url.Action("Delete", "Lesson", new { id = Model.Id }, "http")
                string buttonHtml = userContext.CurrentUser.RoleId == (int)Enumerations.Role.Administrator ?
                                    string.Format("<div><a href='#' class='{0}delete-comment float-left' data-url='{1}' data-commentType='{2}'><span class='float-left web-sprite sprite-{3}'></span>&nbsp;{0}Delete</a><div class='clear'></div></div>",
                                                  comment.Enabled == true ? "" : "Un-",
                                                  Url.Action((comment.Enabled == true ? "" : "Un") + "DeleteComment", "Lesson", new { id = comment.Id, lessonId = id }, "http"),
                                                  comment.CommentType.Name,
                                                  comment.Enabled == true ? "delete16" : "arrow-undo")
                    : "";
                commentData.Add("Actions", buttonHtml);

                var rawCommentData = (from c in commentData
                                      select c.Value).ToArray();

                result.Add(rawCommentData);
            }

            return(Json(
                       new
            {
                eEcho = gridData.sEcho,
                iTotalRecords = totalCount,
                iTotalDisplayRecords = totalCount,
                aaData = result
            }));
        }