public async Task <bool> AddCardToCollectionAsync(string collectionName, Guid cardId, Guid userId) { FieldsAreFilled(userId, collectionName); if (cardId == Guid.Empty) { throw new AppException(nameof(userId) + " is required"); } var desiredCollection = await repository.FindByNameAsync(collectionName, userId); if (desiredCollection.CardItems.Contains(cardId)) { throw new AppException("Collection doesn't contain this card"); } desiredCollection.CardItems.Add(cardId); try { await repository.UpdateAsync(desiredCollection); } catch { return(false); } return(true); }
public async Task <bool> AddCardToCollectionAsync(Guid collectionId, Guid cardId, Guid userId) { if (collectionId == Guid.Empty) { throw new AppException($"Поле {nameof(collectionId)} не указано"); } if (cardId == Guid.Empty) { throw new AppException($"Поле {nameof(cardId)} не указано"); } if (userId == Guid.Empty) { throw new AppException($"Поле {nameof(userId)} не указано"); } var desiredCollection = await repository.FindByIdAsync(collectionId, userId); if (desiredCollection.CardItems.Contains(cardId)) { throw new AppException("В коллекции нет даной карты"); } desiredCollection.CardItems.Add(cardId); try { await repository.UpdateAsync(desiredCollection); } catch { return(false); } return(true); }