Example #1
0
 private void btnSupprimerExeplaire_Click(object sender, EventArgs e)
 {
     if (dgvExemplaires.SelectedRows.Count > 0)
     {
         if (MessageBox.Show("Confirmez-vous la suppression de cet exemplaire?", "Suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
         {
             MongoDB.Bson.ObjectId id = MongoDB.Bson.ObjectId.Parse(dgvExemplaires.SelectedRows[0].Cells["id"].Value.ToString());
             Notice notice            = GetNotice();
             if (notice.exemplaires == null)
             {
                 notice.exemplaires = new List <Exemplaire>();
             }
             var ex = notice.exemplaires.Find(a => a._id == id);
             notice.exemplaires.Remove(ex);
             RemplirExemplaires(notice);
             desherbages.Add(new Desherbage()
             {
                 idNotice  = notice._id,
                 auteur    = notice.auteur,
                 codeBarre = ex.codeBarre,
                 cote      = ex.cote,
                 dt        = DateTime.Now,
                 titre     = notice.titre,
             });
         }
     }
 }
Example #2
0
        CartItems GetCartItems()
        {
            CartItems results = new CartItems();

            try {
                var userId = Request.Cookies["cart"].Value;

                if (string.IsNullOrEmpty(userId))
                {
                    return(results);
                }

                var cartsCollection = Database.GetCollection <UserCart>("Carts");
                var cart            = cartsCollection.Find(x => x.UserId == userId).FirstOrDefault();

                if (cart == null)
                {
                    return(results);
                }

                foreach (var itemId in cart.Items)
                {
                    ObjectId obj = new MongoDB.Bson.ObjectId(itemId);
                    //   var results = _collection.Find(x => x.Name != "").ToList();
                    Thingy thing = _collection.Find(x => x.Id == obj).FirstOrDefault();
                    if (thing != null)
                    {
                        results.Add(thing);
                    }
                }
            }
            catch { }
            results.Items.Sort((x, y) => string.Compare(x.Thing.Name, y.Thing.Name));
            return(results);
        }
Example #3
0
 private void dgvExemplaires_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dgvExemplaires.SelectedRows.Count > 0)
     {
         Notice notice = GetNotice();
         if (notice.exemplaires == null)
         {
             notice.exemplaires = new List <Exemplaire>();
         }
         using (var frm = new frmrExemplaire()
         {
             Text = "Modifier un exemplaire"
         })
         {
             MongoDB.Bson.ObjectId id = MongoDB.Bson.ObjectId.Parse(dgvExemplaires.SelectedRows[0].Cells["id"].Value.ToString());
             frm.SetExemplaire(notice.exemplaires.Find(a => a._id == id));
             if (frm.ShowDialog() == DialogResult.OK)
             {
                 notice.exemplaires.Remove(notice.exemplaires.Find(a => a._id == id));
                 notice.exemplaires.Add(frm.GetExemplaire());
                 RemplirExemplaires(notice);
             }
         }
     }
 }
        public ActionResult Remove(string id)
        {
            var      things = _collection.Find(x => x.Name != null && x.Name != "").ToList();
            ObjectId obj    = new MongoDB.Bson.ObjectId(id);

            _collection.DeleteOne(x => x.Id == obj);

            return(RedirectToAction("index", "manage"));
        }
        public ActionResult Edit(string id)
        {
            //   var things = _collection.Find(x => x.Name != null && x.Name != "").ToList();
            ImagesToAdd.Clear();
            ObjectId obj   = new MongoDB.Bson.ObjectId(id);
            var      thing = _collection.Find(x => x.Id == obj).First();

            return(View(thing));
        }
Example #6
0
 public virtual void Delete(MongoDB.Bson.ObjectId id)
 {
     try
     {
         this.collection.Remove(Query.EQ("_id", id));
     }
     catch (Exception ex)
     {
         MongoCoreExtentions.OnError?.BeginInvoke(this.collection?.Database?.Server?.Settings?.ToString(), ex, null, null);
     }
 }
        public void UpsertRecord <T>(string table, MongoDB.Bson.ObjectId Id, T record)
        {
            var collection = db.GetCollection <T>(table);

            var result = collection.ReplaceOne(
                new BsonDocument("_id", Id),
                record,
                new ReplaceOptions {
                IsUpsert = true
            });
        }
Example #8
0
 public virtual T GetById(MongoDB.Bson.ObjectId id)
 {
     try
     {
         return(this.collection.FindOneByIdAs <T>(id));
     }
     catch (Exception ex)
     {
         MongoCoreExtentions.OnError?.BeginInvoke(this.collection?.Database?.Server?.Settings?.ToString(), ex, null, null);
     }
     return(default(T));
 }
