Skip to main content
more stuff, more things.
Source Link
Jesse C. Slicer
  • 14.2k
  • 1
  • 39
  • 52
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank;
    var startDate = Convert.ToDateTime(DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy"));
    var endDate = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("M/d/yyyy"));
    List<ProPit_User> proPitUsers;

    using (var ppdb = new ProsPitEntities())
    {
        proPitUsers = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
    }

    var teamSales = new List<TeamSales>(proPitUsers.Count());

    using (var db = new TraegerEntities())
    {
        foreach teamSales.AddRange(varproPitUsers
            .Select(user in=> proPitUsers)new
            {
            var orders   user,
                total = db.Orders.Where(o => o.DateCompleted >= startDate
                    && o.DateCompleted < endDate
                    && (o.Status == 1 || o.Status == 2)
                    && o.Kiosk != 0).AsEnumerable();

            var total = orders
                .Where(o =>&& o.SalesRepID == user.SalesRepID)
                .Select(o => (decimal?)o.OrderTotal)
  .Sum() ?? 00.0M
            .Sum(});

            teamSales.AddSelect(userTotal => new TeamSales { userId = userTotal.user.userID, TotalSales = userTotal.total }));
        }

        var rank = teamSales
            .OrderByDescending(x => x.TotalSales)
            .FindIndex(x => x.userId == CurrentUserId);

        currentUserRank = rank == -1 ? 0 : rank + 1;
    }

    return currentUserRank;
}
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank;
    var startDate = Convert.ToDateTime(DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy"));
    var endDate = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("M/d/yyyy"));
    List<ProPit_User> proPitUsers;

    using (var ppdb = new ProsPitEntities())
    {
        proPitUsers = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
    }

    var teamSales = new List<TeamSales>(proPitUsers.Count());

    using (var db = new TraegerEntities())
    {
        foreach (var user in proPitUsers)
        {
            var orders = db.Orders.Where(o => o.DateCompleted >= startDate
                && o.DateCompleted < endDate
                && (o.Status == 1 || o.Status == 2)
                && o.Kiosk != 0).AsEnumerable();

            var total = orders
                .Where(o => o.SalesRepID == user.SalesRepID)
                .Select(o => o.OrderTotal)
                .Sum();

            teamSales.Add(new TeamSales { userId = user.userID, TotalSales = total });
        }

        var rank = teamSales
            .OrderByDescending(x => x.TotalSales)
            .FindIndex(x => x.userId == CurrentUserId);

        currentUserRank = rank == -1 ? 0 : rank + 1;
    }

    return currentUserRank;
}
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank;
    var startDate = Convert.ToDateTime(DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy"));
    var endDate = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("M/d/yyyy"));
    List<ProPit_User> proPitUsers;

    using (var ppdb = new ProsPitEntities())
    {
        proPitUsers = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
    }

    var teamSales = new List<TeamSales>(proPitUsers.Count());

    using (var db = new TraegerEntities())
    {
        teamSales.AddRange(proPitUsers
            .Select(user => new
            {
                user,
                total = db.Orders.Where(o => o.DateCompleted >= startDate
                    && o.DateCompleted < endDate
                    && (o.Status == 1 || o.Status == 2)
                    && o.Kiosk != 0
                    && o.SalesRepID == user.SalesRepID).Select(o => (decimal?)o.OrderTotal).Sum() ?? 00.0M
            })
            .Select(userTotal => new TeamSales { userId = userTotal.user.userID, TotalSales = userTotal.total }));

        var rank = teamSales
            .OrderByDescending(x => x.TotalSales)
            .FindIndex(x => x.userId == CurrentUserId);

        currentUserRank = rank == -1 ? 0 : rank + 1;
    }

    return currentUserRank;
}
stuff and things.
Source Link
Jesse C. Slicer
  • 14.2k
  • 1
  • 39
  • 52
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank = 0;currentUserRank;
    var strStartDatestartDate = Convert.ToDateTime(DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy"));
    var dtStartDateendDate = Convert.ToDateTime(strStartDate);
    var strEndDate = DateTime.Now.AddDays(1).ToString("M/d/yyyy"));
    var dtEndDate =List<ProPit_User> Convert.ToDateTime(strEndDate);
