public ActionResult Index(int? page) { DateTime dt = DateTime.Now; DateTime endTime = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d"))); NameValueCollection q = new NameValueCollection(); q.Add("CreatedAtStart", endTime.AddDays(-1).ToString("yyyy/MM/dd 10:00")); q.Add("CreatedAtEnd", DateTime.Now.AddHours(1).ToString("yyyy/MM/dd HH:00")); InspectOriginQueryModel query = new InspectOriginQueryModel(q); IPagedList<InspectOrigin> inspects = null; using (var txn = new System.Transactions.TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted })) { using (IUnitOfWork unitOfWork = new TskDataDataContext(DbUtil.ConnectionString)) { int currentPageIndex = page.HasValue ? (page.Value <= 0 ? 0 : page.Value - 1) : 0; IInspectOriginRep inspectOriginRep = new InspectOriginRep(unitOfWork); inspects = inspectOriginRep.Queryable(query.CreatedAtStart,query.CreatedAtEnd).ToPagedList(currentPageIndex, int.Parse(Resources.PageSize)); } } ViewBag.Query = query; return View(inspects); }
private IQueryable<InspectOrigin> GenerateQuery(IUnitOfWork unitOfWork, InspectOriginQueryModel query) { IInspectOriginRep inspectRep = new InspectOriginRep(unitOfWork); return inspectRep.Queryable().Where(item => //(string.IsNullOrEmpty(query.Text) ? true : item.Text.Contains(query.Text))&& (query.ProcessResult.HasValue ? item.ProcessResult.Equals(query.ProcessResult) : true) && (query.CreatedAtStart.HasValue ? item.CreatedAt >= query.CreatedAtStart : true) && (query.CreatedAtEnd.HasValue ? item.CreatedAt <= query.CreatedAtEnd : true) ); }