public async Task <IActionResult> PutFavouritePublisher(int id, FavouritePublisher favouritePublisher) { if (id != favouritePublisher.Id) { return(BadRequest()); } _context.Entry(favouritePublisher).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FavouritePublisherExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <FavouritePublisher> > PostFavouritePublisher(FavouritePublisher favouritePublisher) { User user = _context.Users.Where(u => u.Id == favouritePublisher.UserId).Include(p => p.FavPublishers).FirstOrDefault(); _context.Attach(user); _context.FavouritePublisher.Add(favouritePublisher); _context.Users.Update(user).Entity.FavPublishers.Add(favouritePublisher); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFavouritePublisher", new { id = favouritePublisher.Id }, favouritePublisher)); }