示例#1
0
        public JsonResult ManageAjax(int draw, int start, int length)
        {
            var  data            = new List <object>();
            long recordsTotal    = 0;
            long recordsFiltered = 0;

            try
            {
                string searchText = HttpContext.Request.Form["search[value]"];
                searchText = searchText.Trim();
                #region OrderBy and Direction
                string orderBy  = HttpContext.Request.Form["order[0][column]"];
                string orderDir = HttpContext.Request.Form["order[0][dir]"];
                if (!string.IsNullOrEmpty(orderDir))
                {
                    orderDir = orderDir.ToUpper();
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    switch (orderBy)
                    {
                    case "0":
                        orderBy = "name";
                        break;

                    default:
                        orderBy = "";
                        break;
                    }
                }
                #endregion

                recordsTotal    = _pageService.Count(false, searchText);
                recordsFiltered = recordsTotal;
                List <NccPage> itemList       = _pageService.Load(start, length, false, searchText, orderBy, orderDir);
                string         controllerName = "CmsPage";
                foreach (var item in itemList)
                {
                    var str  = new List <string>();
                    var temp = "";
                    #region Title
                    temp = "";
                    if (GlobalContext.WebSite.IsMultiLangual)
                    {
                        foreach (var details in item.PageDetails)
                        {
                            if (!string.IsNullOrEmpty(temp))
                            {
                                temp += "<br />";
                            }
                            temp += "<b>" + details.Language + ":</b> " + details.Title;
                        }
                    }
                    else
                    {
                        temp = item.Name;
                    }
                    str.Add(temp);
                    #endregion
                    if (item.Parent != null)
                    {
                        str.Add(item.Parent.PageDetails.FirstOrDefault().Title);
                    }
                    else
                    {
                        str.Add("-");
                    }

                    if (item.CreateBy == item.ModifyBy)
                    {
                        str.Add(_nccUserService.Get(item.CreateBy)?.UserName);
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + _nccUserService.Get(item.CreateBy)?.UserName + "<br /><b>Mo:</b> " + _nccUserService.Get(item.ModifyBy)?.UserName);
                    }

                    str.Add(item.PageStatus == NccPageStatus.Published ? NccPageStatus.Published.ToString() + ": " + item.PublishDate.ToString("yyyy-MM-dd hh:mm tt") : "Update: " + item.ModificationDate.ToString("yyyy-MM-dd hh:mm tt"));
                    str.Add(item.Layout);
                    str.Add(item.PageType.ToString());
                    str.Add("[Page Id=\"" + item.Id + "\" Page]");

                    string actionLink = " <a href='" + Url.Action("CreateEdit", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-primary btn-outline'>Edit</a> ";
                    //if (item.Status == EntityStatus.Active)
                    //    actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger btn-outline'>Inactive</a> ";
                    //else
                    //    actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-success btn-outline'>Active</a> ";
                    actionLink += " <a href='" + Url.Action("Delete", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger'>Delete</a> ";
                    if (GlobalContext.WebSite.IsMultiLangual == true)
                    {
                        actionLink += "";
                        foreach (var PageDetails in item.PageDetails)
                        {
                            actionLink += " <a href='/" + PageDetails.Language + "/" + PageDetails.Slug + "' target='_blank' class='btn btn-outline btn-info btn-xs'><i class='fa fa-eye'></i> " + PageDetails.Language + "</a> ";
                        }
                    }
                    else
                    {
                        actionLink += " <a href='/" + item.PageDetails.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault().Slug + "'  target='_blank' class='btn btn-outline btn-info btn-xs'><i class='fa fa-eye'></i> " + item.PageDetails.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault().Language + "</a> ";
                    }
                    str.Add(actionLink);
                    data.Add(str);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(Json(new
            {
                draw = draw,
                recordsTotal = recordsTotal,
                recordsFiltered = recordsFiltered,
                start = start,
                length = length,
                data = data
            }));
        }