public string UpdateDocument(AdminData adminData) { try { MongoDatabase myDB = GetDB(); MongoCollection <AdminData> adminDataTable = myDB.GetCollection <AdminData>("AdminData"); QueryDocument queryDoc = new QueryDocument("_id", adminData._id); IMongoQuery query = queryDoc; // IMongoUpdate update = new UpdateDocument("Address","Hyd"); // IMongoUpdate update = new UpdateDocument().Set("Address", "Hyd") as UpdateDocument; // IMongoUpdate update = new UpdateDocument().Set(queryDoc.IndexOfName("Address"), "Hyd") as UpdateDocument; var updateDoc = Update.Set("Address", adminData.Address).Set("Age", adminData.Age.ToString()).Set("Name", adminData.Name).Set("SlNo", adminData.SlNo.ToString()); IMongoUpdate update = updateDoc; WriteConcernResult updateResult = adminDataTable.Update(query, update); return("Succcess"); // adminDataTable.Update() // GetCollection(); } catch (Exception ex) { throw; } }
private void UpdateDoc() { AdminData admindata = grdcAdminData.GetFocusedRow() as AdminData; if (!string.IsNullOrEmpty(repo.UpdateDocument(admindata))) { GetDocs(); } }
private void DeleteDoc() { AdminData recordToDelete = grdcAdminData.GetFocusedRow() as AdminData; if (!string.IsNullOrEmpty(repo.DeleteDocument(recordToDelete._id))) { GetDocs(); } }
public string InsertDocument(AdminData adminData) { try { MongoDatabase myDB = GetDB(); MongoCollection <AdminData> adminDataTable = myDB.GetCollection <AdminData>("AdminData"); adminDataTable.Insert(adminData); return("Succcess"); } catch (Exception ex) { throw; } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { AdminData adminData = new AdminData(); adminData._id = ObjectId.GenerateNewId(); adminData.Name = teName.Text; adminData.SlNo = Convert.ToInt32(tcSlno.Text); adminData.Age = Convert.ToInt32(teAge.Text); adminData.Address = teAddress.Text; Entity = adminData; this.DialogResult = true; }
public List<AdminData> GetCollection() { try { List<AdminData> adminDataList = new List<AdminData>(); MongoDatabase myDB = GetDB(); MongoCollection<AdminData> adminDataTable = myDB.GetCollection<AdminData>("AdminData"); MongoCursor<BsonDocument> cursor = adminDataTable.FindAllAs<BsonDocument>(); foreach (var item in cursor) { AdminData admnData = new AdminData(); admnData._id = (ObjectId)item["_id"]; admnData.Address = item["Address"].ToString(); admnData.Name = item["Name"].ToString(); admnData.Age = Convert.ToInt32(item["Age"].ToString()); admnData.SlNo = Convert.ToInt32(item["SlNo"].ToString()); adminDataList.Add(admnData); } // grdcAdminData.ItemsSource = adminDataList; return adminDataList; } catch (Exception ex) { throw; } }
public List <AdminData> GetCollection() { try { List <AdminData> adminDataList = new List <AdminData>(); MongoDatabase myDB = GetDB(); MongoCollection <AdminData> adminDataTable = myDB.GetCollection <AdminData>("AdminData"); MongoCursor <BsonDocument> cursor = adminDataTable.FindAllAs <BsonDocument>(); foreach (var item in cursor) { AdminData admnData = new AdminData(); admnData._id = (ObjectId)item["_id"]; admnData.Address = item["Address"].ToString(); admnData.Name = item["Name"].ToString(); admnData.Age = Convert.ToInt32(item["Age"].ToString()); admnData.SlNo = Convert.ToInt32(item["SlNo"].ToString()); adminDataList.Add(admnData); } // grdcAdminData.ItemsSource = adminDataList; return(adminDataList); } catch (Exception ex) { throw; } }
public string InsertDocument(AdminData adminData) { try { MongoDatabase myDB = GetDB(); MongoCollection<AdminData> adminDataTable = myDB.GetCollection<AdminData>("AdminData"); adminDataTable.Insert(adminData); return "Succcess"; } catch (Exception ex) { throw; } }
public string UpdateDocument(AdminData adminData) { try { MongoDatabase myDB = GetDB(); MongoCollection<AdminData> adminDataTable = myDB.GetCollection<AdminData>("AdminData"); QueryDocument queryDoc = new QueryDocument("_id", adminData._id); IMongoQuery query = queryDoc; // IMongoUpdate update = new UpdateDocument("Address","Hyd"); // IMongoUpdate update = new UpdateDocument().Set("Address", "Hyd") as UpdateDocument; // IMongoUpdate update = new UpdateDocument().Set(queryDoc.IndexOfName("Address"), "Hyd") as UpdateDocument; var updateDoc = Update.Set("Address", adminData.Address).Set("Age",adminData.Age.ToString()).Set("Name",adminData.Name).Set("SlNo",adminData.SlNo.ToString()); IMongoUpdate update = updateDoc; WriteConcernResult updateResult = adminDataTable.Update(query, update); return "Succcess"; // adminDataTable.Update() // GetCollection(); } catch (Exception ex) { throw; } }