Example #9
0
        public ActionResult Item(string id)
        {
            ObjectId obj = new MongoDB.Bson.ObjectId(id);
            //   var results = _collection.Find(x => x.Name != "").ToList();
            var result = _collection.Find(x => x.Id == obj).FirstOrDefault();

            if (result != null)
            {
                return(View(result));
            }
            return(RedirectToAction("Index"));
        }
Example #10
0
        public static async Task <T> LookupById <T>(string collectionName, MongoDB.Bson.ObjectId idToLookup) where T : IMongoIdentifiable
        {
            var collection = LookupCollectionFromDb <T>(collectionName);
            var cursor     = await collection.FindAsync <T>(x => x._id == idToLookup);

            if (cursor == null)
            {
                return(default(T));
            }

            T match = cursor.First();

            return(match);
        }
        //[HttpPost]
        public ActionResult AddPlace(string id)
        {
            var user =  db.GetUser(User.Identity.Name);
               var obj = user.listOfFavouriteObjects;
            if (obj == null)
                obj = new List<ObjectId>();
            MongoDB.Bson.ObjectId newObjectId = new MongoDB.Bson.ObjectId(id);
            if (!obj.Contains(newObjectId))
            {
                obj.Add(new MongoDB.Bson.ObjectId(id));
                db.UpdateFavPlaces(User.Identity.Name, obj);
            }

            return RedirectToAction("UserInfo", new { userEmail = user.email });
        }
        public ActionResult RemovePlace(string objectId)
        {
            var user = db.GetUser(User.Identity.Name);
            var obj  = user.listOfFavouriteObjects;

            if (obj == null)
            {
                return(RedirectToAction("UserInfo", new { userEmail = user.email }));
            }
            MongoDB.Bson.ObjectId newObjectId = new MongoDB.Bson.ObjectId(objectId);
            if (obj.Contains(newObjectId))
            {
                obj.Remove(new MongoDB.Bson.ObjectId(objectId));
                db.UpdateFavPlaces(User.Identity.Name, obj);
            }
            return(RedirectToAction("UserInfo", new { userEmail = user.email }));
        }
Example #13
0
 public bool LocalDelete(MongoDB.Bson.ObjectId id)
 {
     try
     {
         int r;
         using (var db = new LiteDatabase(dbName))
         {
             var collection = db.GetCollection <T>(tableName);
             r = collection.Delete(e => e.Id == id);
         }
         return(r > 0);
     }
     catch (Exception)
     {
         Error = "Error de eliminar local";
         return(false);
     }
 }
Example #14
0
 public bool Delete(MongoDB.Bson.ObjectId id, bool local)
 {
     try
     {
         if (local)
         {
             Resultado = LocalDelete(id);
         }
         else
         {
             Resultado = Collection().DeleteOne(e => e.Id == id).DeletedCount == 1;
         }
         Error = null;
     }
     catch (Exception)
     {
         Resultado = false;
         Error     = "No se pudo eliminar " + typeof(T).Name;
     }
     return(Resultado);
 }
        public void SetMovieWatchedStatus(string movieId, bool isSetToWatched)
        {
            var signedInUser = GetSignedInUser();

            if(signedInUser == null)
            {
                return;
            }

            var provider = new Provider.MongoDbProvider();
            var movieObjId = new MongoDB.Bson.ObjectId(movieId);
            
            if (isSetToWatched)
            {
                provider.AddSeenMovieToUser(movieObjId, signedInUser.Id);
            }
            else
            {
                provider.RemoveSeenMovieFromUser(movieObjId, signedInUser.Id);
            }
        }
Example #16
0
        public void EmitStart()
        {
            var document = new BsonDocument
            {
                { "Type", "ACTIVITY" },
                { "ActivityType", _type.ToString() },
                { "StartTime", _startTime },
                { "StartDetails", _startDetails },
            };

            ActivityMonitor.ActivitiesCollection.InsertOne(document);
            _objectId = (ObjectId)document.GetValue("_id");

            string msg = string.Format("log4net: START: _activity: {0} ({1})", _type.ToString(), _objectId.ToString());

            if (_startDetails != string.Empty)
            {
                msg += string.Format(", details: {0}", _startDetails);
            }

            debugger.WriteLine(Debugger.DebugLevel.DebugLogic, msg);
        }
Example #17
0
        public FileResult GetImage(string id)
        {
            var folder = AppDomain.CurrentDomain.GetData("DataDirectory") + @"\pictures\";

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            var path = Path.Combine(folder, id + ".jpg"); //validate the path for security or use other means to generate the path.

            ObjectId objId = new MongoDB.Bson.ObjectId(id);
            var      thing = DbLayer.GetEntity("Thingies", objId);

            if (thing != null)
            {
                MemoryStream ms    = new MemoryStream(thing.Images[0]);
                var          image = Image.FromStream(ms);
                image.Save(path);
            }
            return(base.File(path, "image/jpeg"));
        }
