Exemple #1
0
        public ShippingInfoResult GetShippingInfo(ShippingInfoRequest request)
        {
            var result = new ShippingInfoResult();

            try
            {
                using (var cmd = new SqlCommand("usp_GetShippingInfoByDateRange", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.DateTime)
                    {
                        Value = request.StartDate
                    });
                    cmd.Parameters.Add(new SqlParameter("@EndDate", SqlDbType.DateTime)
                    {
                        Value = request.EndDate
                    });

                    var reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        result.Manifests = new List <ItemTracking>();
                        while (reader.Read())
                        {
                            var itemStatus = new ItemTracking
                            {
                                OrderLineItemId = reader.GetString(OrderLineItemIdOrdinal),
                                Carrier         = reader.GetString(CarrierOrdinal),
                                ShipDate        = reader.GetDateTime(ShipDateOrdinal),
                                TrackingNumber  = reader.GetString(TrackingNumberOrdinal),
                                TrackingUrl     = reader.GetString(TrackingUrlOrdinal)
                            };
                            result.Manifests.Add(itemStatus);
                        }
                    }
                    else
                    {
                        // TODO: Throw an exception indicating no rows were returned.
                    }
                }
            }
            catch (SqlException ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSqlException(ex);
            }
            catch (Exception ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSystemException(ex);
            }

            return(result);
        }
        private SubmitOrderResult GetOrderResults()
        {
            var result    = new SubmitOrderResult();
            var lineItems = new List <LineItemStatus>();

            try
            {
                using (var cmd = new SqlCommand("usp_GetOrderLineItems", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@OrderID", SqlDbType.Int)
                    {
                        Value = id
                    });
                    var reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var lineItem = new LineItemStatus
                            {
                                OrderLineItemId   = reader.GetString(OrderLineItemIdOrdinal),
                                ProductIdentifier = reader.GetString(ProductIdentifierOrdinal),
                                QtyReserved       = reader.GetInt32(QtyReservedOrdinal)
                            };
                            lineItems.Add(lineItem);
                        }
                    }
                    else
                    {
                        throw new NoLineItemsFoundException(orderNumber);
                    }
                }
                result.HasException = false;
                result.Exception    = null;
                result.OrderItems   = lineItems;
            }
            catch (SqlException ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSqlException(ex);
            }
            catch (Exception ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSystemException(ex);
            }

            return(result);
        }
        public SubmitOrderResult SaveOrder(SubmitOrderRequest request)
        {
            var result = new SubmitOrderResult();

            orderNumber = request.OrderNumber;

            try
            {
                trans = cn.BeginTransaction();

                var orderId = InsertOrderRecord(request);

                foreach (var orderLineItem in request.LineItems)
                {
                    InsertLineItems(orderId, orderLineItem);
                }

                trans.Commit();
                trans.Dispose();
                trans = null;

                result = GetOrderResults();
            }
            catch (SqlException ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSqlException(ex);
            }
            catch (Exception ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSystemException(ex);
            }
            finally
            {
                if (trans != null)
                {
                    trans.Rollback();
                    trans.Dispose();
                }
                cn.Close();
                cn.Dispose();
            }

            return(result);
        }
        public OrderStatusResult GetOrderStatus(OrderStatusRequest request)
        {
            var result = new OrderStatusResult();

            try
            {
                GetIdAndOrderDate(request, result);
                result.ItemStatuses = GetLineItemStatuses(id);
            }
            catch (SqlException ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSqlException(ex);
            }
            catch (Exception ex)
            {
                result.HasException = true;
                result.Exception    = ExceptionFactory.BuildSystemException(ex);
            }

            return(result);
        }