Ejemplo n.º 1
0
 protected POSOrderItem(string productUniqueCode, int quantity, POSOrderItem item)
 {
     ProductUniqueCode = productUniqueCode;
     CustomerValue     = item.CustomerValue;
     CostPrice         = item.CostPrice;
     POSOrderId        = item.POSOrderId;
     Quantity          = quantity;
 }
Ejemplo n.º 2
0
        public virtual POSOrderItem Sum(POSOrderItem rhs)
        {
            if (this.ProductUniqueCode != rhs.ProductUniqueCode)
            {
                return(rhs);
            }
            var item = new POSOrderItem(this.ProductUniqueCode, this.Quantity + rhs.Quantity, this);

            return(item);
        }
Ejemplo n.º 3
0
        public virtual void AddItem(int productId, int quantity, IRepository <Product> repository)
        {
            var item = POSOrderItem.Create(productId, quantity, this, repository);

            if (!item.Success)
            {
                return;
            }
            AddItem(item.Value);
        }
Ejemplo n.º 4
0
        public static BaseResult <POSOrderItem> Create(int productId, int quantity, POSOrder posOrder, IRepository <Product> productRepository)
        {
            var product = productRepository.GetBy(productId);

            if (product.QuantityInStock == 0)
            {
                return(BaseResult <POSOrderItem> .Failed(new [] { $"can't create item.Product of id {product.Id} is out of stock" }, null));
            }
            if ((product.QuantityInStock - quantity) < 0)
            {
                return(BaseResult <POSOrderItem> .Succeed("Order Item is defined", new POSOrderItem(product, posOrder, product.QuantityInStock)));
            }
            var item = new POSOrderItem(product, posOrder, quantity);

            return(BaseResult <POSOrderItem> .Succeed("Order Item is defined", item));
        }
Ejemplo n.º 5
0
        public virtual void AddItem(POSOrderItem item)
        {
            if (this.State == OrderState.Cancelled)
            {
                return;
            }
            var existingItem = Items.Where(i => i.Id == item.Id).FirstOrDefault();

            if (existingItem is null)
            {
                Items.Add(item);
                this.RemainingValueToPay += item.Quantity * item.CustomerValue;
                return;
            }
            var newItem = existingItem.Sum(item);

            this.Items.Remove(existingItem);
            this.Items.Add(newItem);
            this.RemainingValueToPay += item.Quantity * item.CustomerValue;
        }