示例#1
0
        internal UpdateResult updateDrinkStatus(OrderUserDTO order)
        {
            //TODO
            var collection = _database.GetCollection <BsonDocument>("Orders");
            //var filter = Builders<Order>
            //    .Filter
            //    .Where(x => x.id == order.order);
            //var update = Builders<Order>
            //    .Update
            //    .Set(x => x.products[0].status, order.status_drink);
            var filter = new BsonDocument("id", new BsonDocument("$eq", order.order));
            // var filter = Builders<Order>.Filter.Eq("id", order.order);
            var ordersDb = collection.Find(filter).ToList();

            if (ordersDb.Count() > 0)
            {
                var products = ordersDb.First()["products"].AsBsonArray;
                products[0]["status"] = order.status_drink;
                var update = Builders <BsonDocument> .Update.Set("products", products);

                try
                {
                    var result = collection.UpdateOne(filter, update);
                    return(result);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(null);
        }
示例#2
0
        internal List <OrderUserDTO> GetCurrentOrderStatuses()
        {
            //we get all for now, and update them all regardless of change
            // TODO - detect change and update only if there is actual change
            int totalDrinks = 4;
            var orders      = new List <OrderUserDTO>();

            for (int drinkIndex = 1; drinkIndex <= totalDrinks; drinkIndex++)
            {
                int drinkID = GetInt32Value("DRINK_" + drinkIndex + "_ID");
                if (drinkID != 0)
                {
                    var order = new OrderUserDTO();
                    order.order        = GetInt32Value("ORDER_ID");
                    order.drink        = drinkID;
                    order.status_drink = GetInt32Value("DRINK_" + drinkIndex + "_STATUS");
                    order.robot        = 1;
                    //todo logic for ingredient and later for garnish
                    orders.Add(order);
                }
            }
            return(orders);
            //OrderUserDTO orderUserDTO = new OrderUserDTO()
            //{
            //    order = 247,
            //    robot = 1,
            //    status_drink = 15,
            //    drink = 385
            //    // status_drink =
            //    // drink =
            //    // ingredient =
            //};
        }
示例#3
0
 private bool ChangeStatusDetected(OrderUserDTO order, Order orderDb)
 {
     //find the drink and check if status is changed
     foreach (var product in orderDb.products)
     {
         if (product.id == order.drink)
         {
             //found the drink, now compare statuses
             if (product.status != order.status_drink)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#4
0
 private void UpdateUserAPI(OrderUserDTO orderUserDTO)
 {
     string         json           = JsonConvert.SerializeObject(orderUserDTO);
     UserAPIService userAPIService = new UserAPIService();
     var            updateSuccess  = userAPIService.UpdateOrder(json);
 }