错误1可访问性不一致:参数类型' WingtipToys.Logic.ShoppingCartUpdate []'比方法' WingtipToys.Logic.ShoppingCartActions.UpdateShoppingCartDatabase(字符串,WingtipToys.Logic.ShoppingCartUpdate [])' C:\ Users \ Toshiba \ documents \ visual studio 2013 \ Projects \ WingtipToys \ WingtipToys \ Logic \ ShoppingCartActions.cs 93 21 WingtipToys
我不明白错误,请帮忙。 显示错误的代码位于给定代码UpdateShoppingCartDatabase的第一行。
namespace WingtipToys.Logic
{
public class ShoppingCartActions : IDisposable
{
public string ShoppingCartId { get; set; }
private ProductContext _db = new ProductContext();
public const string CartSessionKey = "CartId";
public void AddToCart(int id)
{
// Retrieve the product from the database.
ShoppingCartId = GetCartId();
var cartItem = _db.ShoppingCartItems.SingleOrDefault(
c => c.CartId == ShoppingCartId && c.ProductId == id);
if (cartItem == null)
{
// Create a new cart item if no cart item exists.
cartItem = new CartItem
{
ItemId = Guid.NewGuid().ToString(),
ProductId = id,
CartId = ShoppingCartId,
Product = _db.Products.SingleOrDefault
(p => p.ProductID == id),
Quantity = 1,
DateCreated = DateTime.Now
};
_db.ShoppingCartItems.Add(cartItem);
}
else
{
// If the item does exist in the cart,
// then add one to the quantity.
cartItem.Quantity++;
}
_db.SaveChanges();
}
public void Dispose()
{
if (_db != null)
{
_db.Dispose();
_db = null;
}
}
public string GetCartId()
{
if (HttpContext.Current.Session[CartSessionKey] == null)
{
if (!string.IsNullOrWhiteSpace(HttpContext.Current.User.Identity.Name))
{
HttpContext.Current.Session[CartSessionKey] = HttpContext.Current.User.Identity.Name;
}
else
{
Guid tempCartId = Guid.NewGuid();
HttpContext.Current.Session[CartSessionKey] = tempCartId.ToString();
}
}
return HttpContext.Current.Session[CartSessionKey].ToString();
}
public List<CartItem> GetCartItems()
{
ShoppingCartId = GetCartId();
return _db.ShoppingCartItems.Where(
c => c.CartId == ShoppingCartId).ToList();
}
public decimal GetTotal()
{
ShoppingCartId = GetCartId();
// Multiply product price by quantity of that product to get
// the current price for each of those products in the cart.
// Sum all product price totals to get the cart total.
decimal? total = decimal.Zero;
total = (decimal?)(from cartItems in _db.ShoppingCartItems
where cartItems.CartId == ShoppingCartId
select (int?)cartItems.Quantity * cartItems.Product.UnitPrice).Sum();
return total ?? decimal.Zero;
}
public ShoppingCartActions GetCart(HttpContext context)
{
using (var cart = new ShoppingCartActions())
{
cart.ShoppingCartId = cart.GetCartId();
return cart;
}
}
public void UpdateShoppingCartDatabase(String cardId, ShoppingCartUpdate []
CartItemUpdates)
{
using (var db = new WingtipToys.Models.ProductContext())
{
try
{
int CartItemCount = CartItemUpdates.Count();
List<CartItem> myCart = GetCartItems();
foreach (var cartItem in myCart)
{
//Iterate through all rows within shopping cart list
for(int i = 0; i < CartItemCount; i++)
{
if (cartItem.Product.ProductID == CartItemUpdates[i].ProductId)
{
if (CartItemUpdates[i].PurchaseQuantity < 1 ||
CartItemUpdates[i].RemoveItem == true)
{
RemoveItem(CartId, cartItem.ProductId);
}
else
{
UpdateItem(CartId, cartItem.ProductId,
CartItemUpdates[i].PurchaseQuantity);
}
}
}
}
}
答案 0 :(得分:0)
我认为您需要提供更多信息才能得到明确的答案。就像ShoppingCartUpdate
是什么以及如何定义它。
正如错误消息所示,您在可访问性方面存在差异。这可能意味着您的ShoppingCartUpdate
被声明为internal
(示例),因此无法在公共方法中使用它,因为程序集之外的内容可以调用UpdateShoppingCartDatabase
,但不允许访问ShoppingCartUpdate
,因为它标记为内部(再次举例,需要更多信息)