public bool UpdateDeliveryStatus(int deliveryId, string newDeliveryStatus, [FromBody] string verificationImage)
        {
            bool result = false;

            try
            {
                Delivery oldDelivery = _deliveryManager.RetrieveDeliveryById(deliveryId);
                Delivery newDelivery = _deliveryManager.RetrieveDeliveryById(deliveryId);
                newDelivery.StatusId = newDeliveryStatus;
                try
                {
                    byte[] verificationAsBytes = Encoding.ASCII.GetBytes(verificationImage);
                    newDelivery.Verification = verificationAsBytes;
                }
                catch
                {
                    byte[] verificationAsBytes = null;
                    newDelivery.Verification = verificationAsBytes;
                }

                if (_deliveryManager.UpdateDelivery(oldDelivery, newDelivery))
                {
                    result = true;
                }
                else
                {
                    result = false;
                }

                List <Delivery> ordersDeliveries = _deliveryManager.RetrieveDeliveriesByOrderId((int)oldDelivery.OrderId);
                bool            allDelivered     = true;
                foreach (Delivery d in ordersDeliveries)
                {
                    if (d.StatusId != "Delivered")
                    {
                        allDelivered = false;
                    }
                }

                if (allDelivered)
                {
                    ProductOrder oldOrder = _orderManager.retrieveProductOrderDetails((int)oldDelivery.OrderId);
                    ProductOrder newOrder = _orderManager.retrieveProductOrderDetails((int)oldDelivery.OrderId);
                    newOrder.OrderStatusId = "Delivered";
                    newOrder.HasArrived    = true;
                    _orderManager.UpdateProductOrder(oldOrder, newOrder);
                }
            }
            catch
            {
                result = false;
            }

            return(result);
        }
예제 #2
0
 /// <summary>
 /// Alissa Duffy
 /// Updated: 2017/04/24
 ///
 /// Saves changes made to Add Edit Delivery form.
 /// Standardized method.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     if (_isEdit)
     {
         Delivery newDelivery = new Delivery()
         {
             DeliveryDate   = dtpckDeliveryDate.SelectedDate,
             DeliveryTypeId = (string)comBoxType.SelectedItem,
             StatusId       = (string)comBoxStatus.SelectedItem,
             Verification   = _delivery.Verification,
             RouteId        = _delivery.RouteId,
             PackageList    = _delivery.PackageList,
             DeliveryId     = _delivery.DeliveryId,
             OrderId        = _delivery.OrderId
         };
         try
         {
             var result = _deliveryManager.UpdateDelivery(_delivery, newDelivery);
             if (result)
             {
                 this.DialogResult = true;
                 MessageBox.Show("Delivery Successfully updated.");
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Update failed.");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
         }
     }
     else
     {
         throw new NotSupportedException("Adding stuff hasn't been implemented yet.");
     }
 }