public long MakeNewBookProposal(string userId, string title, string description, List <Author> authors, List <string> tags, int?datePublished) { authors.ForEach(a => a.Id = 0); //_context.SaveChanges(); HashSet <TagProposal> tagsToAdd = new HashSet <TagProposal>(); tags.ForEach(t => { var newTagProposal = new TagProposal { Label = t }; _context.TagProposals.Add(newTagProposal); tagsToAdd.Add(newTagProposal); }); var bookProposalToAdd = new BookProposal() { Title = title, Description = description, Authors = authors, Proposer = _context.Users.Find(userId), Tags = tagsToAdd, DatePublished = datePublished }; _context.BookProposals.Add(bookProposalToAdd); _context.SaveChanges(); return(bookProposalToAdd.Id); }
private void removeProposal(BookProposal proposalToRemove) { if (proposalToRemove.Authors != null) { _context.Authors.RemoveRange(proposalToRemove.Authors); } _context.BookProposals.Remove(proposalToRemove); if (proposalToRemove.Tags != null) { _context.TagProposals.RemoveRange(proposalToRemove.Tags); } }