|
|
|
@ -50,25 +50,13 @@ public class ExercicesController : ControllerBase
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
public async Task<IActionResult> Update(string id, [FromBody] UpdateSessionDto dto)
|
|
|
|
|
public async Task<IActionResult> Update(string id, [FromBody] UpdateExerciceInstanceDto dto)
|
|
|
|
|
{
|
|
|
|
|
var session = await _context.Sessions
|
|
|
|
|
.Include(s => s.Exercices)
|
|
|
|
|
.FirstOrDefaultAsync(s => s.Id == id);
|
|
|
|
|
if (session == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
_mapper.Map(dto, session);
|
|
|
|
|
|
|
|
|
|
// Supprime tous les anciens exercices
|
|
|
|
|
_context.ExerciceInstances.RemoveRange(session.Exercices);
|
|
|
|
|
|
|
|
|
|
// Ajoute les nouveaux exercices
|
|
|
|
|
foreach (var exoDto in dto.Exercices)
|
|
|
|
|
{
|
|
|
|
|
var exo = _mapper.Map<ExerciceInstance>(exoDto);
|
|
|
|
|
exo.SessionId = session.Id;
|
|
|
|
|
_context.ExerciceInstances.Add(exo);
|
|
|
|
|
}
|
|
|
|
|
var entity = await _context.ExerciceInstances
|
|
|
|
|
.Include(e => e.ExerciceTemplate)
|
|
|
|
|
.FirstOrDefaultAsync(e => e.Id == id);
|
|
|
|
|
if (entity == null) return NotFound();
|
|
|
|
|
_mapper.Map(dto, entity);
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return NoContent();
|
|
|
|
@ -80,6 +68,7 @@ public class ExercicesController : ControllerBase
|
|
|
|
|
var entity = await _context.ExerciceInstances.FindAsync(id);
|
|
|
|
|
if (entity == null) return NotFound();
|
|
|
|
|
_context.ExerciceInstances.Remove(entity);
|
|
|
|
|
_context.ExerciceInstances.Remove(entity);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|