Example #1
0
        public static CustomerDeposit MakeCustomerDeposit(CustomerOrderItem customerOrderItem, float amount, DepositMovement depositMovement)
        {
            if (customerOrderItem == null)
            {
                throw new ArgumentNullException("Customer order item must have a value.");
            }

            if (amount <= 0)
            {
                throw new ArgumentException("Amount must be larger than 0.");
            }

            var deposit = new CustomerDeposit();

            deposit.Amount = amount;

            deposit.RegisterDate        = DateTime.Now;
            deposit.MovementType        = depositMovement;
            deposit.CustomerOrderItemId = customerOrderItem.Id;
            deposit.CustomerOrderItem   = customerOrderItem;
            deposit.Sku = customerOrderItem.Product.Sku;

            deposit.CustomerOrderItem.Product.UpdateAmount(depositMovement == DepositMovement.In ? amount : -amount);

            return(deposit);
        }
Example #2
0
        public override void Delete()
        {
            if (IsDeleted)
            {
                throw new InvalidOperationException("Order item is already deleted.");
            }

            var deletedMovementItem = CustomerDeposit.MakeCustomerDeposit(this, Amount, DepositMovement.In);

            Deposits.Add(deletedMovementItem);

            CustomerOrder.Customer.UpdateTotalSpent(-Amount);

            base.Delete();
        }
Example #3
0
        public void ChangeAmount(float amount)
        {
            if (IsDeleted)
            {
                throw new InvalidOperationException("Order item is deleted.");
            }

            if (amount <= 0)
            {
                throw new ArgumentException("Amount must be larger than 0.");
            }

            if (Amount == amount)
            {
                throw new ArgumentException("Amount can't be the same as before.");
            }

            if (Product.Amount < amount)
            {
                throw new ArgumentException("Amount larger than product deposit.");
            }

            var difference   = amount - Amount;
            var movementType = DepositMovement.Out;

            if (difference < 0)
            {
                difference   = -difference;
                movementType = DepositMovement.In;
            }

            Amount = amount;
            var oldValue = TotalValue;

            TotalValue = Price * Amount;

            var deposit = CustomerDeposit.MakeCustomerDeposit(this, difference, movementType);

            Deposits.Add(deposit);

            difference = TotalValue - oldValue;
            CustomerOrder.UpdateTotalValue(difference);
        }
Example #4
0
        public static CustomerOrderItem MakeCustomerOrderItem(CustomerOrder customerOrder, Product product, float amount)
        {
            if (customerOrder == null)
            {
                throw new ArgumentNullException("Customer order must have a value.");
            }

            if (product == null)
            {
                throw new ArgumentNullException("Product must have a value.");
            }

            if (amount <= 0)
            {
                throw new ArgumentException("Amount must be larger than 0.");
            }

            if (product.Amount < amount)
            {
                throw new ArgumentException("Amount larger than product deposit.");
            }

            var customerOrderItem = new CustomerOrderItem();

            customerOrderItem.CustomerOrderId = customerOrder.Id;
            customerOrderItem.CustomerOrder   = customerOrder;
            customerOrderItem.ProductId       = product.Id;
            customerOrderItem.Product         = product;
            customerOrderItem.Amount          = amount;
            customerOrderItem.Price           = product.Price;
            customerOrderItem.TotalValue      = customerOrderItem.Price * customerOrderItem.Amount;
            customerOrderItem.Deposits        = new List <CustomerDeposit>();

            customerOrder.UpdateTotalValue(customerOrderItem.TotalValue);

            var deposit = CustomerDeposit.MakeCustomerDeposit(customerOrderItem, amount, DepositMovement.Out);

            customerOrderItem.Deposits.Add(deposit);

            return(customerOrderItem);
        }