private void SaveCart() { string cookieValue = string.Empty; if (CartItems != null && CartItems.Count > 0) { cookieValue = string.Join(",", CartItems.Select(x => string.Format("{0}|{1}", x.Key, x.Value))); } var cartCookie = GetResponseCookie(ShoppingCartCookieName); cartCookie.Value = cookieValue; }
public CartCacheAddEvent ToAddOrChangeEvent() { return(new CartCacheAddEvent() { Id = this.Id, Status = this.Status, Code = this.Code, Version = this.Version + 1, ClientId = this.ClientId, ShardId = this.ShardId, LanguageId = this.LanguageId, CreatedUid = this.CreatedUid, StoreId = this.StoreId, UpdatedDateUtc = this.UpdatedDateUtc, UpdatedUid = this.UpdatedUid, CreatedDateUtc = this.CreatedDateUtc, CartItems = CartItems?.Select(p => p.ToAddOrChangeEvent()).ToArray(), CartItemDetails = CartItemDetails?.Select(p => p.Value.ToAddOrChangeEvent()).ToArray(), }); }
public ActionResult UpdateAmount(List <CartItem> updateCartItems) { Thread.Sleep(1000); if (ModelState.IsValid) { foreach (var item in CartItems) { var updateCartItem = updateCartItems.FirstOrDefault(newItem => newItem.Id == item.Id); if (updateCartItem != null) { //若要購買的數量大於存貨,則將購買數量減少至存貨數量 if (updateCartItem.Amount > item.Album.Stock) { item.Amount = item.Album.Stock; } else { item.Amount = updateCartItem.Amount; } } } return(Json( new { NewCartItems = CartItems.Select(item => new { Id = item.Id, Amount = item.Amount, Price = item.Price.ToString("C") }), Total = CartItems.Sum(i => i.Price).ToString("C") })); } else { return(Json(new { Error = "更新失敗" })); } }
public double GetNumberOfDeliveries() { //I am not sure if I have to account all categories (with parents) or only th exact category. return(CartItems.Select(x => x.Value.Product.Category).Distinct().Count()); }