I have two functions that are similar. The only differences is that they're using two different models. How can I change them into one function?
ITagRepository tagRepo = new TagRepository();
ICategoryRepository catRepo = new CategoryRepository();
public void AddTagsDontExist(string tags)
{
var allTags = tagRepo.GetAllQueryAble();
string[] tag = tags.Split(',');
foreach (var item in tag)
{
if (allTags.Where(e => e.Name.Contains(item)).Count() == 0)
{
tagRepo.Add(new Tag
{
Name = item.ToString(),
DateAdded = DateTime.Now,
LastModifiedDate = DateTime.Now,
IsDeleted = false
});
}
}
}
public void AddCategoriesDontExist(string Categories)
{
var allCategory = catRepo.GetAllQueryAble();
string[] Category = Categories.Split(',');
foreach (var item in Category)
{
if (allCategory.Where(e => e.Name.Contains(item)).Count() == 0)
{
catRepo.Add(new Category
{
Name = item.ToString(),
DateAdded = DateTime.Now,
LastModifiedDate = DateTime.Now,
IsDeleted = false
});
}
}
}
ToArray
in one, but not the other? \$\endgroup\$