public void Add(Contact contact)
        {
            if (_contacts.Any(x => x.ContactId == contact.ContactId))
            {
                throw new InvalidOperationException(string.Format("Contact with id '{0}' already exists", contact.ContactId));
            }

            _contacts.Add(contact);
        }
        public IHttpActionResult Post(Contact contact)
        {
            if (ModelState.IsValid)
            {
                _repository.Add(contact);
                return CreatedAtRoute("GetContactById", new {id = contact.ContactId}, contact);
            }

            return BadRequest(ModelState);
        }
        static Contact AddSelfLink(Contact contact, HttpActionExecutedContext context)
        {
            var linkProvider = context.Request.GetDependencyScope().GetService(typeof(LinkProvider)) as LinkProvider;
            if (linkProvider == null)
            {
                throw new Exception("Link provider not found");
            }

            contact.Self = linkProvider.GetLink(context.Request, "GetContactById", new { id = contact.ContactId }).ToString(); ;
            return contact;
        }
        public IEnumerable<Contact> GetContacts()
        {
            var contact = new Contact
            {
                ContactId = 100,
                Address = "Bahnhofstrasse",
                City = "Luzern",
                Email = "*****@*****.**",
                Name = "Filip W",
                Zip = "6000",
                State = "LU"
            };

            return new[] { contact };
        }
        public void Update(Contact updatedContact)
        {
            var contact = Get(updatedContact.ContactId);
            if (contact == null)
            {
                throw new InvalidOperationException(string.Format("Contact with id '{0}' does not exists", contact.ContactId));
            }

            contact.Address = updatedContact.Address;
            contact.City = updatedContact.City;
            contact.Email = updatedContact.Email;
            contact.Name = updatedContact.Name;
            contact.State = updatedContact.State;
            contact.Twitter = updatedContact.Twitter;
            contact.Zip = updatedContact.Zip;
        }
 public HttpResponseMessage Put(int id, Contact contact)
 {
     contact.ContactId = id;
     _repository.Update(contact);
     return new HttpResponseMessage(HttpStatusCode.NoContent);
 }