public virtual JObject Map(RestaurantDatabaseSettings ctx, bool customMap = false)
        {
            JObject result = null;

            PropertyInfo[] objProperties = this.GetType().GetProperties();

            if (objProperties.Count() == 0)
            {
                throw new Exception("There are no mappeable properties.");
            }

            foreach (PropertyInfo pi in objProperties)
            {
                if (pi.PropertyType.IsPrimitive ||
                    pi.PropertyType.FullName.Contains("System.Int") ||
                    pi.PropertyType.FullName.Contains("System.DateTime") ||
                    pi.PropertyType.FullName.Contains("System.Decimal") ||
                    pi.PropertyType.FullName.Contains("System.Float") ||
                    pi.PropertyType.FullName.Contains("System.Double") ||
                    pi.PropertyType.FullName.Contains("System.String") ||
                    pi.PropertyType.FullName.Contains("System.Boolean") ||
                    pi.PropertyType.FullName.Contains("System.Byte") ||
                    pi.PropertyType.FullName.Contains("System.Guid"))
                {
                    if (pi.CanWrite)
                    {
                        var valueToAdd = pi.GetValue(this);

                        if (valueToAdd != null)
                        {
                            if (result == null)
                            {
                                result = new JObject();
                            }

                            if (pi.PropertyType.FullName.Contains("System.DateTime"))
                            {
                                var currentDate = DateTime.SpecifyKind((DateTime)pi.GetValue(this), DateTimeKind.Local);
                                result.Add(pi.Name, new JValue(currentDate));
                            }
                            else
                            {
                                result.Add(pi.Name, new JValue(valueToAdd));
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemple #2
0
        public override JObject Map(RestaurantDatabaseSettings ctx, bool customMap = true)
        {
            dynamic result = base.Map(ctx, customMap);

            if (customMap)
            {
                if (this.Product != null)
                {
                    result.Product = this.Product.Map(ctx, true);
                }
            }

            return(result);
        }
Exemple #3
0
        public override JObject Map(RestaurantDatabaseSettings ctx, bool customMap = true)
        {
            dynamic result = base.Map(ctx, customMap);

            if (customMap)
            {
                if (this.RecipeDetails != null)
                {
                    result.RecipeDetails = this.RecipeDetails.MapAll(ctx, true);
                }
            }

            return(result);
        }
        public static JArray MapAll <TEntity>(this IEnumerable <TEntity> items, RestaurantDatabaseSettings ctx, bool customMap = false) where TEntity : RestaurantTable
        {
            JArray result = null;

            if (items != null)
            {
                result = new JArray();
            }

            foreach (var item in items)
            {
                result.Add(item.Map(ctx: ctx, customMap: customMap));
            }

            return(result);
        }
Exemple #5
0
        public override JObject Map(RestaurantDatabaseSettings ctx, bool customMap = true)
        {
            dynamic result = base.Map(ctx, customMap);

            if (!string.IsNullOrWhiteSpace(this.Password))
            {
                result.Password = null;
            }

            if (customMap)
            {
                if (this.Role != null)
                {
                    result.Role = this.Role.Map(ctx, false);
                }
            }

            return(result);
        }
Exemple #6
0
        public override JObject Map(RestaurantDatabaseSettings ctx, bool customMap = true)
        {
            dynamic result = base.Map(ctx, customMap);

            if (customMap)
            {
                if (this.User != null)
                {
                    result.User = this.User.Map(ctx, false);
                }

                if (this.Table != null)
                {
                    result.Table = this.Table.Map(ctx, false);
                }
            }

            return(result);
        }
Exemple #7
0
        public override JObject Map(RestaurantDatabaseSettings ctx, bool customMap = false)
        {
            dynamic result = base.Map(ctx, customMap);

            if (customMap)
            {
                if (this.MeasurementUnit != null)
                {
                    result.MeasurementUnit = this.MeasurementUnit.Map(ctx, false);
                }

                if (this.Provider != null)
                {
                    result.Provider = this.Provider.Map(ctx, false);
                }

                if (this.ProductType != null)
                {
                    result.ProductType = this.ProductType.Map(ctx, false);
                }
            }

            return(result);
        }
        public override JObject Map(RestaurantDatabaseSettings ctx, bool customMap = true)
        {
            dynamic result = base.Map(ctx, customMap);

            if (customMap)
            {
                if (this.Provider != null)
                {
                    result.Provider = this.Provider.Map(ctx, true);
                }
                if (this.SupplyRequestDetails != null)
                {
                    result.SupplyRequestDetails = this.SupplyRequestDetails.MapAll(ctx, true);
                }
                if (this.State != null)
                {
                    result.State = this.State.Map(ctx, false);
                }

                result.SupplyRequestState = this.SupplyRequestState;
            }

            return(result);
        }