예제 #1
0
        /// <summary>
        /// Gets all account log  LINQ.
        /// </summary>
        /// <param name="totalRecords">The total records.</param>
        /// <param name="currentPage">The current page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="sortBy">The sort by.</param>
        /// <param name="descending">if set to <c>true</c> [descending].</param>
        /// <param name="loginName">The login name.</param>
        /// <param name="fromDate">From date.</param>
        /// <param name="toDate">To date.</param>
        /// <param name="status">The status.</param>
        /// <returns></returns>
        public IEnumerable <AccountLogin> GetAllLogItems(out int totalRecords,
                                                         int currentPage   = 1,
                                                         int pageSize      = 25,
                                                         bool descending   = true,
                                                         string sortBy     = "LoginTime",
                                                         string loginName  = "",
                                                         DateTime?fromDate = null,
                                                         DateTime?toDate   = null,
                                                         bool?status       = null
                                                         )
        {
            var spec = LogQuery.WithAll();

            spec = !string.IsNullOrEmpty(loginName) ? LogQuery.WithLoginName(loginName) : spec;
            spec = fromDate != null
                    ? spec.And(LogQuery.WithFromDate(fromDate))
                    : spec;

            spec = toDate.HasValue
                    ? spec.And(LogQuery.WithToDate(toDate.Value.AddDays(1)))
                    : spec;
            spec = status != null
                    ? spec.And(LogQuery.WithStatus(status))
                    : spec;

            totalRecords = _items.Count(spec);
            var sort = Context.Filters.Sort <AccountLogin, DateTime>(al => al.LoginTime, true);

            switch (sortBy)
            {
            case "LoginTime":
                sort = Context.Filters.Sort <AccountLogin, DateTime>(al => al.LoginTime, descending);
                break;

            case "LoginIP":
                sort = Context.Filters.Sort <AccountLogin, string>(al => al.LoginIP, descending);
                break;

            case "LoginName":
                sort = Context.Filters.Sort <AccountLogin, string>(al => al.LoginName, descending);
                break;
            }
            var pager = Context.Filters.Page <AccountLogin>(currentPage, pageSize);

            return(_items.Find(spec, sort, pager));
        }