Exemple #1
0
        public IActionResult DeliverableOrder(int id)
        {
            List <Order> orders = deliveryService.GetListofCustomersforOrderDeliver(id);

            if (orders.Count != 0)
            {
                List <Delivery> deliveries  = deliveryService.GetListofCustomerstoCheckIfExists(id);
                List <Delivery> deliveries1 = deliveryService.GetListofExistingCustomerstoCheckIfExists(id);
                if (deliveries.Count == 0)
                {
                    for (int i = 0; i < orders.Count; i++)
                    {
                        deliveryService.AddDeliverableOrder(new Delivery()
                        {
                            OrderId       = orders[i].OrderId,
                            Status        = false,
                            DeliveredDate = DateTime.Now,
                            //will be changed at the end, user auth
                            DeliveryStaffId = 1
                        });
                    }
                    return(Json(new { sms = "Saved" }));
                }
                else if (deliveries1.Count != 0)
                {
                    for (int i = 0; i < orders.Count; i++)
                    {
                        deliveryService.AddDeliverableOrder(new Delivery()
                        {
                            OrderId       = orders[i].OrderId,
                            Status        = false,
                            DeliveredDate = DateTime.Now,
                            //will be changed at the end, user auth
                            DeliveryStaffId = 1
                        });
                    }
                    return(Json(new { sms = "Saved" }));
                }
                else
                {
                    deliveryService.DeleteDeliverableOrderbyId(id);
                    return(Json(new { sms = "Deleted" }));
                }
            }
            else
            {
                return(RedirectToAction("CustomerList", "Admin"));
            }
        }