/// <summary> /// 刷新课表 /// </summary> /// <returns></returns> public async Task <(Status, string[][])> GetTable(bool reload = false) { try { if (AppUser == null) { return(Status.TokenExpired, null); } if (AnyNullOrWhiteSpace(AppUser.WhutId, AppUser.WhutPwd)) { return(Status.WhutIdNotFind, null); } var model = _tableDb.FindOrCreate(AppUser); if (reload || model.Table == null) { var res = await TryLogin(); if (res != Status.Ok) { return(res, null); } var html = await LoginUrl .Form("userName", AppUser.WhutId) .Form("password", AppUser.WhutPwd) .Form("type", "xs") .PostBodyAsync(); var tb = await html.ParseTable(); if (tb == null) { return(Status.WhutPwdWrong, null); } model.Table = tb; _tableDb.Update(model); return(Status.Ok, tb); } return(Status.Ok, model.Table); } catch { return(Status.WhutCrashed, null); } }
public static EntityEntry <E> UpdateDefault <E>(this IBaseDbContext dbContext, E entity, params Expression <Func <E, object> >[] changedProperties) where E : class { EntityEntry <E> entry; dbContext.TryAttach(entity, out entry); if (changedProperties?.Any() == true) { foreach (var property in changedProperties) { entry.Property(property).IsModified = true; } } else { return(dbContext.Update(entity)); } return(entry); }
public async Task <(Status, RinkDetail)> GetRink(bool reload = false) { try { if (AppUser == null) { return(Status.TokenExpired, null); } if (AnyNullOrWhiteSpace(AppUser.WhutId, AppUser.WhutPwd)) { return(Status.WhutIdNotFind, null); } var model = _rinkDb.FindOrCreate(AppUser); if (reload || model.RinkDetail == null) { var res = await TryLogin(); if (res != Status.Ok) { return(res, null); } //得到SessionId和位置 var(sessionid, location) = await GetSessionAndLocation(CerLogin, ScoreEntryUrl); if (sessionid == null || location == null) { return(Status.WhutPwdWrong, null); } //分数查询主页面 var html = await location .Cookie(CerLogin) .Cookie(sessionid) .GetBodyAsync(); //学科学分查询 var snkey = await html.ParseSnkeyAsync(); if (IsNullOrWhiteSpace(snkey)) { return(Status.WhutPwdWrong, null); } //绩点及排名查询查询请求 html = await RinkQueryUrl .Cookie(sessionid) .GetBodyAsync(); var rink = await html.ParseRinksAsync(); if (rink == null) { return(Status.WhutCrashed, null); } model.RinkDetail = rink; _rinkDb.Update(model); return(Status.Ok, rink); } return(Status.Ok, model.RinkDetail); } catch { return(Status.WhutCrashed, null); } }
/// <summary> /// 刷新分数 /// </summary> /// <returns></returns> public async Task <(Status, IEnumerable <ScoresDetail>)> GetScores(bool reload = false) { try { if (AppUser == null) { return(Status.TokenExpired, null); } if (AnyNullOrWhiteSpace(AppUser.WhutId, AppUser.WhutPwd)) { return(Status.WhutIdNotFind, null); } var model = _scoresDb.FindOrCreate(AppUser); if (reload || model.ScoresDetails == null) { var res = await TryLogin(); if (res != Status.Ok) { return(res, null); } //得到SessionId和位置 var(sessionid, location) = await GetSessionAndLocation(CerLogin, ScoreEntryUrl); if (sessionid == null || location == null) { return(Status.WhutCrashed, null); } //分数查询主页面 var html = await location .Cookie(CerLogin) .Cookie(sessionid) .GetBodyAsync(); //学科学分查询 var snkey = await html.ParseSnkeyAsync(); if (IsNullOrWhiteSpace(snkey)) { return(Status.WhutPwdWrong, null); } html = await ScoreQueryUrl .Cookie(sessionid) .Form("numPerPage", "100") .Form("pageNum", "1") .Form("snkey", snkey) .Form("xh", AppUser.WhutId) .PostBodyAsync(); var scores = await html.ParseScoresAsync(); if (scores == null) { return(Status.WhutPwdWrong, null); } model.ScoresDetails = scores; _scoresDb.Update(model); return(Status.Ok, scores); } return(Status.Ok, model.ScoresDetails); } catch { return(Status.WhutCrashed, null); } }