Esempio n. 1
0
        public async Task <ActionResult <Music> > Put(
            [FromServices] DataContext context,
            [FromServices] MusicRepository repository,
            [FromBody] UpdateMusicCommand command,
            int id)
        {
            try
            {
                var music = await repository.GetByIdAsync(id);

                if (music == null)
                {
                    return(NotFound(new { message = "A música não foi localizada." }));
                }

                music.Singer   = command.Singer;
                music.Title    = command.Title;
                music.Reminder = command.Reminder;
                music.Lirycs   = command.Lirycs;
                music.Notation = command.Notation;
                music.Video    = command.Video;
                music.Play     = command.Play;

                music.LastModifiedDate = DateTime.Now;

                repository.Update(music);
                await context.SaveChangesAsync();

                return(Ok(new { music }));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  new { message = ErrorMessage.Internal }));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateMusic([FromBody] UpdateMusicCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(result));
        }