private void SetForeignKeysReferences(Entity entity, IIlaroAdmin admin) { foreach (var property in entity.Properties.Where(x => x.IsForeignKey)) { property.ForeignEntity = admin.GetEntity(property.ForeignEntityName); if (property.ReferencePropertyName.IsNullOrEmpty() == false) { property.ReferenceProperty = entity[property.ReferencePropertyName]; if (property.ReferenceProperty != null) { property.ReferenceProperty.IsForeignKey = true; property.ReferenceProperty.ForeignEntity = property.ForeignEntity; property.ReferenceProperty.ReferenceProperty = property; } else if (property.TypeInfo.IsSystemType == false) { property.TypeInfo.OriginalType = property.ForeignEntity == null ? // by default foreign property is int property.TypeInfo.OriginalType = typeof(int) : property.ForeignEntity.Keys.FirstOrDefault().TypeInfo.OriginalType; } } } }
public virtual ActionResult Index(string entityName, TableInfo tableInfo) { var entity = _admin.GetEntity(entityName); if (entity == null) { throw new NoNullAllowedException("entity is null"); } var pagedRecords = _recordsService.GetRecords(entity, Request.QueryString, tableInfo); if (pagedRecords.Records.IsNullOrEmpty() && tableInfo.Page > 1) { return(Redirect(Url.PageUrl(1))); } var model = new EntitiesIndexModel(entity, pagedRecords, tableInfo) { Configuration = _configuration, ChangeEnabled = _admin.ChangeEntity != null }; return(View(model)); }
public virtual ActionResult Create(string entityName) { var entity = _admin.GetEntity(entityName); if (entity == null) { return(RedirectToAction("NotFound", new { entityName })); } var model = new EntityCreateModel { Entity = entity, PropertiesGroups = _entityService.PrepareGroups(entity.CreateEmptyRecord()) }; return(View(model)); }