Ejemplo n.º 1
0
        // GET: Comments
        public async Task <ActionResult> Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewBag.CurrentFilter = searchString;
            IEnumerable <Comment> entityList = null;

            if (await UserRoleManage.IsUserIdInRole(User.Identity.GetUserId(), "Admin"))
            {
                entityList = await _commentDal.QueryAllAsync();
            }
            else
            {
                entityList = await _commentDal.QueryByFunAsync(t => t.Creater == User.Identity.Name || t.LastModifier == User.Identity.Name);
            }
            if (entityList.Any())
            {
                if (!String.IsNullOrEmpty(searchString))
                {
                    entityList = entityList.Where(s => (s.Content != null && s.Content.Contains(searchString)) ||
                                                  (s.UserName != null && s.UserName.Contains(searchString)) ||
                                                  (s.Phone != null && s.Phone.Contains(searchString)));
                }
                switch (sortOrder)
                {
                case "name_desc":
                    entityList = entityList.OrderByDescending(s => s.UserName);
                    break;

                case "Date":
                    entityList = entityList.OrderBy(s => s.LastModifyDate);
                    break;

                case "date_desc":
                    entityList = entityList.OrderByDescending(s => s.LastModifyDate);
                    break;

                default:
                    entityList = entityList.OrderBy(s => s.UserName);
                    break;
                }
            }
            int pageSize   = 20;
            int pageNumber = (page ?? 1);

            return(View(entityList.ToPagedList(pageNumber, pageSize)));
        }
Ejemplo n.º 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         ddlUserRole.DataSourceID = null;
         ddlUserRole.DataSource   = UserRoleManage.GetALLUserRole();
         ddlUserRole.DataBind();
         ddlUserRole.Items.Insert(0, new ListItem("请选择用户类型", "-1"));
     }
 }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Admin admin = (Admin)Session["admin"];
            if (admin == null)
            {
                Response.Redirect("~/Login.aspx");
            }
            else
            {
                ddlUserRole.DataSourceID = null;
                ddlUserRole.DataSource   = UserRoleManage.GetALLUserRole();
                ddlUserRole.DataBind();
                Panelvisible();
            }
        }
        string UserRole = ddlUserRole.SelectedItem.Text.Trim();

        btnAddLost.Attributes.Add("onclick", "return confirm('您是要添加【" + UserRole + "】表的数据吗?');");
    }