Ejemplo n.º 1
0
 public void SetUp()
 {
     DtoMapper mapper = new DtoMapper(new LinkProvider());
      m_order = new Order();
      m_order.Cancel("You are too slow.");
      m_dto = mapper.Map<Order, OrderDto>(m_order);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an order
        /// </summary>
        /// <param name="a_orderModel">Order dto model</param>
        /// <remarks>
        /// Json Invoke: {Location: "inShop", Items: {Name: "latte", Quantity: 5}}
        /// Xml invoke: 
        /// </remarks>
        /// <returns>Response</returns>
        public HttpResponseMessage Post(OrderDto a_orderModel)
        {
            var order = new Order
             {
            Date = DateTime.Today,
            Location = a_orderModel.Location
             };

             foreach (var requestedItem in a_orderModel.Items)
             {
            var product = m_productRepository.GetByName(requestedItem.Name);
            if (product == null)
            {
               return Request.CreateResponse(HttpStatusCode.BadRequest, string.Format("We don't offer {0}", requestedItem.Name));
            }

            var orderItem = new OrderItem(product,
                                        requestedItem.Quantity,
                                        product.Price,
                                        requestedItem.Preferences.ToDictionary(a_x => a_x.Key, a_y => a_y.Value));
            order.AddItem(orderItem);
             }

             if (!order.IsValid())
             {
            var content = string.Join("\n", order.GetErrorMessages());
            return Request.CreateResponse(HttpStatusCode.BadRequest, string.Format("Invalid entities values {0}", content));
             }

             m_orderRepository.MakePersistent(order);
             //var uri = resourceLinker.GetUri<OrderResourceHandler>(orderResource => orderResource.Get(0, null), new { orderId = order.Id });
             return Request.CreateResponse(HttpStatusCode.OK);
        }
Ejemplo n.º 3
0
 public void SetUp()
 {
     var mapper = new DtoMapper(new LinkProvider());
      m_order = new Order();
      m_order.Pay("123", "jose");
      m_dto = mapper.Map<Order, OrderDto>(m_order);
 }