Exemple #1
0
        public Notice Enregistrer()
        {
            Notice notice = GetNotice();

            if (notice != null)
            {
                if (notice.exemplaires == null)
                {
                    notice.exemplaires = new List <Exemplaire>();
                }
                //if (notice.exemplaires.Count == 0)
                //    notice.exemplaires.Add(new Exemplaire() { _id = MongoDB.Bson.ObjectId.GenerateNewId(), codeBarre = notice.isbn, localisation = Properties.Settings.Default.Localisation });

                var coll = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Notice>("Notice");
                if (notice._id == ObjectId.Empty)
                {
                    coll.InsertOne(notice);
                }
                else
                {
                    coll.ReplaceOne(a => a._id == notice._id, notice, new ReplaceOptions()
                    {
                        IsUpsert = true
                    });
                }
                if (desherbages.Count > 0)
                {
                    var coll2 = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Desherbage>("Desherbage");
                    coll2.InsertMany(desherbages);
                    desherbages.Clear();
                }
            }
            return(notice);
        }