示例#1
0
        public ActionResult Index(FormCollection f)
        {
            var _role = new RoleRepo();

            if (f["act"] == "del")
            {
                _repo.Remove(Utils.Split(f["id"]));
            }

            ViewBag.Roles = _role.List();

            long         _totalRows;
            IMongoSortBy _sort = SortBy <User> .Descending(x => x.Created);

            IMongoQuery _query = Query.Null;

            if (f.Count > 0)
            {
                var _kwd    = f["kwd"];
                var _dir    = f["dir"];
                var _sortBy = f["sort"];
                var _stt    = f["stt"];
                var _roleId = f["rid"];

                var _queries =
                    MainDb.Map(
                        Query.And(Query <User> .GTE(x => x.Created, DateTime.Parse(f["from"])),
                                  Query <User> .LTE(x => x.Created, DateTime.Parse(f["to"]))),

                        !string.IsNullOrWhiteSpace(_stt)
                            ? Query <User> .EQ(x => x.Status, int.Parse(_stt))
                            : Query.Null,
                        !string.IsNullOrWhiteSpace(_roleId)
                            ? Query <User> .EQ(x => x.RoleId, ObjectId.Parse(_roleId))
                            : Query.Null,
                        !string.IsNullOrWhiteSpace(_kwd)
                            ? Query.Or(
                            Query <User> .Matches(x => x.UserName,
                                                  BsonRegularExpression.Create(new Regex(_kwd, RegexOptions.IgnoreCase))),
                            Query <User> .Matches(x => x.Address,
                                                  BsonRegularExpression.Create(new Regex(_kwd, RegexOptions.IgnoreCase))),
                            Query <User> .Matches(x => x.FullName,
                                                  BsonRegularExpression.Create(new Regex(_kwd, RegexOptions.IgnoreCase)))
                            )
                            : Query.Null);

                if (_queries.Count > 0)
                {
                    _query = Query.And(_queries);
                }


                _sort = _dir.ToLower() == "asc" ? SortBy.Ascending(_sortBy) : SortBy.Descending(_sortBy);
            }


            var _data = _repo.Search(_query, _sort, IWebContext.PageIndex, IWebContext.Configuration.PageSize, out _totalRows);

            if (Request.IsAjaxRequest() && string.IsNullOrWhiteSpace(Request.QueryString["f"]))
            {
                return(PartialView("List", _data));
            }
            return(View(_data));
        }