public async Task <IActionResult> UpdateMusic(int id, MusicDTO musicDTO) { if (id != musicDTO.Id) { return(BadRequest()); } var music = await _context.Music.FindAsync(id); if (music == null) { return(NotFound()); } music.Title = musicDTO.Title; music.ReleaseDate = musicDTO.ReleaseDate; music.Genre = musicDTO.Genre; music.Rating = musicDTO.Rating; music.Price = musicDTO.Price; music.isValid = musicDTO.isValid; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!MusicExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> PutMusic(int id, Music music) { if (id != music.Id) { return(BadRequest()); } _context.Entry(music).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMusic(int id, Music music) { if (id != music.Id) { return(BadRequest("L'ID doit être fourni")); } if (!String.IsNullOrEmpty(music.Validation)) { return(BadRequest("Que cherchez vous ?")); } _context.Entry(music).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateTodoItem(long id, TodoItemDTO todoItemDTO) { if (id != todoItemDTO.Id) { return(BadRequest()); } var todoItem = await _context.Music.FindAsync(id); if (todoItem == null) { return(NotFound()); } todoItem.Id = todoItemDTO.Id; todoItem.Title = todoItemDTO.Title; todoItem.ReleaseDate = todoItemDTO.ReleaseDate; todoItem.Genre = todoItemDTO.Genre; todoItem.Price = todoItemDTO.Price; todoItem.Rating = todoItemDTO.Rating; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!TodoItemExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> PutMusic(int id, MusicDTO musicDTO) { /* if (id != MusicDTO.Id) * { * return BadRequest(); * } * * _context.Entry(music).State = EntityState.Modified; * * try * { * await _context.SaveChangesAsync(); * } * catch (DbUpdateConcurrencyException) * { * if (!MusicExists(id)) * { * return NotFound(); * } * else * { * throw; * } * } * * return NoContent();*/ if (id != musicDTO.Id) { return(BadRequest()); } var todoItem = await _context.Music.FindAsync(id); if (todoItem == null) { return(NotFound()); } todoItem.Title = musicDTO.Title; todoItem.Artist = musicDTO.Artist; todoItem.ReleaseDate = musicDTO.ReleaseDate; todoItem.Genre = musicDTO.Genre; todoItem.Price = musicDTO.Price; todoItem.Rating = musicDTO.Rating; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!MusicExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Author,AlbumName,ReleaseDate,Genre,Price")] Album album) { if (ModelState.IsValid) { _context.Add(album); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(album)); }
public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price,Creator,IsValidated")] Music music) { if (ModelState.IsValid) { _context.Add(music); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(music)); }
public async Task <IActionResult> Create(Music music) { music.Token = music.Title.ToLower().Replace('\'', '_').Replace(' ', '_') + "-1"; // music.isValid = music.isValid.Equals("true"); if (ModelState.IsValid) { _context.Add(music); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(music)); }
public async Task <IActionResult> PutMusic(int id, MusicDTO musicDTO) { if (id != musicDTO.Id) { return(BadRequest()); } var music = await _context.Music.FindAsync(id); if (music == null) { return(NotFound()); } music.Title = musicDTO.Title; music.Artist = musicDTO.Artist; music.ReleaseDate = musicDTO.ReleaseDate; music.Genre = musicDTO.Genre; music.Price = musicDTO.Price; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }