private static ContentTypeItem CreateContentTypeItem(ContentType contentType) { var contentTypeItem = new ContentTypeItem { Type = contentType.Type, DisplayName = contentType.DisplayName, ControllerName = contentType.ControllerName }; var contentActionItems = contentType.Actions.Select( action => new ContentActionItem { Action = action.Action, ContentType = contentType.Type, DisplayName = action.DisplayName }); contentTypeItem.ContentActionItems.AddRange(contentActionItems); return contentTypeItem; }
private static void UpdateContentTypeItem(ContentTypeItem contentTypeItem, ContentType contentType, ContentDataContext contentDataContext) { contentTypeItem.DisplayName = contentType.DisplayName; var actionsToDelete = (from item in contentTypeItem.ContentActionItems where !contentType.Actions.Any(action => action.Action == item.Action) select item).ToList(); var actionsToUpdate = (from item in contentTypeItem.ContentActionItems let action = contentType.Actions.SingleOrDefault(a => a.Action == item.Action) where action != null select new { item, action }).ToList(); var actionsToInsert = (from action in contentType.Actions where !contentTypeItem.ContentActionItems.Any(a => a.Action == action.Action) select new ContentActionItem { Action = action.Action, ContentType = contentTypeItem.Type, DisplayName = action.DisplayName }). ToList(); contentDataContext.ContentActionItems.DeleteAllOnSubmit(actionsToDelete); actionsToUpdate.ForEach(a => { a.item.DisplayName = a.action.DisplayName; }); contentTypeItem.ContentActionItems.AddRange(actionsToInsert); }