public DynamicParameters GetPrimaryKeyParameters(BusinessBase obj)
        {
            DynamicParameters dynParms = new DynamicParameters();

            foreach (int pos in PrimaryKeys)
            {
                dynParms.Add("@" + names[pos], obj[pos]);
            }

            return(dynParms);
        }
        public async Task <BusinessBase> RetreiveObject(ContextProvider contextProvider, string objectName, int dbNumber, string key)
        {
            string       objectKey = ObjectKey(objectName, dbNumber, key);
            BusinessBase objResp   = await Task.Run(() =>
            {
                return(contextProvider.BusinessItems.GetOrAdd(objectKey, (theKey) =>
                                                              Get(contextProvider, objectName, dbNumber, key, objectKey).Result));
            });

            return(objResp);
        }
        public virtual DataItem New(BusinessBase owner)
        {
            object[] values = new object[ListProperties.Count];

            foreach (PropertyDefinition prop in ListProperties)
            {
                values[prop.Index] = prop.DefaultValue;
            }

            return(new DataItem(owner, values));
        }
 public virtual void CopyTo(BusinessBase Target, List <string> excludeFieldNames)
 {
     foreach (PropertyDefinition prop in Decorator.ListProperties)
     {
         if (!prop.IsReadOnly &&
             !prop.IsPrimaryKey &&
             (excludeFieldNames == null || (excludeFieldNames != null &&
                                            !excludeFieldNames.Contains(prop.FieldName))))
         {
             Target[prop.FieldName] = this[prop.FieldName];
         }
     }
 }
        public bool MoveNext()
        {
            bool found = false;

            pos++;
            while (pos < _col.Count)
            {
                actual = _col[pos];
                if (actual.MatchFilter(_filterName))
                {
                    found = true;
                    break;
                }
                pos++;
            }

            return(found);
        }
        public virtual void FromJObject(JObject obj)
        {
            readed = obj["r"].ToObject(typeof(string)).ToString() == "1";

            if (readed)
            {
                int count = (int)obj["c"].ToObject(typeof(int));

                for (int index = 0; index < count; ++index)
                {
                    BusinessBase item = CreateNewChild();

                    item.FromJObject((JObject)obj["i" + index]);
                    item.Parent = this;

                    list.Add(item);
                }
            }
        }
        private async Task <BusinessBase> Get(ContextProvider contextProvider, string objectName, int dbNumber, string key, string objectKey)
        {
            byte[]       data;
            bool         readFromDB = true;
            BusinessBase obj        = CreateObject(contextProvider, objectName, dbNumber);

            data = await GetData(objectKey);

            if (data != null)
            {
                try
                {
                    obj.Deserialize(data);
                    readFromDB = false;
                }
                catch
                {
                    // Sometimes Redis returns bad data.
                }
            }
            if (readFromDB)
            {
                if (key != "0" && key[0] != '-')
                {
                    await obj.ReadFromDB(key);
                }
                else
                {
                    if (!obj.IsNew)
                    {
                        await obj.SetNew();

                        objectKey = obj.Key;
                    }
                }

                await StoreObject(obj, objectName);
            }

            return(obj);
        }
