Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 693661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:46:36+00:00 2026-05-14T02:46:36+00:00

I have an Action that basically adds an item to a cart, the only

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:46:37+00:00Added an answer on May 14, 2026 at 2:46 am

    Your logic looks ok, though i’d consider whether or not you need to store the cart contents in a database. Unless you have a good reason i’d be tempted just to add it to the session.

    I’d also look into creating a custom model binder for the cart object, which would either pass in a new cart instance or one instantiated from the visitors cookie. That way your controller looks much simpler, e.g.:

    public ActionResult Add(Cart cart, int id)
    {
        AddItemToCart(cart, id);
        return View();
    }
    

    Also, in a RESTful application, you should ideally be using a POST method to add to the cart.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two action methods that are conflicting. Basically, I want to be able
I have a didSelectRowAtIndexPath action that adds a navigation bar and displays a new
I have a search action that returns a json response object which is basically
I have an action that basically does this: public ViewResult Save(Foo postedFoo) { Foo
Basically put, I have an action that saves a form to a database, then
So.... I have an action in my controller that basically copies the current model
I have a query that basically combines tables of actions and selects from them
I have an action that relies on User.Identity.Name to get the username of the
i have an action that return a file content. i added: Response.AddHeader(Content-Disposition, attactment; filename:\
I have an action that lets the customer preview system email messages and i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.