public IActionResult OnPostAddToCollection(string cardName, string lang, string setName, int amount, bool isSigned = false, bool isFoil = false) { MTGCard searchedCard = cardData.SearchForCard(cardName, lang, setName); if (searchedCard != null) { MTGUserCard c = new MTGUserCard(); c.CardId = searchedCard.Id; c.UserId = httpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); c.Amount = amount; c.Signed = isSigned; c.Foil = isFoil; if (cardData.AddToCollection(c)) { return(StatusCode(201, "Successfully added " + cardName + " to collection")); } else { return(StatusCode(500, "Internal Server error, try again later")); } } return(StatusCode(500, "Internal Server error, try again later")); }
public bool AddToCollection(MTGUserCard collectionItem) { MTGUserCard existingCard = _context.MTGUserCard.FirstOrDefault(uc => uc.UserId == collectionItem.UserId && uc.CardId == collectionItem.CardId); if (existingCard == null) { _context.MTGUserCard.Add(collectionItem); } else { existingCard.Amount += collectionItem.Amount; } return(_context.SaveChanges() == 1); }