public ObjectViewModel Build(Object @object) { Class @class = this.handler.Storage.GetRepository<IClassRepository>().WithKey(@object.ClassId); IDictionary<string, DataSourceViewModel> dataSourceInstances = new Dictionary<string, DataSourceViewModel>(); foreach (DataSource dataSource in this.handler.Storage.GetRepository<IDataSourceRepository>().FilteredByClassId(@class.Id)) { System.Type type = System.Type.GetType(dataSource.CSharpClassName); IDataSource dataSourceInstance = System.Activator.CreateInstance(type) as IDataSource; dataSourceInstance.Initialize(this.handler, @object, this.GetParameters(dataSource.Parameters)); dataSourceInstances.Add(dataSource.Code, new DataSourceViewModelBuilder(this.handler).Build(dataSourceInstance.GetObjects())); } return new ObjectViewModel() { Id = @object.Id, Class = new ClassViewModelBuilder(this.handler).Build(@class.Id, @class.ViewName), Url = @object.Url, Properties = this.handler.Storage.GetRepository<IPropertyRepository>().FilteredByObjectId(@object.Id).ToDictionary( p => this.handler.Storage.GetRepository<IMemberRepository>().WithKey(p.MemberId).Code, p => new PropertyViewModelBuilder(this.handler).Build(p) ), DataSources = dataSourceInstances }; }
public IEnumerable<string> GetDisplayProperties(Object @object) { List<string> properties = new List<string>(); foreach (Member member in this.handler.Storage.GetRepository<IMemberRepository>().FilteredByClassId(@object.ClassId)) { if (member.DisplayInList == true) { Property property = this.handler.Storage.GetRepository<IPropertyRepository>().WithObjectIdAndMemberId(@object.Id, member.Id); if (property == null) properties.Add(string.Empty); else { Localization localization = this.handler.Storage.GetRepository<ILocalizationRepository>().WithDictionaryIdAndCultureId(property.HtmlId, 1); if (localization == null) properties.Add(string.Empty); else properties.Add(localization.Value); } } } return properties; }
public MemberViewModel Build(Member member, Object @object, int? objectId = null) { IEnumerable<RelationViewModel> relations = null; PropertyViewModel property = null; if (member.RelationClassId != null) { if (@object == null && objectId == null) relations = new RelationViewModel[] { }; else if (@object == null && objectId != null) relations = new RelationViewModel[] { new RelationViewModel() { PrimaryId = (int)objectId } }; else relations = this.handler.Storage.GetRepository<IRelationRepository>().FilteredByMemberIdAndForeignId(member.Id, @object.Id).Select( r => new RelationViewModelBuilder(this.handler).Build(r) ); } else if (member.PropertyDataTypeId != null) { if (@object == null) property = new PropertyViewModelBuilder(this.handler).Build( new Property() { ObjectId = @object == null ? (int?)null : @object.Id } ); else { Property p = this.handler.Storage.GetRepository<IPropertyRepository>().WithObjectIdAndMemberId(@object.Id, member.Id); property = new PropertyViewModelBuilder(this.handler).Build( p == null ? new Property() { ObjectId = @object == null ? (int?)null : @object.Id } : p ); } } return new MemberViewModel() { Id = member.Id, RelationClass = member.RelationClassId == null ? null : new ClassViewModelBuilder(this.handler).Build( this.handler.Storage.GetRepository<IClassRepository>().WithKey((int)member.RelationClassId) ), IsRelationSingleParent = member.IsRelationSingleParent == true, Relations = relations, PropertyDataType = member.PropertyDataTypeId == null ? null : new DataTypeViewModelBuilder(this.handler).Build( this.handler.Storage.GetRepository<IDataTypeRepository>().WithKey((int)member.PropertyDataTypeId) ), Property = property, Name = member.Name, Position = member.Position }; }
public Object Map(CreateOrEditViewModel createOrEdit) { Object @object = new Object(); if (createOrEdit.Id != null) @object = this.handler.Storage.GetRepository<IObjectRepository>().WithKey((int)createOrEdit.Id); else @object.ClassId = (int)createOrEdit.ClassId; Class @class = this.handler.Storage.GetRepository<IClassRepository>().WithKey(@object.ClassId); if (@class.IsStandalone == true) @object.Url = createOrEdit._Url; else @object.Url = null; return @object; }
private IDictionary<TabViewModel, IEnumerable<MemberViewModel>> GetMembersByTabs(Object @object, int? classId = null, int? objectId = null) { Dictionary<TabViewModel, IEnumerable<MemberViewModel>> membersByTabs = new Dictionary<TabViewModel, IEnumerable<MemberViewModel>>(); membersByTabs.Add(new TabViewModel() { Name = "General" }, new List<MemberViewModel>()); foreach (Tab tab in this.handler.Storage.GetRepository<ITabRepository>().FilteredByClassId(@object != null ? @object.ClassId : (int)classId)) membersByTabs.Add(new TabViewModelBuilder(this.handler).Build(tab), new List<MemberViewModel>()); foreach (Member member in this.handler.Storage.GetRepository<IMemberRepository>().FilteredByClassId(@object != null ? @object.ClassId : (int)classId)) { TabViewModel tab = null; if (member.TabId == null) tab = membersByTabs.Keys.FirstOrDefault(t => t.Id == 0); else tab = membersByTabs.Keys.FirstOrDefault(t => t.Id == (int)member.TabId); (membersByTabs[tab] as List<MemberViewModel>).Add(new MemberViewModelBuilder(this.handler).Build(member, @object, objectId)); } return membersByTabs; }
public ObjectViewModel Build(Object @object) { List<Class> relatedClasses = new List<Class>(); foreach (Member member in this.handler.Storage.GetRepository<IMemberRepository>().FilteredByRelationClassIdRelationSingleParent(@object.ClassId)) { Class @class = this.handler.Storage.GetRepository<IClassRepository>().WithKey((int)member.ClassId); relatedClasses.Add(@class); } return new ObjectViewModel() { Id = @object.Id, Url = @object.Url, Class = new ClassViewModelBuilder(this.handler).Build( this.handler.Storage.GetRepository<IClassRepository>().WithKey(@object.ClassId) ), Properties = new ObjectManager(this.handler).GetDisplayProperties(@object), RelatedClasses = relatedClasses.Select( c => new ClassViewModelBuilder(this.handler).Build(c) ) }; }
private void CreateProperties(Object @object) { foreach (string key in this.Request.Form.Keys) { if (key.StartsWith("propertyMember")) { string memberIdAndCultureCode = key.Replace("propertyMember", string.Empty); string memberId = memberIdAndCultureCode.Remove(memberIdAndCultureCode.Length - 2); string cultureCode = memberIdAndCultureCode.Substring(memberIdAndCultureCode.Length - 2); this.CreateProperty(@object, int.Parse(memberId), cultureCode, this.Request.Form[key]); } } this.Storage.Save(); }
private void CreateOrEditRelations(Object @object) { this.DeleteRelations(@object); this.CreateRelations(@object); }
private void CreateOrEditProperties(Object @object) { this.DeleteProperties(@object); this.CreateProperties(@object); }
private void DeleteRelations(Object @object) { foreach (Relation relation in this.Storage.GetRepository<IRelationRepository>().FilteredByForeignId(@object.Id)) this.Storage.GetRepository<IRelationRepository>().Delete(relation); this.Storage.Save(); }
private void DeleteProperties(Object @object) { foreach (Property property in this.Storage.GetRepository<IPropertyRepository>().FilteredByObjectId(@object.Id).ToList()) this.Storage.GetRepository<IPropertyRepository>().Delete(property); this.Storage.Save(); }
private void CreateRelations(Object @object) { foreach (string key in this.Request.Form.Keys) { if (key.StartsWith("relationMember")) { string memberId = key.Replace("relationMember", string.Empty); IEnumerable<int> primaryIds = this.Request.Form[key].Split(',').Select(id => int.Parse(id)); foreach (int primaryId in primaryIds) this.CreateRelation(int.Parse(memberId), primaryId, @object.Id); this.Storage.Save(); } } }
private void CreateProperty(Object @object, int memberId, string cultureCode, string value) { Property property = this.Storage.GetRepository<IPropertyRepository>().WithObjectIdAndMemberId(@object.Id, memberId); if (property == null) { Dictionary html = new Dictionary(); this.Storage.GetRepository<IDictionaryRepository>().Create(html); this.Storage.Save(); property = new Property(); property.ObjectId = @object.Id; property.MemberId = memberId; property.HtmlId = html.Id; this.Storage.GetRepository<IPropertyRepository>().Create(property); this.Storage.Save(); } Localization localization = new Localization(); localization.DictionaryId = property.HtmlId; localization.CultureId = this.Storage.GetRepository<ICultureRepository>().WithCode(cultureCode).Id; localization.Value = value; this.Storage.GetRepository<ILocalizationRepository>().Create(localization); }
public void Initialize(IHandler handler, Object @object, params KeyValuePair<string, string>[] args) { this.handler = handler; this.@object = @object; this.args = args.ToDictionary(a => a.Key, a => a.Value); }