internal bool Resolve(Project project, Screen screen, ScreenSection screenSection, out string message) { Project = project; Property = screenSection.Entity.Properties.SingleOrDefault(p => p.Id == EntityPropertyId); if (Property == null) { message = $"PropertyId:{EntityPropertyId} does not exisit. So on ScreenId:{screen.Id}"; return(false); } switch (PropertyType) { case PropertyType.PrimaryKey: case PropertyType.ParentRelationshipOneToMany: IsHiddenFromUi = true; break; case PropertyType.ParentRelationshipOneToOne: break; } message = "Success"; return(true); }
private void GenerateAdminScreenAndMenu() { var administrationScreen = Screens.Where(s => s.InternalName.Equals("Administration", StringComparison.OrdinalIgnoreCase)).SingleOrDefault(); if (administrationScreen == null) { administrationScreen = new Screen() { Id = new ObjectId("5ca8770f4a73264e4c06e037"), Title = "Administration", ScreenType = ScreenType.Html, Path = "administration" }; var screens = new List <Screen>(Screens) { administrationScreen }; Screens = screens.ToArray(); var menus = new List <MenuItem>(MenuItems) { new MenuItem() { ScreenId = administrationScreen.Id, Title = "Administration" } }; MenuItems = menus; } ScreenSection administrationSection = null; if (administrationScreen.ScreenSections != null) { administrationSection = administrationScreen.ScreenSections.Where(s => s.InternalName.Equals("Administration", StringComparison.OrdinalIgnoreCase)).SingleOrDefault(); } if (administrationSection == null) { var menuItems = new List <MenuItem>(); foreach (var screen in Screens.Where(a => a.Template == ScreenTemplate.Reference)) { var menuItem = new MenuItem { ScreenId = screen.Id, MenuItemType = MenuItemType.ApplicationLink }; menuItems.Add(menuItem); } administrationSection = new ScreenSection() { Id = new ObjectId("5ca8770f4a73264e4c06e038"), InternalName = "Administration", Title = "Administration", ScreenSectionType = ScreenSectionType.MenuList, MenuListMenuItems = menuItems }; var sections = new List <ScreenSection>() { administrationSection }; if (administrationScreen.ScreenSections != null) { sections.AddRange(administrationScreen.ScreenSections); } administrationScreen.ScreenSections = sections.ToArray(); } }
/// <summary> /// Resolve Form Section /// </summary> internal bool Resolve(Project project, Screen screen, ScreenSection screenSection, out string message) { var errors = new List <string>(); Screen = screen; ScreenSection = screenSection; Entity = screenSection.Entity; // Populate Property property for helper functions to work if (FormFields != null) { foreach (var formField in FormFields) { if (!formField.Resolve(project, screen, screenSection, out string formFieldMessage)) { errors.Add(formFieldMessage); } } // Add Primary Key field if (!FormFields.Any(a => a.PropertyType == PropertyType.PrimaryKey)) { var primaryKeyProperty = Entity.Properties.Single(property => property.PropertyType == PropertyType.PrimaryKey); var primaryKeyFormField = new FormField { EntityPropertyId = primaryKeyProperty.Id, IsHiddenFromUi = true }; if (!primaryKeyFormField.Resolve(project, screen, screenSection, out string formFieldMessage)) { errors.Add(formFieldMessage); } var primaryKeyformFields = new List <FormField>(FormFields) { primaryKeyFormField }; FormFields = primaryKeyformFields; } // Add Parent Relationship if (ScreenSection.ParentScreenSection == null) { Property parentProperty = (from p in ScreenSection.Entity.Properties where p.PropertyType == PropertyType.ParentRelationshipOneToMany || p.PropertyType == PropertyType.ParentRelationshipOneToOne select p).SingleOrDefault(); if (parentProperty != null) { var parentFormField = new FormField { EntityPropertyId = parentProperty.Id, IsHiddenFromUi = true }; if (!parentFormField.Resolve(project, screen, screenSection, out string formFieldMessage)) { errors.Add(formFieldMessage); } var parentFormFields = new List <FormField>(FormFields) { parentFormField }; FormFields = parentFormFields; } } } if (errors.Any()) { message = string.Join(Environment.NewLine, errors); return(false); } else { message = "Success"; return(true); } }
/// <summary> /// Fills in any missing values and records it can to assist templating /// </summary> internal bool Resolve(Project project, out string message) { var errors = new List <string>(); if (EntityId.HasValue) { Entity = project.Entities.Single(e => e.Id == EntityId.Value); } if (ScreenSections == null || !ScreenSections.Any()) { var screenSectionType = ScreenSectionType.Html; if (EntityId.HasValue) { switch (ScreenType) { case ScreenType.Search: screenSectionType = ScreenSectionType.Search; break; case ScreenType.Form: screenSectionType = ScreenSectionType.Form; break; case ScreenType.View: screenSectionType = ScreenSectionType.Form; break; case ScreenType.Html: screenSectionType = ScreenSectionType.Html; break; default: break; } } ScreenSections = new ScreenSection[] { new ScreenSection { Id = Id, Title = Title, EntityId = EntityId, InternalName = InternalName, ScreenSectionType = screenSectionType } }; } else { foreach (var screenSection in ScreenSections) { if (!screenSection.EntityId.HasValue) { screenSection.EntityId = EntityId; } } } if (string.IsNullOrEmpty(Path)) { Path = Title.Kebaberize(); } if (MenuItems != null) { var firstScreenSection = ScreenSections.First(); if (firstScreenSection != null) { var menuItems = new List <MenuItem>(); if (firstScreenSection.MenuItems != null) { menuItems.AddRange(firstScreenSection.MenuItems); } menuItems.AddRange(MenuItems); firstScreenSection.MenuItems = menuItems; } } // Resolve child records foreach (var screenSection in ScreenSections) { if (!screenSection.Resolve(project, this, out string screenSectionMessage)) { errors.Add(screenSectionMessage); } } if (errors.Any()) { message = string.Join(Environment.NewLine, errors); return(false); } else { message = "Success"; return(true); } }