public static void Insert(AthleteModel athlete) { var sql = new StringBuilder(); sql.Append("insert into athletes(" + "ID, " + "MATCH_ID, " + "TEAM_NAME, " + "TEAM_SHORT_NAME, " + "GROUP_NAME, " + "NAME, " + "SEX, " + "BAR_GROUP_GAMES_STATUS, " + "BAR_INDIVIDUAL_GAMES_STATUS, " + "WAY_GROUP_GAMES_STATUS, " + "WAY_INDIVIDUAL_GAMES_STATUS, " + "IDCARD, " + "PHONE, " + "ACCOMMODATION_REQUIREMENTS, " + "IS_VEGETARIAN, " + "CLOTHING_SIZE) values"); sql.Append($"('{athlete.Id}','{athlete.MatchId}','{athlete.TeamName}','{athlete.TeamShortName}','{athlete.GroupName}','{athlete.Name}'," + $"'{athlete.Sex}','{athlete.BarGroupGamesStatus}','{athlete.BarIndividualGamesStatus}','{athlete.WayGroupGamesStatus}'," + $"'{athlete.WayIndividualGamesStatus}'," + $"'{athlete.IdCard}','{athlete.Phone}','{athlete.AccommodationRequirements}','{athlete.IsVegetarian}','{athlete.ClothingSize}')"); SQLiteHelper.ExecuteNonQuery(SQLiteHelper.LocalDbConnectionString, sql.ToString(), CommandType.Text); }
private void GetDoubleWayAthletes(ISheet sheet, List <AthleteModel> result) { for (var row = 38; row < 41; row++) { var athleteWM = new AthleteModel(); athleteWM.WayIndividualGamesStatus = "参加"; athleteWM.Sex = "男女"; athleteWM.Name = ExcelHelper.GetStringValue(sheet, row, 1); var athleteW = new AthleteModel(); athleteW.WayIndividualGamesStatus = "参加"; athleteW.Sex = "女女"; athleteW.Name = ExcelHelper.GetStringValue(sheet, row, 5); var athleteM = new AthleteModel(); athleteM.WayIndividualGamesStatus = "参加"; athleteM.Sex = "男男"; athleteM.Name = ExcelHelper.GetStringValue(sheet, row, 9); if (athleteWM.Name != "/") { result.Add(athleteWM); } if (athleteW.Name != "/") { result.Add(athleteW); } if (athleteM.Name != "/") { result.Add(athleteM); } } }
public IActionResult AthleteList(int?id) { AthleteModel model = new AthleteModel(); string message = string.Empty; try { model.athleteList = BALUser.GetAthletesByTypeId(id.ToSafeInt(), _configuration["DomainName"].ToSafeString()); model.TestId = id.ToSafeInt(); if (TempData["message"] != null) { message = TempData["message"].ToSafeString(); ViewBag.Message = message; if (TempData["IsSuccess"].ToSafeInt() == 0) { ViewBag.IsError = 1; } else { ViewBag.IsForgotPwdSucc = 1; } } } catch (System.Exception) { throw; } return(View(model)); }
public IActionResult CreateNewAthlete(AthleteModel model) { int result = 0; string domainName = _configuration["DomainName"].ToSafeString(); if (!string.IsNullOrEmpty(domainName)) { AthleteTestMapping athleteTest = new AthleteTestMapping(); athleteTest.AthleteTestId = model.TestId.ToSafeInt(); athleteTest.AthleteId = model.AthleteId.ToSafeInt(); athleteTest.Distance = model.Distance; if (model.IsEditMode) { result = BALUser.AddAthlete(athleteTest, domainName, 1, model.MapId.ToSafeInt()); } else { result = BALUser.AddAthlete(athleteTest, domainName, 0, model.MapId.ToSafeInt()); } switch (result) { case -1: TempData["message"] = "Athlete already exists in this test."; TempData["IsSuccess"] = 0; break; case 0: TempData["message"] = "Something went wrong."; TempData["IsSuccess"] = 0; break; case 1: TempData["message"] = "Record successfully inserted."; TempData["IsSuccess"] = 1; break; case 2: TempData["message"] = "Record successfully updated."; TempData["IsSuccess"] = 1; break; } } return(RedirectToAction("AthleteList", new { id = model.TestId })); }
private async Task GetProfileAsync(CancellationToken cancellationToken) { try { AthleteModel athleteModel = await _userProfileService.GetProfileAsync(cancellationToken); if (athleteModel != null) { Console.WriteLine("Found athlete profile:"); Console.WriteLine($"Name: {athleteModel.FirstName} {athleteModel.LastName}"); Console.WriteLine($"Id: {athleteModel.Id}"); Console.WriteLine($"Country: {athleteModel.Country}"); } } catch (Exception ex) { string errorMessage = "An error occurred: " + ex; Console.WriteLine(errorMessage); _logger.LogError(errorMessage); } }
public void Update() { AthleteDisplayModel exists = Athletes.Where(x => x.Id == SelectedAthlete.Id).FirstOrDefault(); if (exists != null) { if (SelectedAthlete != null && Athletes.Count > 0) { isUpdating = true; AthleteModel e = new AthleteModel { Id = SelectedAthlete.Id, FirstName = _firstName, LastName = _lastName, BirthDate = _birthDate, IsMale = _isMale, Phone = _phone, Email = _email, AddressId = SelectedAddress.Id, ParentId = SelectedParent.Id, SchoolId = SelectedSchool.Id, CoachId = SelectedCoach.Id }; SqlDataAccess sql = new SqlDataAccess(); sql.UpdateData <AthleteModel>("dbo.spAthlete_Update", e, "ADBData"); msg = $"Athlete ({SelectedAthlete.FullName}) was successfully updated."; MessageBox.Show(msg, "Athlete Updated"); Athletes = new BindingList <AthleteDisplayModel>(GetAllAthletes()); Clear(); isUpdating = false; _events.PublishOnUIThread(new AthleteChangedEvent()); } } }
private void GetRegularAthletes(ISheet sheet, List <AthleteModel> result) { for (var row = 13; row < 28; row++) { var athlete = new AthleteModel(); athlete.Name = ExcelHelper.GetStringValue(sheet, row, 1); athlete.Sex = ExcelHelper.GetStringValue(sheet, row, 2); athlete.BarGroupGamesStatus = ExcelHelper.GetStringValue(sheet, row, 3); athlete.BarIndividualGamesStatus = ExcelHelper.GetStringValue(sheet, row, 4); athlete.WayGroupGamesStatus = ExcelHelper.GetStringValue(sheet, row, 5); athlete.WayIndividualGamesStatus = ExcelHelper.GetStringValue(sheet, row, 6); athlete.IdCard = ExcelHelper.GetStringValue(sheet, row, 7); athlete.AccommodationRequirements = ExcelHelper.GetStringValue(sheet, row, 8); athlete.IsVegetarian = ExcelHelper.GetStringValue(sheet, row, 9); athlete.ClothingSize = ExcelHelper.GetStringValue(sheet, row, 10); athlete.Phone = ExcelHelper.GetStringValue(sheet, row, 11); if (!string.IsNullOrWhiteSpace(athlete.Name)) { result.Add(athlete); } } }
// 获取球道赛人员信息 public static List <AthleteModel> GetWayPersonInfo(string matchId) { var result = new List <AthleteModel>(); var sql = $"select name,sex,team_name,group_name,team_short_name from athletes where match_id = '{matchId}' and (way_GROUP_GAMES_STATUS ='参加' or way_INDIVIDUAL_GAMES_STATUS = '参加')"; var dataSet = SQLiteHelper.ExecuteDataSet(SQLiteHelper.LocalDbConnectionString, sql, CommandType.Text); var rows = dataSet.Tables[0].Rows; for (var i = 0; i < rows.Count; i++) { var row = rows[i]; var model = new AthleteModel(); model.Name = DBHelper.GetRowIndexStringValue(row, 0); model.Sex = DBHelper.GetRowIndexStringValue(row, 1); model.TeamName = DBHelper.GetRowIndexStringValue(row, 2); model.GroupName = DBHelper.GetRowIndexStringValue(row, 3); model.TeamShortName = DBHelper.GetRowIndexStringValue(row, 4); result.Add(model); } return(result); }
private async Task <AthleteModel> GetAthleteAsync(string token, LinkedAccount linkedAccount, CloudTable table, ILogger logger, CancellationToken cancellationToken) { try { var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://www.strava.com/api/v3/athlete")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); logger.LogInformation($"Received response from Strava: '{responseBody}'"); AthleteModel athleteModel = JsonConvert.DeserializeObject <AthleteModel>(responseBody); // Update linked account in the table storage if the user profile changed if (linkedAccount.StravaAccountId != athleteModel.Id || linkedAccount.FirstName != athleteModel.FirstName || linkedAccount.LastName != athleteModel.LastName) { logger.LogInformation($"Updating Strava account for user: '******' '{linkedAccount.IdpUserName}'. Strava user:'******' {linkedAccount.FirstName} {linkedAccount.LastName}"); linkedAccount.StravaAccountId = athleteModel.Id; linkedAccount.FirstName = athleteModel.FirstName; linkedAccount.LastName = athleteModel.LastName; TableOperation operation = TableOperation.Merge(linkedAccount); await table.ExecuteAsync(operation); } return(athleteModel); } catch (Exception ex) { logger.LogError(ex, "Error occurred while requesting athlete info from Strava"); return(null); } }
public async Task <AthleteModel> GetProfileAsync(CancellationToken cancellationToken) { string accessToken = await _authenticationService.GetAccessTokenAsync(); if (string.IsNullOrEmpty(accessToken)) { Console.WriteLine("Could not get access token, the operation is canceled."); _logger.LogWarning("Could not get access token, the operation is canceled."); return(null); } _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(new Uri("/api/v3/athlete", UriKind.Relative), cancellationToken); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(cancellationToken); AthleteModel athleteModel = JsonConvert.DeserializeObject <AthleteModel>(responseBody); return(athleteModel); }
private void btnOK_Click(object sender, EventArgs e) { var name = this.tbName.Text; var teamName = this.tbTeamName.Text; var teamShortName = this.tbTeamShortName.Text; var athlete = new AthleteModel(); athlete.Id = Guid.NewGuid().ToString(); athlete.GroupName = GroupName; athlete.MatchId = MatchId; athlete.Name = name; athlete.Sex = Sex; athlete.TeamName = teamName; athlete.TeamShortName = teamShortName; athlete.BarIndividualGamesStatus = this.cbBarIndividualStatus.Text.Trim(); athlete.BarGroupGamesStatus = this.cbBarGroupStatus.Text.Trim(); AthletesDAL.Insert(athlete); MessageBox.Show("添加成功"); this.DialogResult = DialogResult.OK; this.Close(); }
public IActionResult CreateAthlete(int?testId, int?athleteId) { AthleteModel model = new AthleteModel(); Test test = new Test(); AthleteTestMapping athleteTestMapping = new AthleteTestMapping(); string domainName = _configuration["DomainName"].ToSafeString(); if (!string.IsNullOrEmpty(domainName)) { if (testId.HasValue && athleteId.ToSafeInt() == 0) { model.TestId = testId.ToSafeInt(); model.userList = BALUser.GetUserListByRoleId((int)Enums.UserRole.Athlete, domainName); test = BALUser.GetTestTypeByTestId(testId.ToSafeInt(), domainName); model.TestName = test.TestName.ToSafeString() + " " + test.TestDate.ToString("yyyy/MM/dd"); model.IsEditMode = false; } else { model.TestId = testId.ToSafeInt(); model.userList = BALUser.GetUserListByRoleId((int)Enums.UserRole.Athlete, domainName); test = BALUser.GetTestTypeByTestId(testId.ToSafeInt(), domainName); model.TestName = test.TestName.ToSafeString() + " " + test.TestDate.ToString("yyyy/MM/dd"); athleteTestMapping = BALUser.GetAthlete(athleteId.ToSafeInt(), domainName); if (athleteTestMapping != null) { model.AthleteId = athleteTestMapping.AthleteId.ToSafeInt(); model.Distance = athleteTestMapping.Distance; model.IsEditMode = true; model.MapId = athleteTestMapping.MapId.ToSafeInt(); } } } return(PartialView("~/Views/Home/AddAthlete.cshtml", model)); }
public IActionResult DeleteTest(AthleteModel model) { int result = 0; string domainName = _configuration["DomainName"].ToSafeString(); if (!string.IsNullOrEmpty(domainName)) { result = BALUser.DeleteTest(model.TestId.ToSafeInt(), domainName); switch (result) { case 0: TempData["message"] = "Something went wrong."; TempData["IsSuccess"] = 0; break; case 1: TempData["message"] = "Record successfully deleted."; TempData["IsSuccess"] = 1; break; } } return(RedirectToAction("Index")); }
public async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "userinfo")] HttpRequest request, [Table("LinkedAccounts")] CloudTable table, ILogger logger, CancellationToken cancellationToken) { try { // The "user" returned here is an actual ClaimsPrincipal with the claims that were in the access_token. // The "token" is a SecurityToken that can be used to invoke services on the part of the user. E.g., create a Google Calendar event on the user's calendar. (ClaimsPrincipal user, SecurityToken token) = await _auth0Authenticator.AuthenticateAsync(request, logger, cancellationToken); string userId = _auth0Authenticator.GetUserId(user); logger.LogInformation($"User authenticated, user id='{userId}'"); UserInfoModel userInfo = new UserInfoModel(); LinkedAccount linkedAccount = await _linkedAccountService.GetLinkedAccountAsync(userId, table, logger); if (linkedAccount != null) { // validate that the access token has not expired and renew if needed string accessToken = await GetValidStravaAccessTokenAsync(linkedAccount, table, logger, cancellationToken); if (accessToken != null) { AthleteModel athlete = await GetAthleteAsync(accessToken, linkedAccount, table, logger, cancellationToken); if (athlete != null) { logger.LogInformation($"Got athlete info from Strava: '{athlete}'"); userInfo.FirstName = athlete.FirstName; userInfo.LastName = athlete.LastName; userInfo.Country = athlete.Country; userInfo.City = athlete.City; userInfo.PictureUrl = athlete.Profile; userInfo.IsStravaAccountLinked = true; } AthleteStatsModel stats = await GetAthleteStatsAsync(accessToken, linkedAccount, logger, cancellationToken); if (stats != null) { logger.LogInformation($"Got athlete stats from Strava: '{stats}'"); userInfo.Runs = stats.AllRunsTotals.Count; userInfo.Swims = stats.AllSwimsTotals.Count; userInfo.Rides = stats.AllRidesTotals.Count; } } } return(new OkObjectResult(userInfo)); } catch (AuthException) { return(new UnauthorizedResult()); } }
public IModel Create(IDataProvider provider, IModelFactoryContainer modelFactoryContainer) { var model = new AthleteModel(); return(model); }