I have a WebGrid in a lot of my pages that list products. And I have the following code that adds the item to the database that the user clicked on:
public bool ToCart(int userId,
string partNumber,
string productDescription,
int units,
int boxes,
decimal unitPrice,
decimal boxPrice,
decimal lineTotal,
string orderId,
DateTime dateTime,
bool isBoxed)
{
bool addedToCart = false;
try
{
Cart cart = new Cart()
{
UserId = userId,
PartNumber = partNumber,
Description = productDescription,
Units = units,
Boxes = boxes,
UnitPrice = unitPrice,
BoxPrice = boxPrice,
LineTotal = lineTotal,
OrderId = orderId,
OrderDate = dateTime,
IsBoxed = isBoxed
};
database.AddToCarts(cart);
database.SaveChanges();
addedToCart = true;
}
catch (Exception exception)
{
addedToCart = false;
Console.Write(exception.Message);
}
return addedToCart;
}
The call to this method, looks like:
ToCart(WebSecurity.CurrentUserId, PartNumber, ProductDescription, Units, Boxes, UnitPrice, BoxPrice, LineTotal, OrderId, DateTime.Now, IsBoxed)
Now I want to make this into an AJAX post. But I don't want anything fancy. I would just like to have the normal WaitCursor or BusyCursor show up while this is being added to the cart, and to display a <p>item added to cart</p>
at the top of the page, when it has been added to the cart.
How can I accomplish this when a user clicks on an item they wish to add to their cart?