public async Task AddCardToCardListAsync(CardList cardList, Card card) { var foundCardList = await FindAndCheckNullabilityHelper <CardList> .InDatabaseAsync(context.CardLists, cardList, "Card list not found!", false); var foundCard = await FindAndCheckNullabilityHelper <Card> .InCollectionAsync(foundCardList.Cards, card, "Card is already in this card list!", true); foundCardList.Cards.Add(card); }
public async Task RemoveCardFromCardListAsync(CardList cardList, Card card) { var foundCardList = await FindAndCheckNullabilityHelper <CardList> .InDatabaseAsync(context.CardLists, cardList, "Card list not found!", false); var foundCard = await FindAndCheckNullabilityHelper <Card> .InCollectionAsync(foundCardList.Cards, card, "Card not found!", false); foundCardList.Cards.Remove(foundCard); }
public async Task RemoveEntityAsync(T entity) { try { var found = await FindAndCheckNullabilityHelper <T> .InDatabaseAsync(set, entity, $"Entity of type {entity.GetType()} was not found", false); set.Remove(found); } catch (Exception ex) { throw ex; } }
public async Task AddEntityAsync(T entity) { try { var found = await FindAndCheckNullabilityHelper <T> .InDatabaseAsync(set, entity, $"Entity of type {entity.GetType()} is already in DB", true); set.Add(entity); } catch (Exception ex) { throw ex; } }
public async Task RenameCardListAsync(CardList cardList, string newName) { var foundCardList = await FindAndCheckNullabilityHelper <CardList> .InDatabaseAsync(context.CardLists, cardList, "Card list not found!", false); if (foundCardList.Name.Equals(newName)) { throw new Exception("Names are equal!"); } else { context.Entry <CardList>(foundCardList).State = EntityState.Detached; foundCardList.Name = newName; context.Entry <CardList>(foundCardList).State = EntityState.Modified; } }
public async Task RemoveCardListFromBoardAsync(Board board, CardList cardList) { try { var foundBoard = await FindAndCheckNullabilityHelper <Board> .InDatabaseAsync(context.Boards, board, "Board was not found!", false); var foundCardList = await FindAndCheckNullabilityHelper <CardList> .InCollectionAsync(foundBoard.CardLists, cardList, "Card list not found!", false); foundBoard.CardLists.Remove(foundCardList); } catch (Exception ex) { throw ex; } }
public async Task RemoveCommentFromCardAsync(Card card, Comment comment) { try { var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false); var foundComment = await FindAndCheckNullabilityHelper <Comment> .InCollectionAsync(foundCard.Comments, comment, "Comment was not found!", false); foundCard.Comments.Remove(foundComment); } catch (Exception ex) { throw ex; } }
public async Task RemoveLabelColorFromCardAsync(Card card, LabelColor labelColor) { try { var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false); var foundLabeColor = await FindAndCheckNullabilityHelper <LabelColor> .InCollectionAsync(foundCard.LabelColors, labelColor, "Label color was not found!", false); foundCard.LabelColors.Remove(foundLabeColor); } catch (Exception ex) { throw ex; } }
public async Task RemoveUserFromCardAsync(Card card, User user) { try { var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false); var foundUser = await FindAndCheckNullabilityHelper <User> .InCollectionAsync(foundCard.Users, user, "User was not found!", false); foundCard.Users.Remove(foundUser); } catch (Exception ex) { throw ex; } }
public async Task AddUserToCardAsync(Card card, User user) { try { var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false); var foundUser = await FindAndCheckNullabilityHelper <User> .InCollectionAsync(foundCard.Users, user, "User is already assigned to this card!", true); foundCard.Users.Add(user); } catch (Exception ex) { throw ex; } }
public async Task AddLabelColorToCardAsync(Card card, LabelColor labelColor) { try { var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false); var foundLabeColor = await FindAndCheckNullabilityHelper <LabelColor> .InCollectionAsync(foundCard.LabelColors, labelColor, "Such label color is already assigned to this card!", true); labelColor.Cards.Add(foundCard); context.Set <LabelColor>().Add(labelColor); } catch (Exception ex) { throw ex; } }
public async Task AddCardListToBoardAsync(Board board, CardList cardList) { try { var foundBoard = await FindAndCheckNullabilityHelper <Board> .InDatabaseAsync(context.Boards, board, "Board was not found!", false); var foundCardList = await FindAndCheckNullabilityHelper <CardList> .InCollectionAsync(foundBoard.CardLists, cardList, "Card list is already in this board!", true); cardList.Board = foundBoard; context.Set <CardList>().Add(cardList); //foundBoard.CardLists.Add(cardList); } catch (Exception ex) { throw ex; } }
public async Task RemoveUserFromBoardAsync(Board board, User user) { try { var foundBoard = await FindAndCheckNullabilityHelper <Board> .InDatabaseAsync(context.Boards, board, "Board was not found!", false); var foundUser = await FindAndCheckNullabilityHelper <User> .InDatabaseAsync(context.Users, user, "User does not exist in database!", false); foundUser = await FindAndCheckNullabilityHelper <User> .InCollectionAsync(foundBoard.Users, user, "User is not assigned to this board!", false); foundBoard.Users.Remove(foundUser); } catch (Exception ex) { throw ex; } }
public async Task AddCommentToCardAsync(Card card, Comment comment) { try { var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false); var foundComment = await FindAndCheckNullabilityHelper <Comment> .InCollectionAsync(foundCard.Comments, comment, "Comment is already assigned to a card!", true); comment.Card = foundCard; context.Set <Comment>().Add(comment); //foundCard.Comments.Add(comment); } catch (Exception ex) { throw ex; } }
public async Task RenameBoardAsync(Board board, string newName) { try { var foundBoard = await FindAndCheckNullabilityHelper <Board> .InDatabaseAsync(context.Boards, board, "Board was not found!", false); if (foundBoard.Name.Equals(newName)) { throw new Exception("Names are equal!"); } else { context.Entry <Board>(foundBoard).State = EntityState.Detached; foundBoard.Name = newName; context.Entry <Board>(foundBoard).State = EntityState.Modified; } } catch (Exception ex) { throw ex; } }
public async Task ChangeNameOfACardAsync(Card card, string newName) { try { var foundCard = await FindAndCheckNullabilityHelper <Card> .InDatabaseAsync(context.Cards, card, "Card not found!", false); if (foundCard.CardName.Equals(newName)) { throw new Exception("Names are the same!"); } else { context.Entry <Card>(foundCard).State = EntityState.Detached; foundCard.CardName = newName; context.Entry <Card>(foundCard).State = EntityState.Modified; } } catch (Exception ex) { throw ex; } }