public async Task <IActionResult> PutPerson(long id, Person person) { if (id != person.Id) { return(BadRequest()); } var authResult = await _authorisationService.AuthorizeAsync(User, person, "SamePerson"); if (!authResult.Succeeded) { return(new ForbidResult()); } _context.Entry(person).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSet(long id, Set @set) { if (id != @set.Id) { return(BadRequest()); } var workout = await _context.Workouts.FindAsync(@set.WorkoutId); if (workout == null) { return(BadRequest()); } var person = await _context.People.FindAsync(workout.PersonId); var exercise = await _context.Exercises.FindAsync(@set.ExerciseId); if (exercise == null) { return(BadRequest()); } var person2 = await _context.People.FindAsync(exercise.PersonId); var authResult = await _authorisationService.AuthorizeAsync(User, person, "SamePerson"); var authResult2 = await _authorisationService.AuthorizeAsync(User, person2, "SamePerson"); if ((!authResult.Succeeded) || (!authResult2.Succeeded)) { return(new ForbidResult()); } _context.Entry(@set).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SetExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }