public void Put(string id, Contact value)
 {
     if (!_contacts.UpdateContact(id, value))
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
 public Contact AddContact(Contact item)
 {
     item.Id = ObjectId.GenerateNewId().ToString();
     item.LastModified = DateTime.UtcNow;
     _contacts.Insert(item);
     return item;
 }
Exemplo n.º 3
0
        public ContactRepository(string connection)
        {
            if (string.IsNullOrWhiteSpace(connection))
            {
                connection = "mongodb://*****:*****@example.com", index),
                    Name = string.Format("test{0}", index),
                    Phone = string.Format("{0}{0}{0} {0}{0}{0} {0}{0}{0}{0}", index)
                };
                AddContact(contact1);
            }
        }
 public bool UpdateContact(string id, Contact item)
 {
     IMongoQuery query = Query.EQ("_id", id);
     item.LastModified = DateTime.UtcNow;
     IMongoUpdate update = Update
         .Set("Email", item.Email)
         .Set("LastModified", DateTime.UtcNow)
         .Set("Name", item.Name)
         .Set("Phone", item.Phone);
     SafeModeResult result = _contacts.Update(query, update);
     return result.UpdatedExisting;
 }
 public Contact Post(Contact value)
 {
     Contact contact = _contacts.AddContact(value);
     return contact;
 }
 private static void PrintContact(Contact contact)
 {
     Console.WriteLine("  Email:         {0}", contact.Email);
     Console.WriteLine("  Name:          {0}", contact.Name);
     Console.WriteLine("  Phone:         {0}", contact.Phone);
     Console.WriteLine("  ID:            {0}", contact.Id);
     Console.WriteLine("  Last Modified: {0}", contact.LastModified);
     Console.WriteLine();
 }