I have a method that checks if the current item exists in the database before it adds it to the database, if it does exist it deletes the item else it adds it.
Is there any better way of doing this? Because right now the titles have to be exactly the same. If the titles have a char/word difference then it wont delete it.
Basically what I mean is this:
If title is "Ronaldo lost his right leg" and there is a title in the database that is "Ronaldo lost his right leg yesterday" it should delete current item.
Another example:
If title is "hello world" and there is a title in the database that is "hello world everyone" it should delete current item.
So basically if the text has common words it should delete the item.
Here is the method I have so far:
public void AddNews(News news)
{
var exists = db.News.Any(x => x.Title == news.Title);
if (exists == false)
{
db.News.AddObject(news);
}
else
{
db.News.DeleteObject(news);
}
}
Any kind of help is appreciated.