Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 16th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class PersonManager
  2. {
  3.         MongoSession mongoSession;
  4.  
  5.         public PersonManager (MongoSession _mongoSession)
  6.         {
  7.                 mongoSession = _mongoSession;
  8.         }
  9.  
  10.         public Person Save (object o)
  11.         {
  12.                 Person person;
  13.                 try {
  14.                         person = o as Person;
  15.                 } catch {
  16.                         throw new Exception ("You can only save an object that inherits Person");
  17.                 }
  18.  
  19.                 var personCollection = mongoSession.Database.GetCollection <Person> ("person");
  20.                 personCollection.Insert<Person> (person); // I don't want to have to specific Person here...
  21.  
  22.                 return person;
  23.         }
  24. }
  25.  
  26. class SomeProcess {
  27.  
  28.         public PersonManager personManager { get; set; }
  29.  
  30.         public void Process (string ent, object dto)
  31.         {
  32.                 var data  = dto as SomeDto;
  33.  
  34.                 // create person
  35.                 var complexPerson = Mapper.Map<SomeDto, SomeComplexPerson>(data);
  36.                 complexPerson.AddedOn = DateTime.UtcNow;
  37.                 personManager.Save (complexPerson);
  38.         }
  39.  
  40. }