If cookie found, get data, else create cookie, is this good logic?

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-03-16T21:25:58Z Indexed on 2010/03/16 21:51 UTC
Read the original article Hit count: 133

Filed under:
|
|

I have an Action that basically adds an item to a cart, the only way the cart is known is by checking the cookie, here is the flow of logic, please let me know if you see any issue...

/order/add/[id] is called via GET

action checks for cookie, if no cookie found, it makes a new cart, writes the identifier to the cookie, and adds the item to the database with a relation to the cart created

if cookie is found, it gets the cart identifier from the cookie, gets the cart object, adds the item to the database with a relation to the cart found

so it's basically like...

action add(int id){

if(cookie is there)
    cart = getcart(cookievalue)
else
    cart = makecart()
    createcookie(cart.id)

additemtocart(cart.id, id)

return "success";
}

Seem right? I can't really thing of another way that would make sense.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about cookies