public async Task <IActionResult> PutUserAnimeManga(int id, UserAnimeManga userAnimeManga) { if (id != userAnimeManga.UserId) { return(BadRequest()); } _context.Entry(userAnimeManga).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserAnimeMangaExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult <Helper> PostAnimeMangaExists(Helper helper) { //If the anime/manga does not exist, we should add it and link it to the useranimemangatable //else we should just make a link in the intermediate table var myAnimeManga = new AnimeManga(); var user = new User(); try { myAnimeManga = _context.AnimeMangas.FromSqlInterpolated($"SELECT * FROM AnimeMangas WHERE MalCode = {helper.AnimeManga.MalCode}").First(); } catch (System.Exception e) { Console.Write(e); return(NotFound()); // _context.AnimeMangas.Add(helper.AnimeManga); // await _context.SaveChangesAsync(); // myAnimeManga = _context.AnimeMangas.FromSqlInterpolated($"SELECT * FROM AnimeMangas WHERE MalCode = {helper.AnimeManga.MalCode}").First(); } try { user = _context.Users.FromSqlInterpolated($"SELECT * FROM Users WHERE Email = {helper.Email}").First(); } catch (System.Exception e) { Console.Write(e); return(NotFound()); } UserAnimeManga userAnimeManga = new UserAnimeManga(); try { userAnimeManga = _context.UserAnimeMangas.FromSqlInterpolated($"SELECT * FROM UserAnimeMangas WHERE UserId = {user.UserId} AND AnimeMangaId = {myAnimeManga.AnimeMangaId}").First(); } catch (System.Exception e) { Console.Write(e); return(NotFound()); } return(Ok(userAnimeManga)); }
public async Task <ActionResult <UserAnimeManga> > DeleteUserAnimeManga(Helper helper) { var myAnimeManga = new AnimeManga(); var user = new User(); try { myAnimeManga = _context.AnimeMangas.FromSqlInterpolated($"SELECT * FROM AnimeMangas WHERE MalCode = {helper.AnimeManga.MalCode}").First(); } catch (System.Exception e) { Console.Write(e); return(NotFound()); } try { user = _context.Users.FromSqlInterpolated($"SELECT * FROM Users WHERE Email = {helper.Email}").First(); } catch (System.Exception e) { Console.Write(e); return(NotFound()); } UserAnimeManga userAnimeManga = new UserAnimeManga(); try { userAnimeManga = _context.UserAnimeMangas.FromSqlInterpolated($"SELECT * FROM UserAnimeMangas WHERE UserId = {user.UserId} AND AnimeMangaId = {myAnimeManga.AnimeMangaId}").First(); _context.UserAnimeMangas.Remove(userAnimeManga); //_context.UserAnimeMangas.FromSqlInterpolated($"DELETE FROM UserAnimeMangas WHERE AnimeMangaId = (SELECT AnimeMangaId FROM AnimeMangas WHERE AnimeMangaId = {myAnimeManga.AnimeMangaId}) AND UserId = (SELECT UserId FROM Users WHERE UserId = {user.UserId})"); await _context.SaveChangesAsync(); } catch (System.Exception e) { Console.Write(e); return(NotFound()); } return(Ok(userAnimeManga)); }