Esempio n. 1
0
    public async void OrderSelectedItems()
    {
        Debug.Log("0");
        if (newOrderItems.Count <= 0)
        {
            return;
        }
        //StartCoroutine(RestController.Instance.AddNewItemToOrder(
        //    UserController.Instance.order.restaurant,
        //    UserController.Instance.order.table,
        //    UserController.Instance.user.id,
        //    UserController.Instance.order.id,
        //    newOrderItems));

        DataContainers.Order newOrder = UserController.Instance.order;
        var suborder = newOrder.suborders[UserController.Instance.user.id];

        foreach (var item in newOrderItems)
        {
            if (suborder.items.ContainsKey(item.Key))
            {
                suborder.items[item.Key].delivered += item.Value.amount;
            }
            else
            {
                suborder.items.Add(item.Key, new DataContainers.OrderItem(item.Value.amount, item.Key));
            }
        }
        await DB.Order.UpdateOrder(UserController.Instance.order.restaurant, UserController.Instance.order.table, UserController.Instance.order.id, newOrder);
    }
Esempio n. 2
0
 public void InitializeMembers(DataContainers.Order iOrder)
 {
     for (int i = 0; i < membersScrollContent.childCount; i++)
     {
         Destroy(membersScrollContent.GetChild(i).gameObject);
     }
     foreach (var item in iOrder.activeUsers)
     {
         Debug.Log("member id: " + item.Value.user.id);
         GameObject go = Instantiate(memberItemPrefab, membersScrollContent);
         go.GetComponent <Prefabs.OrderUser>().Initialize(item.Value, joinRequestPopUp);
     }
 }
Esempio n. 3
0
    public void InitializeMyItems(DataContainers.Order iOrder)
    {
        for (int i = 0; i < myItemsScrollContent.childCount; i++)
        {
            Destroy(myItemsScrollContent.GetChild(i).gameObject);
        }
        var myItems = iOrder.GetUsersItems(UserController.Instance.user.id);

        foreach (var item in myItems)
        {
            GameObject go = Instantiate(orderItemPrefab, myItemsScrollContent);
            go.GetComponent <Prefabs.OrderItem>().Initialize(item.Value, true);
        }
    }
Esempio n. 4
0
    public void InitializeAllItems(DataContainers.Order iOrder)
    {
        for (int i = 0; i < allItemsScrollContent.childCount; i++)
        {
            Destroy(allItemsScrollContent.GetChild(i).gameObject);
        }
        var allItems = iOrder.GetAllItems();

        foreach (var item in allItems)
        {
            GameObject go = Instantiate(orderItemPrefab, allItemsScrollContent);
            go.GetComponent <Prefabs.OrderItem>().Initialize(item.Value);
        }
    }
Esempio n. 5
0
    public override void Initialize()
    {
        createNewOrder.onClick.RemoveAllListeners();
        createNewOrder.onClick.AddListener(async() => {
            //StartCoroutine(RestController.Instance.CreateNewOrder(restaurantId.text, tableId.text, UserController.Instance.user.id));
            //StartCoroutine(RestController.Instance.GetMenu(restaurantId.text));
            string orderId = await DB.Order.CheackIfTableIsEmpty(restaurantId.text, tableId.text);
            if (orderId == null)
            {
                Debug.Log("No active order, create new");
                string newOrderId             = await DB.Order.OrderPushKey(restaurantId.text, tableId.text);
                DataContainers.Order newOrder = new DataContainers.Order(newOrderId, tableId.text, restaurantId.text);
                var v = await DB.Order.UpdateOrder(restaurantId.text, tableId.text, newOrderId, newOrder);
                Debug.Log(v);
            }
            else
            {
                Debug.Log(orderId);
                var o = await DB.Order.ReadOrder(restaurantId.text, tableId.text, orderId);
                if (o.activeUsers.ContainsKey(UserController.Instance.user.id))
                {
                    //user is in order
                    if (o.activeUsers[UserController.Instance.user.id].status.Equals("active"))
                    {
                        //user is in order as active
                        UserController.Instance.menu  = await DB.Order.ReadMenu(restaurantId.text);
                        UserController.Instance.order = o;
                        await DB.Order.ListenOnOrder(restaurantId.text, tableId.text, orderId);
                        UIViewManager.Instance.OpenPanel("TableView");
                    }
                    else
                    {
                        //user has had request resolved
                        UIViewManager.Instance.ErrorNotification("Request allready send");
                    }
                }
                else
                {
                    var v = await DB.Order.AddJoinRequest(restaurantId.text, tableId.text, orderId,
                                                          UserController.Instance.user.id, o.owner);
                    Debug.Log(v);

                    //user is not in order send join request
                }
                UserController.Instance.menu  = await DB.Order.ReadMenu(restaurantId.text);
                UserController.Instance.order = await DB.Order.ReadOrder(restaurantId.text, tableId.text, orderId);
            }
        });
    }
