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
 public ActionResult Edit([Bind(Include = "ProductOrderId,CustomerId,EmployeeId,OrderTypeId,AddressType,DeliveryTypeId,Amount,OrderDate,DateExpected,Discount,OrderStatusId,UserAddressId,HasArrived")] ProductOrder newOrder)
 {
     if (ModelState.IsValid)
     {
         var oldOrder = ordMgr.RetrieveProductOrdersByStatus("Open").Find(o => o.OrderId == (int)newOrder.OrderId);
         if (ordMgr.UpdateProductOrder(oldOrder, newOrder) == true)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable));
         }
     }
     return(View(newOrder));
 }