public void Delete(MongoPerson item) { MongoDatabase db = server.GetDatabase("Person"); var people = db.GetCollection<MongoPerson>("Person"); //people.Find(item); }
private PersonViewModel ToViewModel(MongoPerson personR) { PersonViewModel personVM = new PersonViewModel() { Id = personR.Id, FirstName = personR.FirstName, LastName = personR.LastName, Age = personR.Age, PhoneNumbers = new List<PhoneNumberViewModel>() }; foreach (var pn in personR.phonenumbers) { personVM.PhoneNumbers.Add(new PhoneNumberViewModel() { Id = pn.Id, PhoneNumber = pn.PhoneNumber, PhoneNumberType = pn.PhoneNumberType }); } return personVM; }
public void Create(MongoPerson item) { MongoPerson person = new MongoPerson() { FirstName = item.FirstName, LastName = item.LastName, Age = item.Age, Id=new ObjectId(), phonenumbers = new List<MongoPhoneNumber>()//for one number { new MongoPhoneNumber() { Id=new ObjectId(), PhoneNumber=item.phonenumbers[0].PhoneNumber, PhoneNumberType=item.phonenumbers[0].PhoneNumberType } } }; MongoDatabase db = server.GetDatabase("Person"); var people = db.GetCollection<MongoPerson>("Person"); people.Save(person); }
private MongoPerson FromViewModel(PersonViewModel person) { MongoPerson personR = new MongoPerson() { Id = person.Id, FirstName = person.FirstName, LastName = person.LastName, Age = person.Age, phonenumbers = new List<MongoPhoneNumber>() }; foreach (var pn in person.PhoneNumbers) { if (pn.PhoneNumberType==null) { throw new ArgumentException(); } personR.phonenumbers.Add(new MongoPhoneNumber() { Id=pn.Id, PhoneNumber = pn.PhoneNumber, PhoneNumberType=pn.PhoneNumberType, }); } return personR; }
public void Update(MongoPerson item) { throw new NotImplementedException(); }