/// <summary> /// delets the entry of your order. Equivalent zu DeleteOrder(). /// </summary> /// <param name="order">The order.</param> /// <param name="storageAccountUrl">The storage account URL.</param> /// <param name="storageAccountKey">The storage account key.</param> /// <param name="serviceBusConnectionString">The service bus connection string.</param> public static void MoneyDeduction(Order order, string storageAccountUrl, string storageAccountKey, string serviceBusConnectionString) { try { MoneyLog money = JsonConvert.DeserializeObject <MoneyLog>(GetDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", storageAccountUrl, storageAccountKey)); var userId = money.User.FindIndex(x => x.Name == order.Name); money.User[userId].Owe = Math.Round(money.User[userId].Owe - order.Price, 2); PutDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", JsonConvert.SerializeObject(money), "q.planbutlerupdatemoney", serviceBusConnectionString); } catch // enters if blob dont exist { List <User> users = new List <User>(); User user = new User() { Name = order.Name, Owe = order.Price }; users.Add(user); MoneyLog money = new MoneyLog() { Monthnumber = DateTime.Now.Month, Title = "moneylog", User = users }; PutDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", JsonConvert.SerializeObject(money), "q.planbutlerupdatemoney", serviceBusConnectionString); } }
/// <summary> /// /// </summary> /// <param name="order"></param> public static async Task <HttpStatusCode> UploadMoney(Order order, string storageAccountUrl, string storageAccountKey, string serviceBusConnectionString) { try { MoneyLog money = JsonConvert.DeserializeObject <MoneyLog>(GetDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", storageAccountUrl, storageAccountKey)); var _money = money; var userId = _money.User.FindIndex(x => x.Name == order.Name); if (userId == -1) // enters if the current user is not in the list { User user = new User() { Name = order.Name, Owe = order.Price }; _money.User.Add(user); HttpStatusCode status = await PutDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", JsonConvert.SerializeObject(_money), "q.planbutlerupdatemoney", serviceBusConnectionString); return(status); } else // enters if everything is normal { var newOwe = money.User[userId].Owe; newOwe += order.Price; _money.User[userId].Owe = newOwe; HttpStatusCode status = await PutDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", JsonConvert.SerializeObject(_money), "q.planbutlerupdatemoney", serviceBusConnectionString); return(status); } } catch // enters if blob dont exist { List <User> users = new List <User>(); User user = new User() { Name = order.Name, Owe = order.Price }; users.Add(user); MoneyLog money = new MoneyLog() { Monthnumber = DateTime.Now.Month, Title = "moneylog", User = users }; HttpStatusCode status = await PutDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", JsonConvert.SerializeObject(money), "q.planbutlerupdatemoney", serviceBusConnectionString); return(status); } }