public void AddOrRemoveFavorited(Favorited favorited) { var f = _context.Favorited.Where(x => x.id == favorited.id && x.UserId == favorited.UserId).FirstOrDefault(); if (f == null) { favorited.User = _context.Users.Where(x => x.UserId == favorited.UserId).FirstOrDefault(); _context.Favorited.Add(favorited); _context.SaveChanges(); } else { _context.Favorited.Remove(f); _context.SaveChanges(); } }
public IEnumerable <FavoritedView> Post(Favorited favorito) { Guid id = Guid.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.Jti).Value); favorito.UserId = id; _bookService.AddOrRemoveFavorited(favorito); List <Favorited> favoritos = _bookService.ListFavoritedBooks(id); return(favoritos.Select(x => new FavoritedView { id = x.id, title = x.title, thumbnail = x.thumbnail, authors = x.authors, eTag = x.eTag, kind = x.kind, }).ToList()); }
// ReSharper disable once UnusedMember.Local private void On(Favorited fav) => _users.Add(fav.UserId);