public async Task <IActionResult> GetById([FromServices] DBMusicContext context, string id) { try { var _idGuid = new Guid(id); var author = _service.GetById(_idGuid); return(Ok(author)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> GetByName([FromServices] DBMusicContext context, string name) { try { var author = _service.GetByName(name); return(Ok(author)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Get([FromServices] DBMusicContext context) { try { var lista = _service.GetAuthor(); return(Ok(lista)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Post([FromServices] DBMusicContext context, [FromBody] MusicAuthor model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var musicauthor = _service.Post(model); return(Ok(musicauthor)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Put([FromServices] DBMusicContext context, [FromBody] MusicViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var music = _service.Put(model); return(Ok(music)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Delete([FromServices] DBMusicContext context, [FromBody] string id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var objeto = _service.Delete(id); if (objeto != null) { return(BadRequest(ModelState)); } return(Ok(objeto)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Delete([FromServices] DBMusicContext context, [FromBody] MusicAuthor musicauthor) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var objeto = _service.Delete(musicauthor.MusicId, musicauthor.AuthorId); if (objeto != null) { return(BadRequest("Não foi encontrado registro")); } return(Ok(objeto)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public AuthorController(DBMusicContext context, ServiceAuthor service) { _service = service; }
public ServiceMusicAuthor(DBMusicContext context, IMapper mapper) { _context = context; _mapper = mapper; }