// Add a user - POST request
        public HttpResponseMessage PostUser(user item)
        {
            repository.Add(item);
            var response = Request.CreateResponse<user>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultAPI", new { id = item.Id });
            response.Headers.Location = new Uri(uri);
            return response;
        }
        //update user - PUT
        public HttpResponseMessage PutUser(string id, user item)
        {
            // check if user exists with this id
            user userToDelete = repository.Get(new ObjectId(id));
            if (userToDelete == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            item.Id = new ObjectId(id);
            repository.Update(item);
            HttpResponseMessage response = new HttpResponseMessage();
            response.Content = new StringContent("updated");
            return response;
        }
Exemplo n.º 3
0
 public void Update(user item)
 {
     var query = Builders<user>.Filter.Eq(e => e.Id, item.Id);
     var result = _collection.ReplaceOneAsync(query, item);
 }
Exemplo n.º 4
0
 public void Add(user item)
 {
     _collection.InsertOneAsync(item);
 }