/// <summary> /// Gets the given view in the pattern. /// </summary> /// <returns></returns> public static IViewSchema GetView(this IPatternSchema pattern, Guid defaultViewId) { Guard.NotNull(() => pattern, pattern); Guard.NotNull(() => defaultViewId, defaultViewId); return(pattern.Views.FirstOrDefault(v => ((INamedElementSchema)v).Id == defaultViewId)); }
private static void SetOtherViewAsDefault(IPatternSchema pattern, IViewSchema viewSchema) { var otherViewSchema = pattern.Views.ToList <INamedElementSchema>() .OrderBy(v => v.Name) .FirstOrDefault(v => v.Id != ((INamedElementSchema)viewSchema).Id); if (otherViewSchema != null) { SetDefaultView(pattern, otherViewSchema.Id); } }
/// <summary> /// Sets the given view as the default view in the pattern. /// </summary> /// <returns></returns> public static void SetDefaultView(this IPatternSchema pattern, Guid defaultViewId) { Guard.NotNull(() => pattern, pattern); Guard.NotNull(() => defaultViewId, defaultViewId); var viewSchema = pattern.Views.FirstOrDefault(v => ((INamedElementSchema)v).Id == defaultViewId); if (viewSchema != null) { viewSchema.IsDefault = true; } }
/// <summary> /// Deletes the view from the current pattern. /// </summary> public static bool DeleteView(this IPatternSchema pattern, Guid defaultViewId) { Guard.NotNull(() => pattern, pattern); Guard.NotNull(() => defaultViewId, defaultViewId); var viewSchema = pattern.Views.FirstOrDefault(v => ((INamedElementSchema)v).Id == defaultViewId); if (viewSchema != null) { if (viewSchema.IsDefault) { // Set another view as the default SetOtherViewAsDefault(pattern, viewSchema); } // Delete from the DSL pattern.DeleteViewSchema(viewSchema); return(true); } return(false); }
private static void SetOtherViewAsDefault(IPatternSchema pattern, IViewSchema viewSchema) { var otherViewSchema = pattern.Views.ToList<INamedElementSchema>() .OrderBy(v => v.Name) .FirstOrDefault(v => v.Id != ((INamedElementSchema)viewSchema).Id); if (otherViewSchema != null) { SetDefaultView(pattern, otherViewSchema.Id); } }