How can I avoid code duplication
<p>I have the follwoing code and I would like to write it in a way that I have minimum lines of code and the work is done the same way.  How can  I do that? </p>

<pre><code>List&lt;Category&gt; categoryList = new List&lt;Category&gt;();
categoryList = Category.LoadForProject(project.ID).ToList();
List&lt;string&gt; categories = new List&lt;string&gt;(Categories);
IList&lt;Category&gt; currentCategories = Category.LoadForProject(project.ID).ToList();
if (currentCategories != null)
{
    foreach (var existingCategories in currentCategories)
    {
        if (categories.Contains(existingCategories.Name))
           categories.Remove(existingCategories.Name);
        else
            existingCategories.Delete(Services.UserServices.User);
    }
    foreach (string item in categories)
    {
        Category category = new Category(project, item.ToString());
        category.Project = project;
        category.Save();
   }
}
</code></pre>

<hr>

<pre><code>List&lt;string&gt; priorities = new List&lt;string&gt;(Priorities);
IList&lt;Priority&gt; currentPriorities = Priority.LoadForProject(project.ID).ToList();
if (currentPriorities != null)
{
   foreach (var existingPriorities in currentPriorities)
   {
       if (priorities.Contains(existingPriorities.Name))
           priorities.Remove(existingPriorities.Name);
       else
           existingPriorities.Delete(Services.UserServices.User);
   }
   foreach (string item in priorities)
   {
       Priority priority = new Priority(project, item.ToString());
       priority.Project = project;
       priority.Save();
   }
}
</code></pre>
