예제 #1
0
 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));
     }
 }
예제 #2
0
        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));
            }
        }
예제 #3
0
        public async Task <IActionResult> Get([FromServices] DBMusicContext context)
        {
            try
            {
                var lista = _service.GetAuthor();

                return(Ok(lista));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #4
0
 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));
     }
 }
예제 #5
0
        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));
            }
        }
예제 #6
0
        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));
            }
        }
예제 #7
0
        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));
            }
        }
예제 #8
0
 public AuthorController(DBMusicContext context, ServiceAuthor service)
 {
     _service = service;
 }
예제 #9
0
 public ServiceMusicAuthor(DBMusicContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }