public void Update(CardDetails cardDetails) { var card = _dbContext.Cards.SingleOrDefault(x => x.Id == cardDetails.Id); card.Contents = cardDetails.Contents; card.Notes = cardDetails.Notes; card.ColumnId = cardDetails.Column; _dbContext.SaveChanges(); }
public void Delete(int id) { var card = _dbContext.Cards.SingleOrDefault(x => x.Id == id); _dbContext.Remove(card ?? throw new Exception($"Could not remove {(Card) null}")); _dbContext.SaveChanges(); }
public void AddCard(AddCard viewModel) { var board = _dbContext.Boards .Include(b => b.Columns) .SingleOrDefault(x => x.Id == viewModel.Id); if (board != null) { var firstColumn = board.Columns.FirstOrDefault(); var secondColumn = board.Columns.FirstOrDefault(); var thirdColumn = board.Columns.FirstOrDefault(); if (firstColumn == null || secondColumn == null || thirdColumn == null) { firstColumn = new Models.Column { Title = "Todo" }; secondColumn = new Models.Column { Title = "Doing" }; thirdColumn = new Models.Column { Title = "Done" }; board.Columns.Add(firstColumn); board.Columns.Add(secondColumn); board.Columns.Add(thirdColumn); } firstColumn.Cards.Add(new Models.Card { Contents = viewModel.Contents }); } _dbContext.SaveChanges(); }