Ejemplo n.º 1
0
        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)
            )
              };
        }
Ejemplo n.º 6
0
        private CachedObject CacheObject(Culture culture, Object @object)
        {
            Class @class = this.handler.Storage.GetRepository<IClassRepository>().WithKey(@object.ClassId);
              List<CachedProperty> cachedProperties = new List<CachedProperty>();

              foreach (Member member in this.handler.Storage.GetRepository<IMemberRepository>().FilteredByClassId(@class.Id))
              {
            if (member.PropertyDataTypeId != null)
            {
              Property property = this.handler.Storage.GetRepository<IPropertyRepository>().WithObjectIdAndMemberId(@object.Id, member.Id);

              cachedProperties.Add(this.CacheProperty(culture, property));
            }
              }

              List<CachedDataSource> cachedDataSources = new List<CachedDataSource>();

              foreach (DataSource dataSource in this.handler.Storage.GetRepository<IDataSourceRepository>().FilteredByClassId(@class.Id))
            cachedDataSources.Add(this.CacheDataSource(culture, dataSource));

              CachedObject cachedObject = new CachedObject();

              cachedObject.ObjectId = @object.Id;
              cachedObject.ClassId = @class.Id;
              cachedObject.ClassViewName = @class.ViewName;
              cachedObject.Url = @object.Url;
              cachedObject.CultureId = culture.Id;

              if (cachedProperties.Count != 0)
            cachedObject.CachedProperties = this.SerializeObject(cachedProperties);

              if (cachedDataSources.Count != 0)
            cachedObject.CachedDataSources = this.SerializeObject(cachedDataSources);

              return cachedObject;
        }
Ejemplo n.º 7
0
        public void CacheObject(Object @object)
        {
            foreach (Culture culture in this.handler.Storage.GetRepository<ICultureRepository>().All())
              {
            CachedObject cachedObject = this.handler.Storage.GetRepository<ICachedObjectRepository>().WithKey(culture.Id, @object.Id);

            if (cachedObject == null)
              this.handler.Storage.GetRepository<ICachedObjectRepository>().Create(this.CacheObject(culture, @object));

            else
            {
              CachedObject temp = this.CacheObject(culture, @object);

              cachedObject.ClassId = temp.ClassId;
              cachedObject.ClassViewName = temp.ClassViewName;
              cachedObject.Url = temp.Url;
              cachedObject.CachedProperties = temp.CachedProperties;
              cachedObject.CachedDataSources = temp.CachedDataSources;
              this.handler.Storage.GetRepository<ICachedObjectRepository>().Edit(cachedObject);
            }
              }

              this.handler.Storage.Save();
        }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
 private void CreateOrEditRelations(Object @object)
 {
     this.DeleteRelations(@object);
       this.CreateRelations(@object);
 }
Ejemplo n.º 11
0
 private void CreateOrEditProperties(Object @object)
 {
     this.DeleteProperties(@object);
       this.CreateProperties(@object);
 }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        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].ToString().Split(',').Select(id => int.Parse(id));

              foreach (int primaryId in primaryIds)
            this.CreateRelation(int.Parse(memberId), primaryId, @object.Id);

              this.Storage.Save();
            }
              }
        }
Ejemplo n.º 15
0
        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);
        }