public async Task <IActionResult> Edit(string id, [Bind("ID,Name")] Athlete athlete) { if (id != athlete.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(athlete); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AthleteExists(athlete.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(athlete)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ExerciseTypeId,Question,Media,TrueAnswer")] Exercise exercise) { if (id != exercise.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(exercise); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExerciseExists(exercise.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ExerciseTypeId"] = new SelectList(_context.ExerciseTypes, "Id", "Id", exercise.ExerciseTypeId); return(View(exercise)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,UserName,Password")] User user) { if (id != user.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Icon,NameTopic,IsActive")] Topic topic) { if (id != topic.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(topic); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopicExists(topic.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(topic)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,NameExerciseType")] ExerciseType exerciseType) { if (id != exerciseType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(exerciseType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExerciseTypeExists(exerciseType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(exerciseType)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TopicId,NameLesson,RequireExp")] Lesson lesson) { if (id != lesson.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(lesson); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LessonExists(lesson.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["TopicId"] = new SelectList(_context.Topics, "Id", "Id", lesson.TopicId); return(View(lesson)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,LessonId")] UserLesson userLesson) { if (id != userLesson.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(userLesson); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserLessonExists(userLesson.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["LessonId"] = new SelectList(_context.Lessons, "Id", "Id", userLesson.LessonId); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Password", userLesson.UserId); return(View(userLesson)); }
public async Task <ActionResult <User> > Patch([FromBody] InfoUser infos) { try { var uuid = Guid.Parse(User.Identity.Name); User userFromTokenId = await _context.Users.FirstOrDefaultAsync(u => u.Id == uuid); if (userFromTokenId == null) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState.ToBadRequest())); } var(name, email) = infos; var userWithSameEmail = await _context.Users.FirstOrDefaultAsync(u => u.Email == email); if (userWithSameEmail != null && userWithSameEmail.Email != userFromTokenId.Email) { return(BadRequest("Email is already in use".ToBadRequest())); } userFromTokenId.Name = name; userFromTokenId.Email = email; _context.Update(userFromTokenId); await _context.SaveChangesAsync(); _log.Information("User {Email} has changed his/her information on {date} ", userFromTokenId.Email, DateTime.Now); return(Ok(Format.ToMessage("Success", 200))); } catch (Exception e) { _log.Fatal(e.Message + "on Patch User on {Date}", DateTime.Now); return(StatusCode(500)); } }
public async Task <ActionResult <string> > Put(Guid id, [FromBody] User user) { try { if (user == null) { return(BadRequest("user object is null".ToBadRequest())); } var uuid = Guid.Parse(User.Identity.Name); var uuidFromQuery = id; User userFromDb = await _context.Users.FirstOrDefaultAsync(u => u.Id == uuidFromQuery); User userFromTokenId = await _context.Users.FirstOrDefaultAsync(u => u.Id == uuid); if ((userFromTokenId == null) || (userFromDb?.Id != userFromTokenId?.Id)) { return(Unauthorized()); } User userWithSameLogin = await _context.Users.FirstOrDefaultAsync(u => u.Email == user.Email); if (userWithSameLogin != null) { return(BadRequest("Login already taken".ToBadRequest())); } if (!ModelState.IsValid) { return(BadRequest(ModelState.ToBadRequest())); } var(name, email, password, passwordConfirmation) = user; userFromDb.Name = name; userFromDb.Email = email; userFromDb.Password = password; userFromDb.PasswordConfirmation = passwordConfirmation; userFromDb.SetPasswordhHash(); _context.Update(userFromDb); await _context.SaveChangesAsync(); return(StatusCode(201)); } catch (Exception e) { return(StatusCode(500)); } }