proPitUsers;

    using (ProsPitEntitiesvar ppdb = new ProsPitEntities())
    using (TraegerEntities db = new TraegerEntities())
    {
        IEnumerable<ProPit_User> lstProPit_UserproPitUsers = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
    }

    List<TeamSales>var lstTeamSalesteamSales = new List<TeamSales>(lstProPit_UserproPitUsers.Count());
    
    using lstTeamSales.AddRange(lstProPit_User.Select(uservar =>db = new TeamSalesTraegerEntities())
        {
            userIdforeach =(var user.userID,
    in proPitUsers)
       TotalSales = db.Orders{
             var orders = db.Orders.Where(o => o.DateCompleted >= dtStartDatestartDate
                    && o.DateCompleted < dtEndDateendDate
                    && (o.Status == 1 || o.Status == 2)
                    && o.Kiosk != 0).AsEnumerable();

            var total = orders
      &&          .Where(o => o.SalesRepID == user.SalesRepID)
                .Select(o => o.OrderTotal ?? 0.00M)
                .Sum();
   
      }));

      teamSales.Add(new TeamSales int{ rankuserId = lstTeamSalesuser.OrderByDescending(x =>userID, x.TotalSales).FindIndex(x => x.userId= ==total CurrentUserId});
 
        if (rank == -1)}
        {
           var currentUserRankrank = 0;
        }teamSales
        else
      .OrderByDescending(x => {x.TotalSales)
            // Zero based index need to.FindIndex(x add=> onex.userId to== rankCurrentUserId);
     
        currentUserRank = rank + 1;
 == -1 ? 0 : rank + }1;
    }

    return currentUserRank;
}
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank = 0;
    var strStartDate = DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy");
    var dtStartDate = Convert.ToDateTime(strStartDate);
    var strEndDate = DateTime.Now.AddDays(1).ToString("M/d/yyyy");
    var dtEndDate = Convert.ToDateTime(strEndDate);


    using (ProsPitEntities ppdb = new ProsPitEntities())
    using (TraegerEntities db = new TraegerEntities())
    {
        IEnumerable<ProPit_User> lstProPit_User = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
        List<TeamSales> lstTeamSales = new List<TeamSales>(lstProPit_User.Count());
        lstTeamSales.AddRange(lstProPit_User.Select(user => new TeamSales
        {
            userId = user.userID,
            TotalSales = db.Orders
                .Where(o => o.DateCompleted >= dtStartDate
                    && o.DateCompleted < dtEndDate
                    && (o.Status == 1 || o.Status == 2)
                    && o.Kiosk != 0
                    && o.SalesRepID == user.SalesRepID)
                .Select(o => o.OrderTotal ?? 0.00M)
                .Sum()
        }));

        int rank = lstTeamSales.OrderByDescending(x => x.TotalSales).FindIndex(x => x.userId == CurrentUserId);
 
        if (rank == -1)
        {
            currentUserRank = 0;
        }
        else
        {
            // Zero based index need to add one to rank
            currentUserRank = rank + 1;
        }
    }

    return currentUserRank;
}
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank;
    var startDate = Convert.ToDateTime(DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy"));
    var endDate = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("M/d/yyyy"));
    List<ProPit_User> proPitUsers;

    using (var ppdb = new ProsPitEntities())
    {
        proPitUsers = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
    }

    var teamSales = new List<TeamSales>(proPitUsers.Count());
 
    using (var db = new TraegerEntities())
    {
        foreach (var user in proPitUsers)
        {
            var orders = db.Orders.Where(o => o.DateCompleted >= startDate
                && o.DateCompleted < endDate
                && (o.Status == 1 || o.Status == 2)
                && o.Kiosk != 0).AsEnumerable();

            var total = orders
                .Where(o => o.SalesRepID == user.SalesRepID)
                .Select(o => o.OrderTotal)
                .Sum();
 
            teamSales.Add(new TeamSales { userId = user.userID, TotalSales = total });
        }

        var rank = teamSales
            .OrderByDescending(x => x.TotalSales)
            .FindIndex(x => x.userId == CurrentUserId);
 
        currentUserRank = rank == -1 ? 0 : rank + 1;
    }

    return currentUserRank;
}
Added null-coalescing operator.
Source Link
Jesse C. Slicer
  • 14.2k
  • 1
  • 39
  • 52
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank = 0;
    var strStartDate = DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy");
    var dtStartDate = Convert.ToDateTime(strStartDate);
    var strEndDate = DateTime.Now.AddDays(1).ToString("M/d/yyyy");
    var dtEndDate = Convert.ToDateTime(strEndDate);


    using (ProsPitEntities ppdb = new ProsPitEntities())
    using (TraegerEntities db = new TraegerEntities())
    {
        IEnumerable<ProPit_User> lstProPit_User = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
        List<TeamSales> lstTeamSales = new List<TeamSales>(lstProPit_User.Count());
        lstTeamSales.AddRange(lstProPit_User.Select(user => new TeamSales
        {
            userId = user.userID,
            TotalSales = db.Orders
                .Where(o => o.DateCompleted >= dtStartDate
                    && o.DateCompleted < dtEndDate
                    && (o.Status == 1 || o.Status == 2)
                    && o.Kiosk != 0
                    && o.SalesRepID == user.SalesRepID)
                .Select(o => o.OrderTotal ?? 0.00M)
                .Sum()
        }));

        int rank = lstTeamSales.OrderByDescending(x => x.TotalSales).FindIndex(x => x.userId == CurrentUserId);

        if (rank == -1)
        {
            currentUserRank = 0;
        }
        else
        {
            // Zero based index need to add one to rank
            currentUserRank = rank + 1;
        }
    }

    return currentUserRank;
}
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank = 0;
    var strStartDate = DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy");
    var dtStartDate = Convert.ToDateTime(strStartDate);
    var strEndDate = DateTime.Now.AddDays(1).ToString("M/d/yyyy");
    var dtEndDate = Convert.ToDateTime(strEndDate);


    using (ProsPitEntities ppdb = new ProsPitEntities())
    using (TraegerEntities db = new TraegerEntities())
    {
        IEnumerable<ProPit_User> lstProPit_User = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
        List<TeamSales> lstTeamSales = new List<TeamSales>(lstProPit_User.Count());
        lstTeamSales.AddRange(lstProPit_User.Select(user => new TeamSales
        {
            userId = user.userID,
            TotalSales = db.Orders
                .Where(o => o.DateCompleted >= dtStartDate
                    && o.DateCompleted < dtEndDate
                    && (o.Status == 1 || o.Status == 2)
                    && o.Kiosk != 0
                    && o.SalesRepID == user.SalesRepID)
                .Select(o => o.OrderTotal)
                .Sum()
        }));

        int rank = lstTeamSales.OrderByDescending(x => x.TotalSales).FindIndex(x => x.userId == CurrentUserId);

        if (rank == -1)
        {
            currentUserRank = 0;
        }
        else
        {
            // Zero based index need to add one to rank
            currentUserRank = rank + 1;
        }
    }

    return currentUserRank;
}
public static int GetNationalRank(int teamId, int CurrentUserId)
{
    int currentUserRank = 0;
    var strStartDate = DateTime.Now.AddDays(-(DateTime.Now.Day - 1)).ToString("M/d/yyyy");
    var dtStartDate = Convert.ToDateTime(strStartDate);
    var strEndDate = DateTime.Now.AddDays(1).ToString("M/d/yyyy");
    var dtEndDate = Convert.ToDateTime(strEndDate);


    using (ProsPitEntities ppdb = new ProsPitEntities())
    using (TraegerEntities db = new TraegerEntities())
    {
        IEnumerable<ProPit_User> lstProPit_User = ppdb.ProPit_User.Where(x => x.SalesRepID != null).ToList();
        List<TeamSales> lstTeamSales = new List<TeamSales>(lstProPit_User.Count());
        lstTeamSales.AddRange(lstProPit_User.Select(user => new TeamSales
        {
            userId = user.userID,
            TotalSales = db.Orders
                .Where(o => o.DateCompleted >= dtStartDate
                    && o.DateCompleted < dtEndDate
                    && (o.Status == 1 || o.Status == 2)
                    && o.Kiosk != 0
                    && o.SalesRepID == user.SalesRepID)
                .Select(o => o.OrderTotal ?? 0.00M)
                .Sum()
        }));

        int rank = lstTeamSales.OrderByDescending(x => x.TotalSales).FindIndex(x => x.userId == CurrentUserId);

        if (rank == -1)
        {
            currentUserRank = 0;
        }
        else
        {
            // Zero based index need to add one to rank
            currentUserRank = rank + 1;
        }
    }

    return currentUserRank;
}
Source Link
Jesse C. Slicer
  • 14.2k
  • 1
  • 39
  • 52
Loading