Calculating total sales from each member I am building a new system that is using some tables from an old system.

For each user on this new system, I need to go to the old system and total up their sales.  Currently it takes between 2-5 minutes to load.

public static List&lt;DailyTeamGoal&gt; GetListDailyTeamGoals(int teamId)
{
    string teamGoal = "";
    List&lt;ProPit_User&gt; lstProPit_User = new List&lt;ProPit_User&gt;();
    using (ProsPitEntities db = new ProsPitEntities())
    {
        // Find the team
        Team team = db.Teams.Where(x =&gt; x.teamID == teamId).FirstOrDefault();

        if (team != null)
        {
            // Grab team goal
            teamGoal = Convert.ToString(team.goal);
        }
        // Make a list of all users who are on the team
        lstProPit_User = db.ProPit_User.Where(x =&gt; x.teamID == teamId).ToList();
    }

    List&lt;DailyTeamGoal&gt; lstDailyTeamGoal = new List&lt;DailyTeamGoal&gt;();
    using (TEntities db = new TEntities())
    {
        //have to get every day of the month
        DateTime dt = DateTime.Now;
        int days = DateTime.DaysInMonth(dt.Year, dt.Month);
        decimal orderTotal = 0m;
        for (int day = 1; day &lt;= days; day++)
        {
            // For every day in the month total the sales
            DailyTeamGoal dtg = new DailyTeamGoal();
            dtg.Date = day.ToString(); //dt.Month + "/" + day; + "/" + dt.Year;
            dtg.TeamGoal = teamGoal;
            decimal orderTotalRep = 0m;
            foreach (var propit_User in lstProPit_User)
            {
                DateTime dtStartDate = Convert.ToDateTime(dt.Month + "/" + day + "/" + dt.Year);
                DateTime dtEndDate = dtStartDate.AddDays(1);
                var lstorderTotalRep = (from o in db.Orders
                                    where o.DateCompleted &gt;= dtStartDate
                                    where o.DateCompleted &lt;= dtEndDate
                                    where (o.Status == 1 || o.Status == 2)
                                    where o.Kiosk != 0
                                    where o.SalesRepID == propit_User.SalesRepID
                                    orderby o.OrderTotal descending
                                    select o.OrderTotal).ToList();

                foreach (var item in lstorderTotalRep)
                {
                    //orderTotalRep =+ item;
                    orderTotalRep += item;
                }
            }

            orderTotal += orderTotalRep;
            dtg.DailyTotal = orderTotal;

            lstDailyTeamGoal.Add(dtg);
        }
    }

    return lstDailyTeamGoal;
}


The above code will use my site to find the teamID the logged in person is on.  It will then find all members who are on that team.  For each member it finds it will calculate the total sales and then spit me back a list.  Any way to speed this up?
I won't comment about the fact that this is a static method in what's possibly a static &quot;helper&quot; class and that it would be much prettier in a service class instance... but I just did.
The method is doing way too many things.

Thing one:
// Make a list of all users who are on the team


That's one method. But there's a twist: you not only need all users on the team, but also the teamGoal figure. I'd encapsulate that in its own class:
public class TeamGoalAndUsersResult // todo: rename this class
{
    public IEnumerable&lt;ProPit_User&gt; Users { get; private set; }
    public string Goal { get; private set; }

    public TeamGoalAndUsersResult(string goal, IEnumerable&lt;ProPit_User&gt; users)
    {
        Users = users;
        Goal = goal;
    }
}

And then you can write a method/function that will return that type:
private TeamGoalAndUsersResult GetTeamGoalAndUsers(int teamId)
{
    using (ProsPitEntities db = new ProsPitEntities())
    {
        var goal = string.Empty;
        var team = db.Teams.SingleOrDefault(x =&gt; x.teamID == teamId);
        if (team != null)
        {
            goal = Convert.ToString(team.goal);
        }

        var users = db.ProPit_User.Where(x =&gt; x.teamID == teamId).ToList();
        return new TeamGoalAndUsersResult(goal, users);
    }
}



Performance Issue:
            var lstorderTotalRep = (from o in db.Orders
                                where o.DateCompleted &gt;= dtStartDate
                                where o.DateCompleted &lt;= dtEndDate
                                where (o.Status == 1 || o.Status == 2)
                                where o.Kiosk != 0
                                where o.SalesRepID == propit_User.SalesRepID
                                orderby o.OrderTotal descending
                                select o.OrderTotal).ToList();

            foreach (var item in lstorderTotalRep)
            {
                //orderTotalRep =+ item;
                orderTotalRep += item;
            }


You're doing all the computation on the client. I'd take a wild guess and say that this is where your bottleneck is. Do you really need to select, sort and materialize all orders just to sum up OrderTotal?
var total = db.Orders.Where(o =&gt; o.DateCompleted &gt;= dtStartDate
                              &amp;&amp; o.DateCompleted &lt;= dtEndDate
                              &amp;&amp; (o.Status == 1 || o.Status == 2)
                              &amp;&amp; o.Kiosk != 0
                              &amp;&amp; o.SalesRepID == user.SalesRepID)
                     .Sum(o =&gt; o.OrderTotal);

orderTotal += total;
dtg.DailyTotal = orderTotal;
dailyTeamGoals.Add(dtg);

The above doesn't sort anything, has the same criterion and performs everything on the server side, without materializing every order in the way. Also I believe if the table has all the fields used in the WHERE, in an index (guts tell me &quot;especially DateCompleted&quot;), that would further help the server-side processing, but that's something you're probably better off finding out with a profiler.