public async Task <ActionResult> CreateOrder(List <string> OrderedProducts) { //Create a new order model object Orders order = new Orders(); order.OrderedProducts = OrderedProducts; order.OrderUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; order.OrderStatus = "Created"; //Create a new order in Cosmos DB var OrderPost = await CosmosDBClient <Orders> .CreateItemAsync(order, "Orders"); //Place the Order on a Service Bus queue for fulfillment processing await ServiceBusClient.SendMessageAsync(order.ToString()); //Add the newly generated order ID to the user's order history var UserProfile = await CosmosDBClient <Users> .GetItemAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value, "Users"); UserProfile.OrderHistory.Add(OrderPost.Id); //Clear their shopping cart UserProfile.ShoppingCart.Clear(); //Update Cosmos DB with the changes var UpdatedUserProfile = await CosmosDBClient <Users> .UpdateItemAsync(UserProfile.UserId, UserProfile, "Users"); return(RedirectToAction(nameof(HomeController.Index), "Home")); }
public async Task <ActionResult> AddToCart(string ItemName, string ItemId, string ItemCategory) { //Get the user's current data (containing their shopping cart) Users UserData = await CosmosDBClient <Users> .GetItemAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value, "Users"); //Add the new item to the Shopping Cart dictionary UserData.ShoppingCart.Add(ItemName, ItemId); //Return the updated data to CosmosDB var ShoppingCartUpdate = await CosmosDBClient <Users> .UpdateItemAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value, UserData, "Users"); return(RedirectToAction(nameof(ShopController.Category), "Shop", new { category = ItemCategory })); }