public static ShoppingCartTableEntity Map(ShoppingCart shoppingCart) { if (shoppingCart == null) { return(null); } var result = new ShoppingCartTableEntity(shoppingCart.UserCartId) { TrackingId = shoppingCart.TrackingId }; var shoppingCartItems = new List <ShoppingCartItemTableEntity>(); foreach (var shoppingCartItem in shoppingCart.ShoppingCartItems) { shoppingCartItems.Add(new ShoppingCartItemTableEntity() { ProductId = shoppingCartItem.ProductId, ProductName = shoppingCartItem.ProductName, ProductPrice = shoppingCartItem.ProductPrice, Quantity = shoppingCartItem.Quantity, CheckoutErrorMessage = shoppingCartItem.CheckoutErrorMessage }); } result.ShoppingCartItemsJson = new JavaScriptSerializer().Serialize(shoppingCartItems); return(result); }
public static ShoppingCart Map(ShoppingCartTableEntity shoppingCart) { if (shoppingCart == null) { return(null); } var result = new ShoppingCart(shoppingCart.RowKey) { TrackingId = shoppingCart.TrackingId }; var shoppingCartItems = new JavaScriptSerializer().Deserialize <ICollection <ShoppingCartItemTableEntity> >(shoppingCart.ShoppingCartItemsJson); foreach (var shoppingCartItem in shoppingCartItems) { result.AddItem(new ShoppingCartItem() { ProductId = shoppingCartItem.ProductId, ProductName = shoppingCartItem.ProductName, ProductPrice = shoppingCartItem.ProductPrice, Quantity = shoppingCartItem.Quantity, CheckoutErrorMessage = shoppingCartItem.CheckoutErrorMessage }); } return(result); }
public void Delete(ShoppingCartTableEntity shoppingCart) { var table = this.tableClient.GetTableReference(TableName); TableOperation deleteOperation = TableOperation.Delete(shoppingCart); table.Execute(deleteOperation); }
public void Save(ShoppingCartTableEntity shoppingCart) { var table = this.tableClient.GetTableReference(TableName); TableOperation insertOrReplaceOperation = TableOperation.InsertOrReplace(shoppingCart); table.Execute(insertOrReplaceOperation); }
public ShoppingCartTableEntity Get(string rowKey) { var table = this.tableClient.GetTableReference(TableName); var partitionKey = ShoppingCartTableEntity.CalculatePartitionKey(rowKey); TableOperation retrieveOperation = TableOperation.Retrieve <ShoppingCartTableEntity>(partitionKey, rowKey); try { TableResult retrievedResult = table.Execute(retrieveOperation); return((ShoppingCartTableEntity)retrievedResult.Result); } catch (System.Exception) { return(null); } }
public ShoppingCartTableEntity(string userId) { this.RowKey = userId; this.PartitionKey = ShoppingCartTableEntity.CalculatePartitionKey(userId); }