コード例 #1
0
        /// <summary>
        /// Creates a Order in database.
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public HttpResponseMessage Post(OrderDto orderDto)
        {
            try
            {
                var order = new OrderConverter().Convert(orderDto);
                facade.GetOrderRepository().Add(order);

                var response = Request.CreateResponse<OrderDto>(HttpStatusCode.Created, orderDto);
                var uri = Url.Link("GetOrderById", new { order.Id });
                response.Headers.Location = new Uri(uri);
                return response;
            }
            catch (Exception)
            {
                var response = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent("Could not add a Order to the database")
                };
                throw new HttpResponseException(response);
            }
        }
コード例 #2
0
 /// <summary>
 /// Updates a Order from database.
 /// </summary>
 /// <param name="order"></param>
 /// <returns></returns>
 public HttpResponseMessage Put(OrderDto orderDto)
 {
     try
     {
         Order order = new OrderConverter().Convert(orderDto);
         facade.GetOrderRepository().Edit(order);
         var response = Request.CreateResponse<OrderDto>(HttpStatusCode.OK, orderDto);
         var uri = Url.Link("GetOrderById", new { order.Id });
         response.Headers.Location = new Uri(uri);
         return response;
     }
     catch (Exception)
     {
         var response = new HttpResponseMessage(HttpStatusCode.Conflict)
         {
             Content = new StringContent("No matching order")
         };
         throw new HttpResponseException(response);
     }
 }