Ejemplo n.º 1
0
        /// <summary>
        ///
        /// GetWithOrderTotals() build a DTOobject list and returns a complete order withOUT orderlines and WITH total amount calculated
        /// </summary>
        /// <param name="paramOrderID"></param>
        /// <returns>_orderlist</returns>
        public async Task <DTOOrderWithTotal> GetWithOrderTotals(int paramOrderID)
        {
            // open async connection reader order get by order ID
            _dbManager.command.CommandText = "select * FROM tblOrders WHERE id=@paramOrderID AND deleted IS NULL";
            _dbManager.command.Parameters.Add("paramOrderID", SqlDbType.Int).Value = paramOrderID;
            await _dbManager.connection.OpenAsync();

            SqlDataReader reader = await _dbManager.command.ExecuteReaderAsync().ConfigureAwait(false);

            _order = _tblOrdersDBReader.ReadDB(reader).FirstOrDefault();
            _dbManager.connection.Close();

            // get lines from services
            var orderlines = await orderLinesService.GetBy(paramOrderID).ConfigureAwait(false);

            var customer = await customerService.GetBy(_order.CustomerId).ConfigureAwait(false);

            // break if customer is deleted
            if (customer.Zip == 1234)
            {
                return(null);
            }

            //build output
            _DTOOrderWithTotal = _DTOOrderWithTotalsBuilder.Build(customer, _order, orderlines);
            return(_DTOOrderWithTotal);
        }
        public DTOOrderWithTotal Build(tblCustomer paramCustomer, tblOrders paramOrder, List <DTOOrderlines> paramOrderlines)
        {
            // build total order amount
            Decimal ordertotal = 0;

            foreach (var item in paramOrderlines)
            {
                ordertotal += item.OrderlineTotal;
            }

            //build output
            _DTOOrderWithTotal = new DTOOrderWithTotal
            {
                CreateDate   = paramOrder.CreateDate,
                CustomerId   = paramOrder.CustomerId,
                CustomerName = paramCustomer.Firstname + " " + paramCustomer.Lastname,
                Id           = paramOrder.Id,
                OrderTotal   = ordertotal
            };
            return(_DTOOrderWithTotal);
        }
Ejemplo n.º 3
0
        public async Task <List <DTOOrderWithTotal> > GetWithOrderTotalsList(int _paramFrom, int _paramTo)
        {
            _orderlist = await orderService.GetList(_paramFrom, _paramTo).ConfigureAwait(false);

            foreach (var item in _orderlist)
            {
                // init dependency
                OrderService orderService = new OrderService();
                _DTOOrderWithTotal = new DTOOrderWithTotal();
                _DTOOrderWithTotal = await Task.Run(() => orderService.GetWithOrderTotals(item.Id)).ConfigureAwait(false);

                if (_DTOOrderWithTotal == null)
                {
                    // do nothing, customer doesnt exist
                }
                else
                {
                    _orderlinelist.Add(_DTOOrderWithTotal);
                }
            }
            ;
            return(_orderlinelist);
        }