Esempio n. 1
0
 public virtual void AddItem(OrderItem a_orderItem)
 {
     if (Status != OrderStatus.Unpaid)
      {
     throw new InvalidOrderOperationException(
        string.Format("Can't add another item to the order because it is {0}.",
                      Status.ToString().ToLower()));
      }
      a_orderItem.Order = this;
      _items.Add(a_orderItem);
 }
Esempio 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);
        }
 public virtual void AddOrderItem(OrderItem a_item)
 {
     orderItems.Add(a_item);
 }
 public OrderItemRepresentation(OrderItem item)
     : this()
 {
     Name = item.Product.Name;
       Quantity = item.Quantity;
 }
        public ActionResult Save(FormCollection form_collection)
        {
            //Save Order
            var order_repository = (OrderRepository)System.Web.HttpContext.Current.Application["order_repository"];
            var order_items = (IList<OrderItemModel>)Session["order_items"];
            var order = new Order();

            foreach (var order_item in order_items)
            {
                var item = new OrderItem {item_id = order_item.item_id, quantity = order_item.quantity, price = order_item.price};
                order.items.Add(item);
            }

            order_repository.save(order);

            //Send email
            MailMessage email = new MailMessage("*****@*****.**","*****@*****.**");
            email.Subject = "Order submitted";

            SmtpClient client = new SmtpClient("localhost");

            try
            {
                client.Send(email);
            }
            catch(Exception exception)
            {
                //It is ok that it doesn't actually send the email for this project
            }

            ViewData["order"] = order;
            return View("ThankYou");
        }