Example #18
0
 public async Task <OrderModel> GetByIdAsync(MongoDB.Bson.ObjectId id)
 {
     throw new NotImplementedException();
 }
 public Clientes(MongoDB.Bson.ObjectId id, string Nome)
 {
     this.Id   = id;
     this.Nome = Nome;
 }
Example #20
0
        public static T FindOneByIdAs <T>(string connectionName, string database, string collection, string id)
        {
            var _id = new MongoDB.Bson.ObjectId(id);

            return(FindOne <T>(connectionName, database, collection, new MongoQueryWarpper().EQ("_id", _id), null, null));
        }
Example #21
0
        public async void Save() {
            if (Id == null) {
                Id = new MongoDB.Bson.ObjectId();
            }; //new character
            var characterCollection = MongoUtils.MongoData.GetCollection<NPC>("Characters", "NPCCharacters");

            await MongoUtils.MongoData.SaveAsync<NPC>(characterCollection, n => n.Id == Id, this);  //upsert

            //if (npcCharacter == null) {
            //    //this is the NPC's first save, create everything from scratch
            //    npcCharacter = new NPC {
            //        FirstName = this.FirstName,
            //        LastName = this.LastName,
            //        _race = this._race,
            //        _class = this._class,
            //        _gender = this._gender,
            //        _skinColor = this._skinColor,
            //        _skinType = this._skinType,
            //        _hairColor = this._hairColor,
            //        _eyeColor = this._eyeColor,
            //        Weight = this.Weight,
            //        Height = this.Height,
            //        _actionState = this._actionState,
            //        _stanceState = this._stanceState,
            //        Description = this.Description,
            //        Location = this.Location,
            //        AiState = Fsm.state.ToString(),
            //        PreviousState = Fsm.previousState != null ? Fsm.previousState.ToString() : "",
            //        GlobalState = Fsm.globalState != null ? Fsm.globalState.ToString() : "",
            //        NextAiAction = this.NextAiAction.ToUniversalTime(),
            //        IsNPC = this.IsNPC,
            //        MobTypeID = this.MobTypeID,
            //        CurrentTarget = this.CurrentTarget != null ? this.CurrentTarget.ToString() : "",
            //        LastTarget = this.LastTarget != null ? this.LastTarget.ToString() : "",
            //        InCombat = this.InCombat,
            //        LastCombatTime = this.LastCombatTime,
            //        Experience = this.Experience,
            //        Level = this.Level,
            //        KillerID = this.KillerID,
            //        Title = this.Title

                    //BsonArray attributeList = new BsonArray();

                    //foreach (Attribute a in this.Attributes.Values) {
                    //	BsonDocument attributes = new BsonDocument();
                    //	attributes.Add("Name", a.Name);
                    //	attributes.Add("Value", a.Value);
                    //	attributes.Add("Max", a.Max);
                    //	attributes.Add("RegenRate", a.RegenRate);

                    //	attributeList.Add(attributes);
                    //}
                    //npcCharacter.Add("Attributes", attributeList);

                    //BsonArray xpTracker = new BsonArray();

                    //foreach (KeyValuePair<string, double> tracker in damageTracker) {
                    //	BsonDocument track = new BsonDocument();
                    //	track.Add("ID", tracker.Key);
                    //	track.Add("Value", tracker.Value);

                    //	xpTracker.Add(track);
                    //}

                    //BsonArray questIds = new BsonArray();
                    //foreach (var quest in Quests) {
                    //	BsonDocument questDoc = new BsonDocument();
                    //	questDoc.Add("QuestID", quest.QuestID);
                    //	BsonArray playerSteps = new BsonArray();
                    //	foreach (var playerStep in quest.CurrentPlayerStep) {
                    //		BsonDocument step = new BsonDocument();
                    //		step.Add("PlayerID", playerStep.Key);
                    //		step.Add("Step", playerStep.Value);
                    //		playerSteps.Add(step);
                    //	}
                    //	BsonArray autoProcess = new BsonArray();
                    //	foreach (string playerStep in quest.AutoProcessPlayer) {
                    //		autoProcess.Add(BsonValue.Create(playerStep));
                    //	}

                    //	questDoc.Add("AutoPlayers", autoProcess);
                    //	questDoc.Add("PlayersIDs", playerSteps);
                    //	questIds.Add(questDoc);
                    //}

                    //npcCharacter.Add("QuestIds", questIds);

                    //npcCharacter.Add("XpTracker", xpTracker);

                    //npcCharacter.Add("Bonuses", Bonuses.GetBson());
            //    };
            //} else {
            //    npcCharacter["FirstName"] = this.FirstName;
            //    npcCharacter["LastName"] = this.LastName;
            //    npcCharacter["Race"] = this.Race;
            //    npcCharacter["Class"] = this.Class;
            //    npcCharacter["Gender"] = this.Gender.CamelCaseWord();
            //    npcCharacter["SkinColor"] = this.SkinColor.CamelCaseWord();
            //    npcCharacter["SkinType"] = this.SkinType.CamelCaseWord();
            //    npcCharacter["HairColor"] = this.HairColor.CamelCaseWord();
            //    npcCharacter["EyeColor"] = this.EyeColor.CamelCaseWord();
            //    npcCharacter["Weight"] = this.Weight;
            //    npcCharacter["Height"] = this.Height;
            //    npcCharacter["Description"] = this.Description;
            //    npcCharacter["Location"] = this.Location;
            //    npcCharacter["ActionState"] = this.ActionState.ToString().CamelCaseWord();
            //    npcCharacter["StanceState"] = this.StanceState.ToString().CamelCaseWord();
            //    npcCharacter["AiState"] = Fsm.state != null ? Fsm.state.ToString() : "None";
            //    npcCharacter["previousAiState"] = Fsm.previousState == null ? "" : Fsm.previousState.ToString();
            //    npcCharacter["AiGlobalState"] = Fsm.globalState == null ? "" : Fsm.globalState.ToString();
            //    npcCharacter["NextAiAction"] = this.NextAiAction.ToUniversalTime();
            //    npcCharacter["MobTypeID"] = this.MobTypeID;
            //    npcCharacter["IsNPC"] = this.IsNPC;
            //    npcCharacter["CurrentTarget"] = this.CurrentTarget == null ? "" : this.CurrentTarget;
            //    npcCharacter["LastTarget"] = this.LastTarget == null ? "" : this.LastTarget;
            //    npcCharacter["InCombat"] = this.InCombat;
            //    npcCharacter["LastCombatTime"] = this.LastCombatTime;
            //    npcCharacter["Experience"] = this.Experience;
            //    npcCharacter["Level"] = this.Level;
            //    npcCharacter["KillerID"] = this.KillerID;
            //    npcCharacter["Title"] = this.Title;

            //    BsonArray playerAttributes = new BsonArray();
            //    BsonArray xpTracker = new BsonArray();

            //    foreach (KeyValuePair<string, IAttributes> attribute in Attributes) {
            //        BsonDocument attrib = new BsonDocument();
            //        attrib.Add("Name", "");
            //        attrib.Add("Value", "");
            //        attrib.Add("Max", "");
            //        attrib.Add("RegenRate", "");


            //        attrib["Name"] = attribute.Key;
            //        attrib["Value"] = attribute.Value.Value;
            //        attrib["Max"] = attribute.Value.Max;
            //        attrib["RegenRate"] = attribute.Value.RegenRate;

            //        playerAttributes.Add(attrib);
            //    }

            //    npcCharacter["Attributes"] = playerAttributes;

            //    foreach (KeyValuePair<string, double> tracker in damageTracker) {
            //        BsonDocument track = new BsonDocument();
            //        track.Add("ID", "");
            //        track.Add("Value", 0.0d);

            //        track["ID"] = tracker.Key;
            //        track["Value"] = tracker.Value;

            //        xpTracker.Add(track);
            //    }

            //    BsonArray questIds = new BsonArray();
            //    foreach (var quest in Quests) {
            //        BsonDocument questDoc = new BsonDocument();
            //        questDoc.Add("QuestID", quest.QuestID);
            //        BsonArray playerSteps = new BsonArray();

            //        foreach (var playerStep in quest.CurrentPlayerStep) {
            //            BsonDocument step = new BsonDocument();
            //            step.Add("PlayerID", playerStep.Key);
            //            step.Add("Step", playerStep.Value);
            //            playerSteps.Add(step);
            //        }

            //        BsonArray autoProcess = new BsonArray();
            //        foreach (string playerStep in quest.AutoProcessPlayer) {
            //            autoProcess.Add(BsonValue.Create(playerStep));
            //        }

            //        questDoc.Add("AutoPlayers", autoProcess);
            //        questDoc.Add("PlayerIDs", playerSteps);
            //        questIds.Add(questDoc);
            //    }

            //    npcCharacter["QuestIds"] = questIds;

            //    npcCharacter["XpTracker"] = xpTracker;

            //    npcCharacter["Bonuses"] = Bonuses.GetBson();
            //}

            //characterCollection.Save(npcCharacter);

            //if (this.ID == "000000000000000000000000") {
            //    this.ID = npcCharacter["_id"].AsObjectId.ToString();
            //}
        }
Example #22
0
 public BaseEntity()
 {
     this._id = ObjectId.GenerateNewId();
 }
Example #23
0
 public void Save(T_CollectionType _Item, MongoDB.Bson.ObjectId _ID)
 {
     _Item.Id = _ID;
 }