Exemple #1
0
        public virtual BsonDocument PreSave(BsonDocument doc, string[] references = null)
        {
            var tempId = doc.GetString("_id", "");

            if (tempId == "" || tempId == "0" || doc.Get("_id") == BsonNull.Value || tempId == null)
            {
                doc.Set("_id", SequenceNo.Get(this.TableName).ClaimAsInt());
            }
            return(doc);
        }
Exemple #2
0
        public static SequenceNo Get(string id)
        {
            var        q   = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", id);
            SequenceNo ret = DataHelper.Populate <SequenceNo>("SequenceNos", q).FirstOrDefault();

            if (ret == null)
            {
                ret = new SequenceNo
                {
                    _id    = id,
                    Title  = id,
                    NextNo = 1,
                    Format = ""
                };
            }
            return(ret);
        }
Exemple #3
0
        public int ClaimAsInt(bool commit = true)
        {
            int        ret = 0;
            var        q   = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", _id);
            SequenceNo sn  = DataHelper.Populate <SequenceNo>("SequenceNos", q).FirstOrDefault();

            if (sn != null)
            {
                NextNo = sn.NextNo;
            }
            ret = NextNo;
            if (commit)
            {
                this.NextNo++;
                DataHelper.Save("SequenceNos", new BsonDocument[] { this.ToBsonDocument() });
            }
            return(ret);
        }
Exemple #4
0
        public string ClaimAsString(string format = "", bool commit = true)
        {
            string ret = "";
            var    q   = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", _id);

            SequenceNo sn = DataHelper.Populate <SequenceNo>("SequenceNos", q).FirstOrDefault();

            if (sn != null)
            {
                NextNo = sn.NextNo;
            }
            if (String.IsNullOrEmpty(format))
            {
                format = Format;
            }
            ret = (format.Equals("")) ? NextNo.ToString() :
                  String.Format(format, NextNo);
            if (commit)
            {
                this.NextNo++;
                DataHelper.Save("SequenceNos", new BsonDocument[] { this.ToBsonDocument() });
            }
            return(ret);
        }