예제 #1
0
        /// <summary>
        /// Create and add a new order line
        /// </summary>
        /// <param name="productId">the product identifier</param>
        /// <param name="amount">the number of items</param>
        /// <param name="unitPrice">the unit price of each item</param>
        /// <param name="discount">applied discount</param>
        /// <returns>added new order line</returns>
        public OrderLine AddNewOrderLine(Guid productId, int amount, decimal unitPrice, decimal discount)
        {
            //check precondition
            if (amount <= 0
                ||
                productId == Guid.Empty)
            {
                throw new ArgumentException(Messages.exception_InvalidDataForOrderLine);
            }

            //check discount values
            if (discount < 0)
            {
                discount = 0;
            }


            if (discount > 100)
            {
                discount = 100;
            }

            //create new order line
            var newOrderLine = new OrderLine()
            {
                OrderId   = this.Id,
                ProductId = productId,
                Amount    = amount,
                Discount  = discount,
                UnitPrice = unitPrice
            };

            //set identity
            newOrderLine.GenerateNewIdentity();

            //add order line
            this.OrderLines.Add(newOrderLine);

            //return added orderline
            return(newOrderLine);
        }
예제 #2
0
      /// <summary>
      ///    Create and add a new order line
      /// </summary>
      /// <param name="productId">the product identifier</param>
      /// <param name="amount">the number of items</param>
      /// <param name="unitPrice">the unit price of each item</param>
      /// <param name="discount">applied discount</param>
      /// <returns>added new order line</returns>
      public OrderLine AddNewOrderLine(Guid productId, int amount, decimal unitPrice, decimal discount)
      {
         //check precondition
         if (amount <= 0 || productId == Guid.Empty) {
            throw new ArgumentException(Messages.exception_InvalidDataForOrderLine);
         }

         //check discount values
         if (discount < 0) { discount = 0; }

         if (discount > 100) { discount = 100; }

         //create new order line
         var newOrderLine = new OrderLine()
         {
            OrderId = this.Id,
            ProductId = productId,
            Amount = amount,
            Discount = discount,
            UnitPrice = unitPrice
         };
         //set identity
         newOrderLine.GenerateNewIdentity();

         //add order line
         this.OrderLines.Add(newOrderLine);

         //return added orderline
         return newOrderLine;
      }