Beispiel #1
0
        public IHttpActionResult CreateLyric(LyricDto lyricDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var lyric = Mapper.Map <LyricDto, Lyric>(lyricDto);

            _context.Lyrics.Add(lyric);
            _context.SaveChanges();

            lyricDto.Id = lyric.Id;
            return(Created(new Uri(Request.RequestUri + "/" + lyric.Id), lyricDto));
        }
Beispiel #2
0
        public IHttpActionResult UpdateLyric(int id, LyricDto lyricDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var lyricInDb = _context.Lyrics.SingleOrDefault(c => c.Id == id);

            if (lyricInDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(lyricDto, lyricInDb);

            _context.SaveChanges();

            return(Ok());
        }