示例#1
0
        public async void PutEmployee()
        {
            var client = new HttpClient();
            var peggy = new Employee { Id = 2, Name = "Peggy", Title = "Marketing" };

            HttpResponseMessage response = await client.GetAsync("http://E6400:8001/services/employee");
            response.EnsureSuccessStatusCode();
            IEnumerable<Employee> confirm = await response.Content.ReadAsAsync<IEnumerable<Employee>>();
            int n = 0;

        }
        public HttpResponseMessage Put(int id, Employee employeeUpdate)
        {
            if (employeeUpdate == null)
            {
                return this.Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "");
            }

            var employee = (from e in employees where e.Id == id select e).FirstOrDefault();

            if (employee == null)
            {
                return this.Request.CreateErrorResponse(HttpStatusCode.NotFound, string.Format("Employee {0} not found.", id));
            }

            Console.WriteLine(string.Format("Employee: {0}", employeeUpdate.Id));
            return this.Request.CreateResponse(HttpStatusCode.OK, employeeUpdate);
        }
        public async void PutEmployee()
        {
            var client = new HttpClient();
            var don = new Employee { Id = 1, Name = "Don", Title = "Marketing Director" };

            MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();

            try
            {
                HttpResponseMessage response = await client.PutAsync("http://localhost.:8001/employees", don, jsonFormatter);
                response.EnsureSuccessStatusCode();
            }
            catch (Exception e)
            {
                string mes = e.Message;
                throw;
            }
            
        }
 public void Post(Employee newHire)
 {
     employees.Add(newHire);
 }