public Customer Update(MovieStoreDAL.Customer customer)
 {
     using (var client = new HttpClient())
     {
         HttpResponseMessage response = client.PostAsJsonAsync("http://localhost:9885/api/Customer/", customer.Id).Result;
         return(response.Content.ReadAsAsync <Customer>().Result);
     }
 }
Ejemplo n.º 2
0
        // POST: api/Customers
        public HttpResponseMessage PostCustomer(Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            try
            {
                customer = service.Customers.Create(customer);
                service.Save();
                var response = Request.CreateResponse(HttpStatusCode.Created, customer);

                string uri = Url.Link("DefaultApi", new {id = customer.Id});
                response.Headers.Location = new Uri(uri);

                return response;
            }
            catch (Exception ex)
            {

                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
        }
Ejemplo n.º 3
0
        public CustomerDto PutCustomer(Customer customer)
        {

            var customers = dalFacade._customersRepository.Edit(customer);
            return customerConverter.Convert(customers);
        }
Ejemplo n.º 4
0
        // PUT: api/Customers/5
        public HttpResponseMessage PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            if (id != customer.Id)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest,"Customers id is not the same with given id");
            }

            try
            {
                service.Customers.Update(customer);
                service.Save();
            }
            catch (Exception ex)
            {
                if (!CustomerExists(id))
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound, "Customer with given id not found");
                }
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
            return Request.CreateResponse(HttpStatusCode.OK, customer);
        }