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> NewUser() { //Added authentication check below bool newUser = false; bool.TryParse(User.FindFirst("newUser")?.Value, out newUser);//Try and find the newUser boolean claim and put into variable if (User.Identity.IsAuthenticated) { if (newUser) { //Create user profile in Cosmos DB Users user = new Users(); user.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; user.FirstName = User.Identity.Name; user.LastName = User.FindFirst(ClaimTypes.Surname).Value; user.ShoppingCart = new Dictionary <string, string>(); user.OrderHistory = new List <string>(); var newUserProfile = await CosmosDBClient <Users> .CreateItemAsync(user, "Users"); return(RedirectToAction(nameof(HomeController.Index))); } return(RedirectToAction(nameof(HomeController.Index))); } return(RedirectToAction(nameof(HomeController.Index))); }