Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MVC Help

  • 10-08-2013 6:55pm
    #1
    Registered Users, Registered Users 2 Posts: 1,521 ✭✭✭


    Hi,
    I'm developing a sample Internet App using MVC4

    I have a Local SQL database connected, and within it is a Decimal class, Price.

    So users can enter the price, and it will then be displayed on the Index screen.

    Could someone help me out with coding a way to have a total of all the 'Price's entered so far. So if there are two entries, at 10 and 5, the total would display 15.


Comments

  • Registered Users, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


    mcw92 wrote: »
    Hi,
    I'm developing a sample Internet App using MVC4

    I have a Local SQL database connected, and within it is a Decimal class, Price.

    So users can enter the price, and it will then be displayed on the Index screen.

    Could someone help me out with coding a way to have a total of all the 'Price's entered so far. So if there are two entries, at 10 and 5, the total would display 15.

    You have a couple of options, do you want the DB to return the total or it to return all the prices and you sum it within the app?
    If you are only showing the total then I'd suggest summing it within the DB.


  • Registered Users, Registered Users 2 Posts: 1,521 ✭✭✭mcw92


    GreeBo wrote: »
    You have a couple of options, do you want the DB to return the total or it to return all the prices and you sum it within the app?
    If you are only showing the total then I'd suggest summing it within the DB.

    Ya i didn't think of doing the total within the DB itself.

    Is there a way i can do this fairly straight forward?
    Could i do this through adding a new 'Total' to the model, then use code migrations to update the DB ?

    EDIT
    Sorry i misunderstood, no i want to show the individual prices, and then also the total. So potentially users could see the total price.

    This is how it would be really,

    Price Paid
    11
    13
    10

    Total
    34


    The Price entered are 'Decimal' format,.


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Are you using Entity Framework, or SQL Stored Procedures invoked from you VB/C# code.

    If it's the former then you can using the Sum Linq operator very easily.

    var total = products.Sum(p=>p.PricePaid);


Advertisement