public async Task <IActionResult> Edit(string id) { try { if (id.Equals(Guid.Empty)) { throw new ApplicationException($"No se pudo encontrar el usuario con el id {id}."); } ApplicationUser user = await _context.Users.FindAsync(id); AthleteViewModel model = new AthleteViewModel() { Id = user.Id, Fields = new AthleteFieldsViewModel() { Email = user.Email, PhoneNumber = user.PhoneNumber, UserName = user.UserName, PaternalSurname = user.PaternalSurname, MaternalSurname = user.MaternalSurname, Name = user.Name } }; return(View(model)); } catch (Exception e) { throw e; } }
public IHttpActionResult GetAthlete(int id) { List <AthleteViewModel> la = new List <AthleteViewModel>(); AthleteViewModel atl = new AthleteViewModel(); // var x = db.Athléte.ToList(); var x = db.Entitésportif.FirstOrDefault(p => p.ID == id); foreach (var l in x.Entitéathléte) { Athléte a = new Athléte(); a = db.Athléte.FirstOrDefault(y => y.ID == l.AthléteID); AthleteViewModel avm = new AthleteViewModel(); avm.ID = a.ID; avm.Nom = a.Nom; avm.Prenom = a.Prenom; avm.image = a.image; la.Add(avm); } return(Ok(la)); }
public AthleteViewModel UpdateTestResultForAnAthlete(int athleteId, string testresult, int shuttlenumber, int shuttlespeedlevel) { foreach (var athlete in _athletes) { if (athlete.Id.Equals(athleteId)) { var indexofcurrentshuttle = _shuttles.IndexOf(_shuttles.FirstOrDefault(x => x.ShuttleNo == shuttlenumber && x.SpeedLevel == shuttlespeedlevel)); athlete.ShuttleState = testresult; if (indexofcurrentshuttle >= 0) { athlete.CurrentShuttle = _shuttles[indexofcurrentshuttle]; } } } AthleteViewModel athleteViewModel = new AthleteViewModel() { Athletes = _athletes, }; return(athleteViewModel); }
public async Task <IActionResult> Add(AthleteViewModel model) { try { if (!ModelState.IsValid) { return(BadRequest(model)); } if (_context.Users.Any(x => x.UserName.Equals(model.Fields.UserName))) { return(BadRequest("El usuario especificado ya se encuentra registrado.")); } if (_context.Users.Any(x => x.Email.Equals(model.Fields.Email))) { return(BadRequest("El correo electrónico especificado ya se encuentra registrado.")); } var passwordValidator = new PasswordValidator <ApplicationUser>(); var passwordIsValid = passwordValidator.ValidateAsync(_userManager, new ApplicationUser(), model.Fields.Password).Result.Succeeded; if (!passwordIsValid) { return(BadRequest("La contraseña debe contener al menos 1 letra mayúscula, 1 letra minúscula, 1 dígito y un caracter no alfanumérico.")); } var user = new ApplicationUser(); FillApplicationUser(ref user, model.Fields); var identityResult = await _userManager.CreateAsync(user, model.Fields.Password); if (!identityResult.Succeeded) { return(BadRequest("Ocurrió un problema al registrar.")); } var identityRoleResult = await _userManager.AddToRoleAsync(user, ConstantHelpers.ROLES.ATHLETE); //var identityResultRole = await _userManager.AddToRoleAsync(user, new IdentityRole(ConstantHelpers.ROLES.ATHLETE)); if (!identityRoleResult.Succeeded) { return(BadRequest("Ocurrió un problema al registrar.")); } await _context.Users.AddAsync(user); return(Ok()); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Edit(AthleteViewModel model, Guid id) { if (!ModelState.IsValid) { return(BadRequest(model)); } var validateUserName = await _context.Users.FirstOrDefaultAsync(x => x.UserName.Equals(model.Fields.UserName) && !x.Id.Equals(model.Id)); if (validateUserName != null) { return(BadRequest("El usuario especificado ya se encuentra registrado.")); } var validateEmail = await _context.Users.FirstOrDefaultAsync(x => x.Email.Equals(model.Fields.Email) && !x.Id.Equals(model.Id)); if (validateEmail != null) { return(BadRequest("El correo electrónico especificado ya se encuentra registrado.")); } var passwordValidator = new PasswordValidator <ApplicationUser>(); var passwordIsValid = passwordValidator.ValidateAsync(_userManager, new ApplicationUser(), model.Fields.Password).Result.Succeeded; if (!passwordIsValid) { return(BadRequest("La contraseña debe contener al menos 1 letra mayúscula, 1 letra minúscula, 1 dígito y un caracter no alfanumérico.")); } if (!ModelState.IsValid) { return(BadRequest(model)); } var user = await _context.Users.FindAsync(model.Id); FillApplicationUser(ref user, model.Fields); var identityResult = await _userManager.UpdateAsync(user); if (!identityResult.Succeeded) { return(BadRequest("Ocurrió un problema al registrar.")); } user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, model.Fields.Password); _context.SaveChanges(); // student.UserId = user.Id; // student.CareerId = model.Fields.SelectedCareer; return(Ok()); }
public IHttpActionResult PutAthlete(int id, AthleteViewModel athlete) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != athlete.Id) { return(BadRequest()); } //db.Entry(athlete).State = EntityState.Modified; using (var ctx = new Tuks_Athletics_SystemEntities()) { var existingAthlete = ctx.Athletes.Where(s => s.Athlete_ID == athlete.Id).FirstOrDefault <Athlete>(); if (existingAthlete != null) { existingAthlete.Name = athlete.Name; existingAthlete.Surname = athlete.Surname; existingAthlete.Description = athlete.Description; existingAthlete.Club_ID = athlete.ClubId; existingAthlete.Gender_ID = athlete.GenderId; existingAthlete.Status_ID = athlete.StatusId; existingAthlete.User_ID = athlete.UserId; } try { ctx.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AthleteExists(id)) { return(NotFound()); } else { throw; } } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> AddAthleteAsync([FromForm] AthleteViewModel athlete) { UserTestMapper UserTest = new UserTestMapper(); var UserExist = (from user in _context.UserTestMappers.Where(t => t.TestID == TestID) select user.User.Name).ToList(); var Tests = await _context.Tests.FirstOrDefaultAsync(t => t.ID == TestID); var Users = _context.Users.Where(u => u.Name == athlete.Name); if (!UserExist.Contains(athlete.Name)) { UserTest.TestID = Tests.ID; foreach (User user in Users) { UserTest.UserID = user.ID; } if (athlete.Distance != 0) { UserTest.CooperTestDistance = athlete.Distance; UserTest.FitnessRating = CalculateFitness(athlete.Distance); } else { UserTest.SprintTestTime = athlete.Time; } _context.UserTestMappers.Add(UserTest); } else { var UpdateUser = _context.UserTestMappers.Where(u => u.User.Name == athlete.Name).Where(u => u.TestID == TestID).FirstOrDefault(); if (athlete.Distance != 0) { UpdateUser.CooperTestDistance = athlete.Distance; UpdateUser.FitnessRating = CalculateFitness(athlete.Distance); } else { UpdateUser.SprintTestTime = athlete.Time; } _context.UserTestMappers.Update(UpdateUser); } await _context.SaveChangesAsync(); return(RedirectToAction("TestDetails", new { id = TestID })); }
public ActionResult Athlete(int?id) { if (id == null) { return(View("~/Views/Error/PageNotFound.cshtml")); } var found = db.Athletes.Find(id); if (found == null) { return(View("~/Views/Error/PageNotFound.cshtml")); } var ViewModel = new AthleteViewModel(found); return(View(ViewModel)); }
public new ActionResult Create(AthleteViewModel athleteViewModel) { Athletes athlete = new Athletes(); if (ModelState.IsValid) { List <Sports> allSports = UnitOfWork.UOW.SportRepository.GetAll(); Sports currentSport = allSports.Where(x => x.ID == athleteViewModel.Sport).FirstOrDefault(); athlete.ID = athleteViewModel.ID; athlete.Name = athleteViewModel.Name; athlete.Sport = currentSport; return(base.Create(athlete)); } else { List <Sports> allSports = UnitOfWork.UOW.SportRepository.GetAll(); SelectList selectListItems = new SelectList(allSports, "ID", "Name"); ViewData["SportsList"] = selectListItems; return(View(athlete)); } }
public AthleteViewModel GetUpdatedAtheleViewModel(int athleteId, string testresult, int shuttlenumber, int shuttlespeedlevel) { foreach (var athlete in _athletes) { if (athlete.Id.Equals(athleteId)) { athlete.ShuttleState = testresult; if (athlete.ShuttleState.Equals("stop")) { var indexofcurrentshuttle = _shuttles.IndexOf(_shuttles.FirstOrDefault(x => x.ShuttleNo == shuttlenumber && x.SpeedLevel == shuttlespeedlevel)); athlete.FinishedShuttles.AddRange(_shuttles.Where(x => x.ShuttleNo == shuttlenumber && x.SpeedLevel <= shuttlespeedlevel).ToList()); athlete.FinishedShuttles.AddRange(_shuttles.Where(x => x.ShuttleNo < shuttlenumber).ToList()); if (athlete.CurrentShuttle == null) { if (indexofcurrentshuttle >= 1) { athlete.CurrentShuttle = _shuttles[indexofcurrentshuttle - 1]; } else { athlete.CurrentShuttle = new Shuttle(); } } } } } AthleteViewModel athleteViewModel = new AthleteViewModel() { Athletes = _athletes, }; return(athleteViewModel); }
private async Task <AthleteViewModel> BuildAthleteViewModel(StravaTokenSet tokenSet, string slackUserId, int athleteIdentifier, string name) { var activities = await GetRecentActivities(tokenSet, athleteIdentifier); var latestActivity = activities.FirstOrDefault(); var athlete = new AthleteViewModel { Id = athleteIdentifier, Name = name, AccessToken = tokenSet.AccessToken, RefreshToken = tokenSet.RefreshToken, ExpiresAt = tokenSet.ExpiresAt, SlackUserId = slackUserId, SignupDateTimeUtc = DateTime.UtcNow, ReminderCount = 0, LastReminderDateTimeUtc = DateTime.UtcNow, LatestActivityId = latestActivity?.Id, Activities = activities }; return(athlete); }
private async Task <AthleteViewModel> GetAthleteProfile(Authenticator authenticator) { var client = new Client(authenticator); var profile = await client.Athletes.GetCurrent(); var result = new AthleteViewModel() { IsAuthenticated = authenticator.IsAuthenticated, Firstname = profile.FirstName, Lastname = profile.LastName, City = profile.City, Profile = profile.Profile, ProfileMedium = profile.ProfileMedium, Weight = profile.Weight, MeasurementPreference = profile.MeasurementPreference, Follower = profile.FollowerCount, FriendCount = profile.FriendCount, AthleteType = profile.AthleteType.ToString(), FullName = profile.FirstName + " " + profile.LastName }; return(result); }
// GET: Athletes/Details/5 public ActionResult Details(int?id) { if (User.Identity.IsAuthenticated) { // only if you need to ask manually. Normally use [Authorize] attribute on the class or method. TempData["LoggedIn"] = "THIS IS AN ELEVATED PRIVILAGE TEST – You are logged in as: " + User.Identity.Name; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Athlete athlete = db.Athletes.Find(id); if (athlete == null) { return(HttpNotFound()); } AthleteViewModel viewModel = new AthleteViewModel(athlete); return(View(viewModel)); } TempData["!LoggedIn"] = "THIS IS AN ELEVATED PRIVILAGE TEST – Please log into an existing account to access the Athlete Details page"; return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Create([Bind(Include = "FirstName,LastName,EmailAddress,BirthDate,Gender,SubscriptionLength,SubscriptionId")] AthleteViewModel model) { Athlete athlete = new Athlete { FirstName = model.FirstName, LastName = model.LastName, EmailAddress = model.EmailAddress, Gender = model.Gender, BirthDate = model.BirthDate, Subscription = _db.Subscriptions.Single(x => x.Id.Equals(model.SubscriptionId)), SubscriptionLength = model.SubscriptionLength, }; athlete.Reminders = new ClassReminders { Athlete = athlete, AthleteId = athlete.Id, Reminders = new List <Class>() }; if (athlete.EmailAddress == "*****@*****.**") { List <Class> pastClasses = _db.Classes.Where(c => c.Time <= DateTime.Now).ToList(); athlete.Classes = pastClasses; } if (ModelState.IsValid) { _db.Athletes.Add(athlete); await _db.SaveChangesAsync(); await BeginAthleteSetup(athlete); return(RedirectToAction("Index")); } return(View(athlete)); }
public IActionResult Add() { AthleteViewModel athleteViewModel = new AthleteViewModel(); return(View(athleteViewModel)); }
protected override void OnAppearing() { base.OnAppearing(); BindingContext = new AthleteViewModel(Navigation); }
public ActionResult AthleteDetails(int athleteId) { var athlete = new AthleteViewModel(Umbraco.Content(athleteId)); return(View("~/Views/BusinessPages/Athletes/Athlete.cshtml", athlete)); }