public async Task <CheckoutSummary> Checkout(string userId) { var result = new CheckoutSummary(); //call user actor to get the basket IUserActor userActor = GetUserActor(userId); Dictionary <Guid, int> basket = await userActor.GetBasket(); //get catalog client IProductCatalogService catalogService = GetProductCatalogService(); //constuct CheckoutProduct items by calling to the catalog foreach (KeyValuePair <Guid, int> basketLine in basket) { Product product = await catalogService.GetProduct(basketLine.Key); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Value }; result.Products.Add(checkoutProduct); } //generate total price result.TotalPrice = result.Products.Sum(p => p.Price); //clear user basket await userActor.ClearBasket(); await AddToHistory(result); return(result); }
public async Task <CheckoutSummary> Checkout(string userId) { var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Products = new List <CheckoutProduct>(); IUserActor userActor = GetUserActor(userId); Dictionary <Guid, int> basket = await userActor.GetBasket(); IProductCatalogService catalogService = GetProductCatalogService(); foreach (KeyValuePair <Guid, int> basketLine in basket) { Product product = await catalogService.GetProduct(basketLine.Key); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Value }; result.Products.Add(checkoutProduct); } result.TotalPrice = result.Products.Sum(p => p.Price); await userActor.ClearBasket(); await AddToHistory(result); return(result); }
public async Task <CheckoutSummary> CheckoutAsync(string userId) { var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Products = new List <CheckoutProduct>(); // Get the user basket IUserActor userActor = GetUserActor(userId); BasketItem[] basket = await userActor.GetBasket(); IProductCatalogService catalogService = GetProductCatalogService(); foreach (var item in basket) { var product = await catalogService.GetProduct(item.ProductId); var checkoutProduct = new CheckoutProduct() { Product = product, Price = product.Price, Quantity = item.Quantity }; result.Products.Add(checkoutProduct); } return(result); }
private void Subscribe(IUserActor userActor) { Log.Info($"{_user.Login}"); if (_syncSubscription != null) { throw new InvalidOperationException("Already subscribed to changes."); } var start = new ChangeSummary(); start.Add(userId: _user.UserId); // Changes streamed from the queue _syncSubscription = _syncManager.Changes .ObserveOn(TaskPoolScheduler.Default) .StartWith(start) // Run an initial sync no matter what. .Select(c => Observable.FromAsync(() => _syncContext.Sync(c)) .Catch <Unit, Exception>(LogError <Unit>)) .Concat() // Force sequential evaluation .Subscribe(); // Polling for updates _pollSubscription = _PollInterval .ObserveOn(TaskPoolScheduler.Default) .StartWith(0) .Select(_ => Observable.FromAsync(() => userActor.Sync()) .Catch <Unit, Exception>(LogError <Unit>)) .Concat() // Force sequential evaluation .Subscribe(); }
public async Task <CheckoutSummary> CheckoutAsync(string userId) { var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Products = new List <CheckoutProduct>(); IUserActor userActor = GetUserActor(userId); BasketItem[] basket = await userActor.GetBasket(); var catalogService = GetProductCatalogService(); foreach (var basketLine in basket) { var product = await catalogService.GetProduct(basketLine.ProductId); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Quantity }; result.Products.Add(checkoutProduct); } result.TotalPrice = result.Products.Sum(p => p.Price); await userActor.ClearBasket(); await AddToHistoryAsync(result); return(result); }
public async Task AddAsync( string userId, [FromBody] ApiBasketAddRequest request) { IUserActor actor = GetActor(userId); await actor.AddToBasket(request.ProductId, request.Quantity); }
public async Task <ApiBasket> Get(string userId) { IUserActor actor = GetActor(userId); Dictionary <Guid, int> products = await actor.GetBasket(); return(new ApiBasket() { UserId = userId, Items = products.Select(p => new ApiBasketItem { ProductId = p.Key.ToString(), Quantity = p.Value }).ToArray() }); }
public async Task <UserInfo> Get(int id) { IUserActor actor = this.GetActor(id); UserInfo userInfo = await actor.GetUserInfoAsync(); if (userInfo == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } else { return(userInfo); } }
public async Task <ApiBasket> Get(string userId) { IUserActor userActor = GetActor(userId); Dictionary <Guid, int> basketItems = await userActor.GetBasket(); ApiBasket apiBasket = new ApiBasket() { UserId = userId, Items = basketItems.Select(i => new ApiBasketItem { ProductId = i.Key.ToString(), Quantity = i.Value }).ToArray() }; return(apiBasket); }
public async Task <ApiBasket> GetAsync(string userId) { IUserActor actor = GetActor(userId); BasketItem[] products = await actor.GetBasket(); return(new ApiBasket() { UserId = userId, Items = products.Select(p => new ApiBasketItem { ProductId = p.ProductId.ToString(), Quantity = p.Quantity }) .ToArray() }); }
public async Task <ApiBasket> GetAsync(string userId) { IUserActor actor = GetActor(userId); // We should not use any complicated types over the wire (interfaces, generics, etc) //Dictionary<Guid, int> products = await actor.GetBasket(); BasketItem[] products = await actor.GetBasket(); return(new ApiBasket() { UserId = userId, Items = products.Select( // Convert from Product to ApiBasketItem p => new ApiBasketItem { ProductId = p.ProductId.ToString(), //Key.ToString(), Quantity = p.Quantity //Value }).ToArray() }); }
public async Task Add(string userId, [FromBody] ApiBasketAddRequest request) { try { IUserActor actor = GetActor(userId); if (request == null) { request = new ApiBasketAddRequest { ProductId = Guid.NewGuid(), Quantity = 1 }; } await actor.AddToBasket(request.ProductId, request.Quantity); } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public async Task <CheckoutSummary> Checkout(string userId) { var result = new CheckoutSummary() { Date = DateTime.UtcNow, Products = new List <CheckoutProduct>() }; IUserActor actor = CreateUserActor(userId); var cart = await actor.GetCart(); IProductCatalogService productCatalogService = GetProductCatalogService(); var products = await productCatalogService.GetAllProducts(); var totalCost = 0.0; foreach (var item in cart) { var productId = item.Key; var quantity = item.Value; var product = products.FirstOrDefault(p => p.Id == productId); if (product != null) { result.Products.Add(new CheckoutProduct() { Product = product, Quantity = quantity, Price = product.Price * quantity }); totalCost += (product.Price * quantity); } } result.TotalPrice = totalCost; //Clearing the cart since user has checkout all the products and add to history await actor.ClearCart(); await AddToHistory(result); return(result); }
public async Task <CheckoutSummary> CheckoutAsync(string userId) { //holds result of the checkout var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Products = new List <CheckoutProduct>(); //call user actor to get the basket IUserActor userActor = GetUserActor(userId); BasketItem[] basket = await userActor.GetBasket(); //get catalog client IProductCatalogService catalogService = GetProductCatalogService(); //get detailed product information for each basket item by calling product service foreach (BasketItem basketLine in basket) { Product product = await catalogService.GetProductAsync(basketLine.ProductId); var checkoutProduct = new CheckoutProduct { Product = product, Price = product.Price, Quantity = basketLine.Quantity }; result.Products.Add(checkoutProduct); } //generate total price result.TotalPrice = result.Products.Sum(p => p.Price); //clear user basket await userActor.ClearBasket(); await AddToHistoryAsync(result); return(result); }
public async Task <CheckoutSummary> CheckoutAsync(string userId) { var checkoutSummary = new CheckoutSummary(); checkoutSummary.Date = DateTime.UtcNow; checkoutSummary.Products = new List <CheckoutProduct>(); IUserActor userActor = GetUserActor(userId); var userBasketItems = await userActor.GetBasketAsync(); var basket = new Dictionary <Guid, int>(); foreach (var userBasketItem in userBasketItems) { basket.Add(userBasketItem.ProductId, userBasketItem.Quantity); } IProductCatalogService catalogService = GetProductCatalogService(); foreach (KeyValuePair <Guid, int> basketLine in basket) { Product product = await catalogService.GetProductAsync(basketLine.Key); var checkoutProduct = new CheckoutProduct { Product = product, Quantity = basketLine.Value, SubTotal = product.Price * basketLine.Value }; checkoutSummary.Products.Add(checkoutProduct); checkoutSummary.TotalPrice += checkoutProduct.SubTotal; } await AddToHistoryAsync(checkoutSummary); return(checkoutSummary); }
public async Task <CheckoutSummary> CheckoutAsync(string userId) { CheckoutSummary result = new CheckoutSummary() { Date = DateTime.UtcNow, Products = new List <CheckoutProduct>() }; // get user basket IUserActor userActor = GetUserActor(userId); var basket = await userActor.GetBasket(); IProductCatalogService catalogService = GetProductCatalogService(); // build the products using the catalog service data and the basket line items foreach (var basketItem in basket) { Product product = await catalogService.GetProductAsync(basketItem.ProductId); if (product != null) { var checkoutProduct = new CheckoutProduct() { Product = product, Price = product.Price, Quantity = basketItem.Quantity }; result.Products.Add(checkoutProduct); } } // add the current checkout summary to history (for later retrieval) await AddToHistoryAsync(result); return(result); }
public async Task Add(string userId, [FromBody] CartRequest request) { IUserActor actor = GetActor(userId); await actor.AddToCart(request.ProductId, request.Quantity); }
public async Task Delete(int id) { IUserActor actor = this.GetActor(id); await actor.DeleteUserInfoAsync(); }
public async Task Put(int id, [FromBody] UserInfo value) { IUserActor actor = this.GetActor(id); await actor.SetUserInfoAsync(value); }
public async Task Add(string userId, [FromBody] ApiBasketAddRequest request) { IUserActor userActor = GetActor(userId); await userActor.AddToBasket(new Guid(request.ProductId), request.Quantity); }
private void CreateActor(string userId) { _userActor = ActorProxy.Create <IUserActor>( actorId: new ActorId(userId), serviceUri: new Uri("fabric:/ECommerce.Sf/UserActorService")); }
public async Task Delete(string userId) { IUserActor actor = GetActor(userId); await actor.ClearBasket(); }
public async Task Add(string userId, [FromBody] BasketRequestItemViewModel request) { IUserActor actor = GetActor(userId); await actor.AddToBasket(request.ProductId, request.Quantity); }