示例#1
0
        public void ChangeReference(ObjectReal objectReal, ReferenceObject referenceObject, bool bulk = false)
        {
            var filter = Builders <ObjectReal> .Filter.Eq(or => or.EPC, objectReal.EPC);

            var objects = ObjectsReal.Find(filter).ToList();

            if (objects.Count < 1)
            {
                return;
            }
            if (objects[0].objectReference == referenceObject.id.ToString())
            {
                return;
            }
            var update = Builders <ObjectReal> .Update
                         .Set(r => r.objectReference, referenceObject.id.ToString())
                         .Set(r => r.name, referenceObject.name)
                         .Set(r => r.marca, referenceObject.marca)
                         .Set(r => r.price, referenceObject.precio)
                         .Set(r2 => r2.LastmodDate, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));

            if (!bulk)
            {
                var result = ObjectsReal.UpdateOneAsync(filter, update);
                ObjectsReal = _database.GetCollection <ObjectReal>("ObjectReal");
            }
            else
            {
                BulkObjectsReal.Add(new UpdateOneModel <ObjectReal>(filter, update));
            }
        }
示例#2
0
        public void Insert(ReferenceObject referenceObject)
        {
            string objectId = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            var    result   = ReferenceObjects.Find(_ => true).SortByDescending(x => x.object_id).Limit(1).ToList();

            if (result.Count > 0)
            {
                objectId = (Convert.ToInt32(result[0].object_id) + 1).ToString();
            }
            referenceObject.object_id = objectId;
            ReferenceObjects.InsertOne(referenceObject);
        }
示例#3
0
        public void ChangeCategory(ReferenceObject referenceObject, Category category, bool bulk = false)
        {
            var filter = Builders <ReferenceObject> .Filter.Eq(reference => reference.id, referenceObject.id);

            var update = Builders <ReferenceObject> .Update
                         .Set(r => r.parentCategory, category.id.ToString())
                         .Set(r2 => r2.LastmodDate, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));

            if (!bulk)
            {
                var result = ReferenceObjects.UpdateOneAsync(filter, update);
                ReferenceObjects = _database.GetCollection <ReferenceObject>("ReferenceObjects");
            }
            else
            {
                BulkReferenceObjects.Add(new UpdateOneModel <ReferenceObject>(filter, update));
            }
        }
示例#4
0
        public void Remove(ReferenceObject referenceObject)
        {
            var filter = Builders <ReferenceObject> .Filter.Eq(or => or.id, referenceObject.id);

            var result = ReferenceObjects.DeleteOneAsync(filter);
        }