Example #1
0
        /// <summary>
        /// GetWithOrderLines() build a DTOobject list and returns a complete order with orderlines and total amount calculated
        /// </summary>
        /// <param name="paramOrderID"></param>
        /// <returns>_orderlist</returns>
        public async Task <DTOOrderWithOrderLines> GetWithOrderLines(int paramOrderID)
        {
            // open async connection reader order get by order ID
            _dbManager.command.CommandText = "select * FROM tblOrders WHERE id=@paramOrderID";
            _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
            _DTOOrderWithOrderLines = _DTOOrderWithOrderLinesBuilder.Build(customer, _order, orderlines);
            return(_DTOOrderWithOrderLines);
        }
Example #2
0
        public DTOOrderWithOrderLines 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
            _DTOOrderWithOrderLines = new DTOOrderWithOrderLines
            {
                CreateDate    = paramOrder.CreateDate,
                CustomerId    = paramOrder.CustomerId,
                Id            = paramOrder.Id,
                DTOOrderlines = paramOrderlines,
                OrderTotal    = ordertotal,
                customer      = paramCustomer
            };
            return(_DTOOrderWithOrderLines);
        }