public async Task <ActionResult> DeleteEventMusics( [FromServices] DataContext context, [FromServices] EventRepository eventRepository, [FromServices] MusicRepository musicRepository, int eventId, int musicId) { try { var eventExists = eventRepository.CheckExistsById(eventId); if (!eventExists) { return(NotFound(new { message = "O Evento não foi localizado." })); } var musicExists = musicRepository.CheckExistsById(musicId); if (!musicExists) { return(NotFound(new { message = "A música não foi localizada." })); } eventRepository.DeleteMusic(eventId, musicId); await context.SaveChangesAsync(); return(Ok()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = ErrorMessage.Internal })); } }
public async Task <ActionResult> PostEventMusics( [FromServices] DataContext context, [FromServices] EventRepository eventRepository, [FromServices] MusicRepository musicRepository, [FromBody] AddEventMusicCommand command, int eventId) { try { var eventExists = await eventRepository.GetByIdAsync(eventId); if (eventExists == null) { return(NotFound(new { message = "O Evento não foi localizado." })); } var musicExists = musicRepository.CheckExistsById(command.MusicId); if (!musicExists) { return(NotFound(new { message = "A música não foi localizada." })); } var musicAlreadyAdded = eventRepository.CheckMusicAlreadyAdded(eventId, command.MusicId); if (musicAlreadyAdded) { return(Ok()); } var eventMusic = new EventMusic { EventId = eventId, MusicId = command.MusicId }; eventRepository.AddEventMusic(eventMusic); await context.SaveChangesAsync(); // var list = await eventRepository.GetEventUsersAsync(eventId); return(Ok()); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = ErrorMessage.Internal })); } }