public ActionResult GetManagedContests(string Token, int? Page) { var user = CheckUser(Token); if (user == null) return Json(new Contests { List = null, Code = 500, IsSuccess = false, PageCount = -1, Info = "AccessToken不正确" }); if (Page == null) Page = 0; IQueryable<Entity.Contest> contests = (from c in DbContext.Contests orderby c.End descending select c); if (user.Role < Entity.UserRole.Master) contests.Where(x=> (from cm in x.Managers select cm.UserID).Contains(user.ID)); contests.Skip(10 * Page.Value).Take(10).ToList(); var ret = new Contests() { Code = 0, IsSuccess = true, Info = "", PageCount = Convert.ToInt32(Math.Ceiling(DbContext.Contests.Count() / 10f)), List=new List<Contest>() }; foreach (var contest in contests) { ret.List.Add(new Contest { ContestID = contest.ID, Begin = contest.Begin, End = contest.End, Format = contest.Format.ToString(), FormatAsInt = contest.FormatAsInt, RestBegin = contest.RestBegin, RestEnd = contest.RestEnd, Title = contest.Title }); } return Json(ret); }
public ActionResult GetContests(string Token, int? Page) { var user = CheckUser(Token); if(user == null) return Json(new Contests { List = null, Code = 500, IsSuccess = false, Info = "AccessToken不正确" }); if (Page == null) Page = 0; var HistroyTime = Convert.ToDateTime("2014-8-1 0:00"); var contests = (from c in DbContext.Contests where c.End >=HistroyTime orderby c.End descending select c).Skip(10 * Page.Value).Take(10).ToList(); var ret = new Contests { Code = 0, IsSuccess = true, Info = "", PageCount = DbContext.Contests.Count() / 10 + 1 , List = new List<Contest>() }; foreach (var contest in contests) { ret.List.Add(new Contest { ContestID = contest.ID, Begin= contest.Begin, End=contest.End, Format=contest.Format.ToString(), FormatAsInt = contest.FormatAsInt, RestBegin = contest.RestBegin, RestEnd = contest.RestEnd, Title = contest.Title }); } return Json(ret); }