Ejemplo n.º 8
0
        public async Task SetValue(BusinessBase obj, string value)
        {
            if (obj.IsReadOnly(FieldName) || value == null)
            {
                return;
            }

            if (BasicType == BasicType.Text || BasicType == BasicType.TextLong)
            {
                value = value.NoNullString().Trim();

                if (IsNullable && (value == "" || (value == "0" && Type == PropertyInputType.select)))
                {
                    // strings as IDs !!! :)
                    if (!(obj[FieldName] == null))
                    {
                        obj[FieldName] = null;
                    }
                }
                else
                {
                    if (obj[FieldName].NoNullString() != value)
                    {
                        obj[FieldName] = value;
                    }
                }
            }

            else if (Type == PropertyInputType.checkbox || BasicType == BasicType.Bit)
            {
                if (obj[FieldName].NoNullBool() != (value == "1"))
                {
                    obj[FieldName] = (value == "1");
                }
            }

            else if (Type == PropertyInputType.datetimeHHmm || Type == PropertyInputType.datetimeHHmmss || Type == PropertyInputType.date)
            {
                try
                {
                    if (value != "")
                    {
                        AppUser us = await obj.CurrentUser();

                        DateTime d;
                        string   _format = "yyyy/MM/dd";

                        if (Type == PropertyInputType.datetimeHHmm)
                        {
                            _format += " HH:mm";
                        }
                        else if (Type == PropertyInputType.datetimeHHmmss)
                        {
                            _format += " HH:mm:ss";
                        }

                        try
                        {
                            d = DateTime.ParseExact(value, _format, us.Culture);
                        }
                        catch
                        {
                            d = DateTime.Parse(value, us.Culture);
                        }

                        if (obj[FieldName] == null)
                        {
                            obj[FieldName] = d;
                        }
                        else
                        {
                            if ((DateTime)obj[FieldName] != d)
                            {
                                obj[FieldName] = d;
                            }
                        }
                    }
                    else
                    {
                        if (!(obj[FieldName] == null))
                        {
                            obj[FieldName] = null;
                        }
                    }
                }
                catch
                {
                    if (!(obj[FieldName] == null))
                    {
                        obj[FieldName] = null;
                    }
                }
            }

            else if (BasicType == BasicType.GUID)
            {
                Guid newGuid = Guid.Empty;

                try
                {
                    newGuid = Guid.Parse(value.ToString());
                    if ((Guid)obj[FieldName] != newGuid)
                    {
                        obj[FieldName] = newGuid;
                    }
                }
                catch
                {
                }
            }

            else if (BasicType == BasicType.Number)
            {
                try
                {
                    Lib.Numerize(ref value);

                    if (obj[FieldName] == null && !IsNullable)
                    {
                        obj[FieldName] = 0;
                    }

                    if (IsNullable && (value == "" || (value == "0" && Type == PropertyInputType.select)))
                    {
                        if (!(obj[FieldName] == null))
                        {
                            obj[FieldName] = null;
                        }
                    }
                    else
                    {
                        //value = value.NoNullDouble().ToString();

                        try
                        {
                            if (Double.Parse(value) == 0)
                            {
                                value = "0";
                            }
                        }
                        catch
                        {
                            value = "0";
                        }
                        if (obj[FieldName] == null && value != "")
                        {
                            obj[FieldName] = 0;
                        }

                        if (DataType == typeof(System.Int32))
                        {
                            int tmp = Int32.Parse(value);

                            if ((int)obj[FieldName] != tmp)
                            {
                                obj[FieldName] = tmp;
                            }
                        }
                        if (DataType == typeof(System.Int64))
                        {
                            long tmp = Int32.Parse(value);

                            if ((long)obj[FieldName] != tmp)
                            {
                                obj[FieldName] = tmp;
                            }
                        }
                        else if (DataType == typeof(System.Int16))
                        {
                            short tmp = Int16.Parse(value);

                            if ((short)obj[FieldName] != tmp)
                            {
                                obj[FieldName] = tmp;
                            }
                        }
                        if (DataType == typeof(System.Single))
                        {
                            Single tmp = Single.Parse(value);

                            if ((float)obj[FieldName] != tmp)
                            {
                                obj[FieldName] = tmp;
                            }
                        }
                        if (DataType == typeof(System.Double))
                        {
                            Double tmp = Double.Parse(value);

                            if ((double)obj[FieldName] != tmp)
                            {
                                obj[FieldName] = tmp;
                            }
                        }
                        if (DataType == typeof(System.Decimal))
                        {
                            Decimal tmp = Decimal.Parse(value);

                            if ((decimal)obj[FieldName] != tmp)
                            {
                                obj[FieldName] = tmp;
                            }
                        }
                    }
                }
                catch
                {
                    //Invalid user input
                    //value = "0";
                    //obj[PropertyName] = 0;
                }
            }
        }
Ejemplo n.º 9
0
        public async Task <string> GetValue(BusinessBase obj)
        {
            string value = "";

            if (Type == PropertyInputType.date)
            {
                if (!(obj[FieldName] == null))
                {
                    if (obj.IsReadOnly(FieldName))
                    {
                        value = String.Format(Format, (DateTime)obj[FieldName]);
                    }
                    else
                    {
                        value = ((DateTime)obj[FieldName]).ToString("yyyy/MM/dd");
                    }
                }
            }
            else if (Type == PropertyInputType.datetimeHHmm)
            {
                if (!(obj[FieldName] == null))
                {
                    if (obj.IsReadOnly(FieldName))
                    {
                        value = String.Format(Format, (DateTime)obj[FieldName]);
                    }
                    else
                    {
                        value = ((DateTime)obj[FieldName]).ToString("yyyy/MM/dd HH:mm");
                    }
                }
            }
            else if (Type == PropertyInputType.datetimeHHmmss)
            {
                if (!(obj[FieldName] == null))
                {
                    if (obj.IsReadOnly(FieldName))
                    {
                        value = String.Format(Format, (DateTime)obj[FieldName]);
                    }
                    else
                    {
                        value = ((DateTime)obj[FieldName]).ToString("yyyy/MM/dd HH:mm:ss");
                    }
                }
            }
            else if (Type == PropertyInputType.checkbox || BasicType == BasicType.Bit)
            {
                value = obj[FieldName].NoNullBool() ? "1" : "0";
            }
            else if (Type == PropertyInputType.select)
            {
                if (obj[FieldName] == null)
                {
                    value = "0";
                }
                else
                {
                    value = obj[FieldName].ToString();
                }

                if (Required && value == "0" && !IsObjectView)
                {
                    // First element
                    ListTable dt = await obj.BusinessProvider.ListProvider.GetList(obj.ContextProvider, ListObjectName, ListName);

                    if (dt.ToClient.Count > 0)
                    {
                        value = dt.First[0].ToString();
                    }
                }
            }
            else
            {
                if (Format != "")
                {
                    value = String.Format(Format, obj[FieldName]);
                }
                else
                {
                    value = obj[FieldName].NoNullString();
                }
            }

            return(value);
        }
 public void Reset()
 {
     actual = null;
     pos    = -1;
 }
Ejemplo n.º 11
0
        public async Task StoreObject(BusinessBase obj, string objectName)
        {
            string objectKey = ObjectKey(objectName, obj.Decorator.DBNumber, obj.Key);

            await StoreData(objectKey, obj.Serialize());
        }
Ejemplo n.º 12
0
 public DataItem(BusinessBase owner, object[] values)
 {
     this.owner  = owner;
     this.values = values;
 }
 public virtual void SetPropertiesFrom(BusinessBase source)
 {
 }