コード例 #1
0
        public void Delete(int id)
        {
            ContactBO contact = ContactsMap.Map(this.Contactrepository.GetContactById(id));

            if (contact == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Contactrepository.Delete(id);
        }
コード例 #2
0
        public HttpResponseMessage Put(int id, ContactBO contact)
        {
            contact.Id = id;
            var entity = ContactsMap.Map(contact);

            if (!Contactrepository.Update(entity))
            {
                throw new HttpResponseException(HttpStatusCode.NotModified);
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
        }
コード例 #3
0
        public HttpResponseMessage Post(ContactBO request)
        {
            var data = ContactsMap.Map(request);

            var entity   = Contactrepository.Insert(data);
            var response = Request.CreateResponse(HttpStatusCode.Created, entity);

            try
            {
                string uri = Url.Link("DefaultApi", new { id = entity.ID });
                response.Headers.Location = new Uri(uri);
            }
            catch (Exception e)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = new StringContent("An error occurred, please try again"),
                    ReasonPhrase = "Critical exception"
                });
            }

            return(response);
        }