예제 #1
0
 public void Put(string id, Contact value)
 {
     if (!_contacts.UpdateContact(id, value))
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
예제 #2
0
 public Contact AddContact(Contact item)
 {
     item.Id = ObjectId.GenerateNewId().ToString();
     item.LastModified = DateTime.UtcNow;
     _contacts.Insert(item);
     return item;
 }
예제 #3
0
 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);
     WriteConcernResult result = _contacts.Update(query, update);
     return result.UpdatedExisting;
 }
예제 #4
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);
            }
        }
예제 #5
0
 public Contact Post(Contact value)
 {
     Contact contact = _contacts.AddContact(value);
     return contact;
 }