Пример #1
0
 /// <summary>
 /// Update the tags associated with a content container that has been edited
 /// </summary>
 /// <param name="contentContainer"></param>
 /// <param name="listOfTags"></param>
 private void UpdateTagsInContentContainer(ContentContainer contentContainer, string listOfTags)
 {
     IEnumerable<string> formattedListOfTags = ExtractTagsFromString(listOfTags);
     // gets a IEnumerable of string tags from the comma separated list of tags
     DeleteTagsFromContentContainer(contentContainer, formattedListOfTags);
     // add tags
     AddListOfTagsToContentContainer(contentContainer, formattedListOfTags);
 }
Пример #2
0
 /// <summary>
 /// Update the categories associated with a content container that has been edited
 /// </summary>
 /// <param name="contentContainer"></param>
 /// <param name="categoryId"></param>
 private void UpdateCategoriesInContentContainer(ContentContainer contentContainer, int[] categoryId)
 {
     // Delete association with categories no longer selected
     DeleteCategoriesFromContentContainer(contentContainer, categoryId);
     // Add association with categories that have been selected
     AddCategoriesToContentContainer(contentContainer, categoryId);
 }
Пример #3
0
 /// <summary>
 /// Deletes the association between a content container and those tags that are no longer selected
 /// </summary>
 /// <param name="contentContainer"></param>
 /// <param name="stringTags"></param>
 private void DeleteTagsFromContentContainer(ContentContainer contentContainer, IEnumerable<string> stringTags)
 {
     var query = from tag in contentContainer.Tags
                 from tagString in stringTags
                 where tag.Name == tagString
                 select tag;
     var tagsPresent = query.Distinct().ToList();
     // Delete the association with tags that are no longer needed
     // select tags to delete
     List<Tag> tagsToDelete = contentContainer.Tags.Where(tag => !tagsPresent.Contains(tag)).ToList();
     // delete them
     foreach(var tag in tagsToDelete)
         contentContainer.Tags.Remove(tag);
 }
Пример #4
0
 /// <summary>
 /// Deletes the associations with categories that are no longer selected
 /// </summary>
 /// <param name="contentContainer"></param>
 /// <param name="categoryId"></param>
 private void DeleteCategoriesFromContentContainer(ContentContainer contentContainer, int[] categoryId)
 {
     if (categoryId != null)
     {
         // This should be improved****
         var query = from category in contentContainer.Categories
                     from id in categoryId
                     where category.CategoryID == id
                     select category;
         List<Category> categoriesPresent = query.Distinct().ToList();
         // Delete those not present
         // Select categories to delete
         List<Category> categoriesToDelete = contentContainer.Categories.Where(category => !categoriesPresent.Contains(category)).ToList();
         // Delete them
         foreach (var category in categoriesToDelete)
             contentContainer.Categories.Remove(category);
     }
     else
     {
         while (contentContainer.Categories.Count > 0)
             contentContainer.Categories.RemoveAt(0);
     }
 }
Пример #5
0
 /// <summary>
 /// Method that adds the tags represented by a string list of tags to a certain
 /// contentContainer
 /// </summary>
 /// <param name="contentContainer"></param>
 /// <param name="listOfTags"></param>
 private void AddListOfTagsToContentContainer(ContentContainer contentContainer, IEnumerable<string> listOfTags)
 {
     IEnumerable<Tag> tags = ManageTagsFromListOfTags(listOfTags);
     foreach (Tag tag in tags)
     {
         if (!contentContainer.Tags.Contains(tag))
             contentContainer.Tags.Add(tag);
     }
 }
Пример #6
0
 /// <summary>
 /// Adds the categories that have been selected to a given content container
 /// </summary>
 /// <param name="contentContainer"></param>
 /// <param name="categories"></param>
 private void AddCategoriesToContentContainer(ContentContainer contentContainer, int[] categories)
 {
     if (categories != null)
     {
         foreach (var categoryID in categories)
         {
             // get category from database
             Category category = _context.Categories.Single(x => x.CategoryID == categoryID);
             // add it to blogPost
             if (!contentContainer.Categories.Contains(category))
                 contentContainer.Categories.Add(category);
         }
     }
 }