Esempio n. 6
0
 public void InitializeRequests(DataContainers.Order iOrder)
 {
     for (int i = 0; i < requestsScrollContent.childCount; i++)
     {
         Destroy(requestsScrollContent.GetChild(i).gameObject);
     }
     foreach (var item in iOrder.transferRequests.Values)
     {
         Debug.Log("request aprover: " + item.aprover);
         if (item.aprover.Equals(UserController.Instance.user.id))
         {
             GameObject go = Instantiate(transferItemRequestPrefab, requestsScrollContent);
             go.GetComponent <Prefabs.TransferItemRequestPrefab>().Initialize(item, transferRequestPopUp);
         }
     }
 }
Esempio n. 7
0
    public async void TransferItems()
    {
        DataContainers.Order newOrder = UserController.Instance.order;
        var suborder = newOrder.suborders[UserController.Instance.user.id];

        foreach (var item in newTransfers)
        {
            //  Debug.Log(item);
            await DB.Order.CreateNewTransferRequest(
                UserController.Instance.order.restaurant,
                UserController.Instance.order.table,
                UserController.Instance.user.id,
                item.Key,
                UserController.Instance.order.id,
                new DataContainers.transferItem(TransferItem.id, item.Value),
                suborder.items[TransferItem.id].delivered - item.Value, suborder.items[TransferItem.id].transfered + item.Value
                );

            //StartCoroutine(RestController.Instance.CreateNewTransferRequest(UserController.Instance.order.restaurant, UserController.Instance.order.table, UserController.Instance.user.id, item.Key, UserController.Instance.order.id, new DataContainers.transferItem(TransferItem.id, item.Value)));
        }
    }
Esempio n. 8
0
 public override void Initialize()
 {
     orderButton.onClick.RemoveAllListeners();
     orderButton.onClick.AddListener(() => {
         UIViewManager.Instance.OpenPanel("RestaurantMenuView");
     });
     InitializeAllItems(UserController.Instance.order);
     InitializeMyItems(UserController.Instance.order);
     InitializeMembers(UserController.Instance.order);
     InitializeRequests(UserController.Instance.order);
     paymentButton.onClick.RemoveAllListeners();
     paymentButton.onClick.AddListener(async() => {
         List <string> transferRequestIds = new List <string>();
         foreach (var item in UserController.Instance.order.transferRequests.Keys)
         {
             transferRequestIds.Add(item);
         }
         foreach (var item in UserController.Instance.order.transferRequests.Values)
         {
             if (item.requirer.Equals(UserController.Instance.user.id) || item.aprover.Equals(UserController.Instance.user.id))
             {
                 UIViewManager.Instance.ErrorNotification("User has pending items");
                 return;
             }
         }
         DataContainers.Order newOrder = UserController.Instance.order;
         var suborder   = newOrder.suborders[UserController.Instance.user.id];
         suborder.items = new Dictionary <string, DataContainers.OrderItem>();
         await DB.Order.UpdateOrder(UserController.Instance.order.restaurant, UserController.Instance.order.table, UserController.Instance.order.id, newOrder);
         //StartCoroutine(RestController.Instance.Payment(
         //    UserController.Instance.order.restaurant,
         //    UserController.Instance.order.table,
         //    UserController.Instance.user.id,
         //    "1",
         //    UserController.Instance.order.id,
         //    transferRequestIds
         //    ));
     });
     //throw new System.NotImplementedException();
 }
Esempio n. 9
0
 public void setOrder(DataContainers.Order iOrder)
 {
     order = iOrder;
     UIViewManager.Instance.InitializePanel("TableView");
 }