/// <summary> /// Saves the property item /// </summary> /// <param name="MappingHolder">Mapping holder</param> /// <param name="Object">Object</param> /// <param name="Models">Models</param> /// <returns>True if it is saved, false otherwise</returns> public override bool SaveValue(MappingHolder MappingHolder, dynamic Object, IEnumerable <Dynamo> Models) { if (MappingHolder == null) { return(false); } ClassType TempItem = Object; if (TempItem == null) { return(false); } if (AssignExpression == null) { return(false); } var Mapping = (IAPIMapping <DataType>)MappingHolder[typeof(DataType).Name]; var ClassMapping = (IAPIMapping <ClassType>)MappingHolder[typeof(ClassType).Name]; if (Mapping == null || ClassMapping == null || Models == null) { return(false); } Dynamo Model = Models.FirstOrDefault(); if (Model == null) { return(false); } dynamic TempModel = Model.SubSet(Mapping.Properties.Where(x => x is IReference || x is IID) .Select(x => x.Name) .ToArray()); DataType Property = TempModel; DataType Value = CompiledExpression(TempItem); if (Value == null) { AssignExpression(TempItem, Property); Mapping.SaveFunc(Property); return(ClassMapping.SaveFunc(TempItem)); } else if (Value.Equals(Property)) { Model.SubSet(Mapping.Properties.Where(x => x is IReference || x is IID) .Select(x => x.Name) .ToArray()) .CopyTo(Value); return(Mapping.SaveFunc(Value)); } AssignExpression(TempItem, Property); return(ClassMapping.SaveFunc(TempItem)); }
/// <summary> /// Gets the value of the property from an object /// </summary> /// <param name="Object">Object to get the property from</param> /// <param name="Mappings">Mappings</param> /// <returns>The property specified</returns> public override dynamic GetValue(MappingHolder Mappings, dynamic Object) { if (Mappings == null || CompiledExpression == null) { return(false); } ClassType TempItem = Object; if (TempItem == null) { return(null); } var Mapping = (IAPIMapping <DataType>)Mappings[typeof(DataType).Name]; if (Mapping == null) { return(new Dynamo(CompiledExpression(TempItem))); } var ReturnValue = new List <Dynamo>(); foreach (DataType Item in CompiledExpression(TempItem)) { if (Mapping.CanGet(Item)) { var ReturnItem = new Dynamo(Item); ReturnValue.Add(ReturnItem.SubSet(Mapping.Properties.Where(x => x is IReference || x is IID) .Select(x => x.Name) .ToArray())); } } return(ReturnValue); }
/// <summary> /// Saves the specified object /// </summary> /// <param name="Object">Object to save</param> /// <returns>True if it is saved, false otherwise</returns> public bool Save(Dynamo Object) { if (Object == null) { return(false); } IAPIProperty IDProperty = Properties.FirstOrDefault(x => x is IID); if (IDProperty == null) { return(false); } object IDValue = Object[IDProperty.Name]; ClassType Item = IDValue == null ? new ClassType() : AnyFunc(IDValue.ToString()).Check(new ClassType()); if (!CanSaveFunc(Item)) { return(false); } Dynamo SubSet = Object.SubSet(Properties.Where(x => x is IReference) .Select(x => x.Name) .ToArray()); if (SubSet != null) { SubSet.CopyTo(Item); } return(SaveFunc(Item)); }
/// <summary> /// Gets the item specified of the mapped type /// </summary> /// <param name="ID">ID of the item</param> /// <param name="Mappings">Mappings</param> /// <param name="EmbeddedProperties">Properties to embed</param> /// <returns>The item specified</returns> public Dynamo Any(string ID, MappingHolder Mappings, params string[] EmbeddedProperties) { if (string.IsNullOrEmpty(ID)) { throw new ArgumentNullException(nameof(ID)); } ClassType Object = AnyFunc(ID); if (!CanGetFunc(Object)) { return(null); } var TempItem = new Dynamo(Object); Dynamo ReturnValue = TempItem.SubSet(Properties.Where(x => x is IReference || x is IID) .Select(x => x.Name) .ToArray()); string AbsoluteUri = HttpContext.Current != null?HttpContext.Current.Request.Url.AbsoluteUri.Left(HttpContext.Current.Request.Url.AbsoluteUri.IndexOf('?')) : ""; if (!AbsoluteUri.EndsWith("/", StringComparison.Ordinal)) { AbsoluteUri += "/"; } foreach (IAPIProperty Property in Properties.Where(x => x is IMap)) { ReturnValue[Property.Name] = EmbeddedProperties.Contains(Property.Name) ? (object)Property.GetValue(Mappings, TempItem) : (object)(AbsoluteUri + Property.Name); } return(ReturnValue); }
/// <summary> /// Gets the value of the property from an object /// </summary> /// <param name="Object">Object to get the property from</param> /// <param name="Mappings">Mappings</param> /// <returns>The property specified</returns> public override dynamic GetValue(MappingHolder Mappings, dynamic Object) { if (Mappings == null) { return(false); } ClassType TempItem = Object; if (TempItem == null) { return(null); } var Mapping = (IAPIMapping <DataType>)Mappings[typeof(DataType).Name]; if (Mapping == null) { return(new Dynamo(CompiledExpression(TempItem))); } DataType Value = CompiledExpression(TempItem); if (!Mapping.CanGet(Value)) { return(null); } var ReturnValue = new Dynamo(Value); return(ReturnValue.SubSet(Mapping.Properties.Where(x => x is IReference || x is IID) .Select(x => x.Name) .ToArray())); }
/// <summary> /// Gets all items of the mapped type /// </summary> /// <param name="EmbeddedProperties">Properties to embed</param> /// <param name="Mappings">Mappings</param> /// <returns>All items of the mapped type</returns> public IEnumerable <Dynamo> All(MappingHolder Mappings, params string[] EmbeddedProperties) { IEnumerable <ClassType> Objects = AllFunc(); if (Objects == null) { Objects = new List <ClassType>(); } var ReturnValue = new List <Dynamo>(); foreach (ClassType Object in Objects) { if (CanGetFunc(Object)) { var TempItem = new Dynamo(Object); Dynamo ReturnItem = TempItem.SubSet(Properties.Where(x => x is IReference || x is IID) .Select(x => x.Name) .ToArray()); string AbsoluteUri = HttpContext.Current != null?HttpContext.Current.Request.Url.AbsoluteUri.Left(HttpContext.Current.Request.Url.AbsoluteUri.IndexOf('?')) : ""; AbsoluteUri = AbsoluteUri.Check(""); if (!AbsoluteUri.EndsWith("/", StringComparison.Ordinal)) { AbsoluteUri += "/"; } AbsoluteUri += Properties.FirstOrDefault(x => x is IID).GetValue(Mappings, Object).ToString() + "/"; foreach (IAPIProperty Property in Properties.Where(x => x is IMap)) { ReturnItem[Property.Name] = EmbeddedProperties.Contains(Property.Name) ? (object)Property.GetValue(Mappings, TempItem) : (object)(AbsoluteUri + Property.Name); } ReturnValue.Add(ReturnItem); } } return(ReturnValue); }
/// <summary> /// Gets all items of the mapped type /// </summary> /// <param name="Mappings">The mapping holder</param> /// <param name="PageSize">Size of the page.</param> /// <param name="Page">The page specified</param> /// <param name="OrderBy">The order by clause</param> /// <param name="EmbeddedProperties">Properties to embed</param> /// <returns>All items of the mapped type</returns> public IEnumerable <Dynamo> Paged(MappingHolder Mappings, int PageSize, int Page, string[] OrderBy, string[] EmbeddedProperties) { if (OrderBy == null) { OrderBy = new string[0]; } string OrderByClauseFinal = ""; string Splitter = ""; foreach (string OrderByClause in OrderBy) { string[] SplitValues = OrderByClause.Split(' '); if (SplitValues.Length > 0) { if (Properties.Where(x => x is IReference || x is IID).Any(x => string.Equals(x.Name, SplitValues[0], StringComparison.InvariantCulture))) { OrderByClauseFinal += Splitter + SplitValues[0]; if (SplitValues.Length > 1) { SplitValues[1] = SplitValues[1].Equals("DESC", StringComparison.InvariantCultureIgnoreCase) ? "DESC" : "ASC"; OrderByClauseFinal += " " + SplitValues[1]; } Splitter = ","; } } } IEnumerable <ClassType> Objects = PagedFunc(PageSize, Page, OrderByClauseFinal); if (Objects == null) { Objects = new List <ClassType>(); } var ReturnValue = new List <Dynamo>(); foreach (ClassType Object in Objects) { if (CanGetFunc(Object)) { var TempItem = new Dynamo(Object); Dynamo ReturnItem = TempItem.SubSet(Properties.Where(x => x is IReference || x is IID) .Select(x => x.Name) .ToArray()); string AbsoluteUri = HttpContext.Current != null?HttpContext.Current.Request.Url.AbsoluteUri.Left(HttpContext.Current.Request.Url.AbsoluteUri.IndexOf('?')) : ""; AbsoluteUri = AbsoluteUri.Check(""); if (!AbsoluteUri.EndsWith("/", StringComparison.Ordinal)) { AbsoluteUri += "/"; } AbsoluteUri += Properties.FirstOrDefault(x => x is IID).GetValue(Mappings, Object).ToString() + "/"; foreach (IAPIProperty Property in Properties.Where(x => x is IMap)) { ReturnItem[Property.Name] = EmbeddedProperties.Contains(Property.Name) ? (object)Property.GetValue(Mappings, TempItem) : (object)(AbsoluteUri + Property.Name); } ReturnValue.Add(ReturnItem); } } return(ReturnValue); }