private void showData() { MongoDatabase database = MongoService.getDatabase(); var collection = database.GetCollection <Animal>("Animals"); var universityCollection = database.GetCollection <University>("University"); var query1 = from University in universityCollection.AsQueryable <University>() where University.Name == university select University; u = query1.First(); list.Items.Clear(); foreach (MongoDBRef tmpRef in u.generatedData) { Animal tmp = database.FetchDBRefAs <Animal>(tmpRef); Topic t = database.FetchDBRefAs <Topic>(tmp.topic); list.Items.Add((list.Items.Count + 1) + ". " + tmp.name + ", date: " + tmp.date + " - topic:" + t.name); } }
public void UpdateWinnings(string username, int winnings, Hand hand) { var u = (from user in UserCollection.AsQueryable <User>() where user.username == username select user).Single(); Hand newBestHand = new Hand(); foreach (var card in hand.cards) { List <Card> cards = new List <Card>(); cards.Add(card.Value[0]); cards.Add(card.Value[1]); newBestHand.cards.Add(card.Key, cards); } foreach (var user in hand.username) { newBestHand.username.Add(user.Key, user.Value); } foreach (var move in hand.moves) { Move m = new Move(); m.moveType = move.moveType; m.option = move.option; m.position = move.position; newBestHand.moves.Add(m); } foreach (var card in hand.dealtCards) { Card c = new Card(); c.number = card.number; c.sign = card.sign; newBestHand.dealtCards.Add(c); } if (u.bestHand != null) { Hand oldHand = dataBase.FetchDBRefAs <Hand>(u.bestHand); var fil = Builders <Hand> .Filter.Eq("id", oldHand.id); HandCollection.DeleteOne(fil); } HandCollection.InsertOne(newBestHand); var filter = Builders <User> .Filter.Eq("username", username); var update = Builders <User> .Update.Set("bestHand", new MongoDBRef("Hand", newBestHand.id)).Set("bestWinnings", winnings); UserCollection.UpdateOneAsync(filter, update); }
void IDbRef.LoadRef(MongoDatabase mongoDatabase) { if (Object == null) { Object = mongoDatabase.FetchDBRefAs <T>(this); } }
private void comboProp_SelectedIndexChanged(object sender, EventArgs e) { MongoDatabase database = MongoService.getDatabase(); Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]); lblName.Text = animal.name; lblDate.Text = animal.date.ToShortDateString(); textPropName.Text = animal.properties[comboProp.SelectedIndex].Name; textPropValue.Text = animal.properties[comboProp.SelectedIndex].Value; }
public List <Izvestaj> getIzvestajiPrestupnik(string lk) { List <Izvestaj> lista = new List <Izvestaj>(); var collection = db.GetCollection <Izvestaj>("izvestaji"); Prestupnik p = getPrestupnik(lk); foreach (MongoDBRef iz in p.Izvestaji) { Izvestaj izvestaj = db.FetchDBRefAs <Izvestaj>(iz); lista.Add(izvestaj); } return(lista); }
// Returns a list of Characters of given Profile public List <Character> GetCharacters(Profile profile) { MongoDatabase db = MongoConnection(); var collection = db.GetCollection <Character>("characters"); List <Character> characters = new List <Character>(); foreach (MongoDBRef characterRef in profile.characterRefs) { Character character = db.FetchDBRefAs <Character>(characterRef); characters.Add(character); } return(characters); }
private void list_MouseClick(object sender, MouseEventArgs e) { if (list.SelectedItem == null) { return; } MongoDatabase database = MongoService.getDatabase(); Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]); lblName.Text = animal.name; lblDate.Text = animal.date.ToShortDateString(); addComboData(animal); }
private void btnDelete_Click(object sender, EventArgs e) { MongoDatabase database = MongoService.getDatabase(); var collection = database.GetCollection <Animal>("Animals"); var UniversityCollection = database.GetCollection <University>("University"); MongoDBRef animalRef = u.generatedData[list.SelectedIndex]; Animal animal = database.FetchDBRefAs <Animal>(animalRef); u.generatedData.RemoveAt(list.SelectedIndex); UniversityCollection.Save(u); collection.Remove(Query.EQ("_id", animal.Id)); showData(); }
private void btnAddProp_Click(object sender, EventArgs e) { if (textPropName.TextLength < 1 || textPropValue.TextLength < 1) { MessageBox.Show("Enter property"); return; } MongoDatabase database = MongoService.getDatabase(); var collection = database.GetCollection <Animal>("Animals"); Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]); animal.properties.Add(new Property { Name = textPropName.Text, Value = textPropValue.Text }); collection.Save(animal); addComboData(animal); }
private void showData() { MongoDatabase database = MongoService.getDatabase(); var collection = database.GetCollection <Animal>("Animals"); var topicCollection = database.GetCollection <Topic>("Topics"); var query1 = from Topics in topicCollection.AsQueryable <Topic>() where Topics.name == topic select Topics; t = query1.First(); //var query = from Animals in collection.AsQueryable<Animal>() // where Animals.properties // select Animals; //foreach(Animal a in query) //{ // MessageBox.Show(a.name); //} //list.Items.Clear(); List <Animal> lista = new List <Animal>(); List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ("topic.$id", t.Id)); foreach (Animal tmp in collection.Find(Query.And(queries))) { Topic t = database.FetchDBRefAs <Topic>(tmp.topic); lista.Add(tmp); } list.DataSource = lista; list.DisplayMember = "name"; list.ValueMember = "Id"; }
private void btnSave_Click(object sender, EventArgs e) { MongoDatabase database = MongoService.getDatabase(); var collection = database.GetCollection <Animal>("Animals"); Animal animal = database.FetchDBRefAs <Animal>(u.generatedData[list.SelectedIndex]); if (textName.TextLength > 0) { animal.name = textName.Text; } animal.date = dateTime.Value; if (textPropName.TextLength > 0 && textPropValue.TextLength > 0) { animal.properties[comboProp.SelectedIndex].Name = textPropName.Text; animal.properties[comboProp.SelectedIndex].Value = textPropValue.Text; } collection.Save(animal); clearAll(); showData(); }
public TDocument FetchDBRefAs <TDocument>(MongoDBRef dbRef) { return(_mongoDatabase.FetchDBRefAs <TDocument>(dbRef)); }
private void getUniversity() { MongoDatabase database = MongoService.getDatabase(); university = database.FetchDBRefAs <University>(logedUser.university); }