Ejemplo n.º 1
0
        internal WorldScore UpdateWholeEntry(FirstEntry item)
        {
            if (item.UId != 0)
            {
                using (bnbEntities ctx = new bnbEntities())
                {
                    User chkUser = ctx.User.Where(x => x.UId == item.UId).FirstOrDefault();

                    if (chkUser != null)
                    {
                        chkUser.BallCount = item.BallCount;
                        chkUser.LLimit    = item.LLimit;
                        chkUser.Score     = item.Score;
                        chkUser.TSpeed    = item.TSpeed;
                        chkUser.Version   = item.Version;
                        chkUser.Stages    = item.Stages;
                        chkUser.Starts    = item.Stars;
                        if (!string.IsNullOrEmpty(item.Location))
                        {
                            chkUser.Location = item.Location;
                        }
                        if (!string.IsNullOrEmpty(item.FbId))
                        {
                            chkUser.FbId = item.FbId;
                        }
                        chkUser.RankScore = CalculateRankScore(chkUser);
                        ctx.SaveChanges();
                    }
                }
            }
            return(GetTopTen(item.UId));
        }
Ejemplo n.º 2
0
        internal GameVersion GetVersion()
        {
            GameVersion outcome = new GameVersion();

            using (bnbEntities bnbEntities = new bnbEntities())
            {
                outcome = bnbEntities.GameVersions.OrderByDescending(x => x.Id).FirstOrDefault();
            }
            return(outcome);
        }
Ejemplo n.º 3
0
 public void FixRanks()
 {
     using (bnbEntities bnbEntities = new bnbEntities())
     {
         List <User> list = bnbEntities.User.ToList <User>();
         foreach (User current in list)
         {
             int value = this.CalculateRankScore(current);
             current.RankScore = new int?(value);
             bnbEntities.SaveChanges();
         }
     }
 }
Ejemplo n.º 4
0
        internal WorldScore WholeEntry(FirstEntry item)
        {
            if (item.UId == 0)
            {
                using (bnbEntities ctx = new bnbEntities())
                {
                    User chkUser = null;
                    if (!string.IsNullOrEmpty(item.FbId))
                    {
                        var fbCheck = ctx.User.Where(x => x.FbId == item.FbId).FirstOrDefault();
                        if (fbCheck != null)
                        {
                            chkUser = fbCheck;
                        }
                    }



                    if (chkUser == null)
                    {
                        var NameCheck = ctx.User.Where(x => x.Name == item.Name).FirstOrDefault();
                        if (NameCheck != null)
                        {
                            chkUser = NameCheck;
                        }


                        if (chkUser == null)
                        {
                            User newEnt = new User();
                            newEnt.Name      = item.Name;
                            newEnt.Guid      = item.Guid;
                            newEnt.BallCount = item.BallCount;
                            newEnt.LLimit    = item.LLimit;
                            newEnt.Score     = item.Score;
                            newEnt.TSpeed    = item.TSpeed;
                            newEnt.Version   = item.Version;
                            newEnt.Stages    = item.Stages;
                            newEnt.Starts    = item.Stars;
                            if (!string.IsNullOrEmpty(item.Location))
                            {
                                newEnt.Location = item.Location;
                            }
                            if (!string.IsNullOrEmpty(item.FbId))
                            {
                                newEnt.FbId = item.FbId;
                            }
                            newEnt.RankScore = CalculateRankScore(newEnt);
                            ctx.User.Add(newEnt);
                            ctx.SaveChanges();
                            item.UId = newEnt.UId;
                        }
                        else
                        {
                            return(new WorldScore()
                            {
                                Msg = "Try Another Name"
                            });
                        }
                    }
                    else
                    {
                        if (chkUser.Score < item.Score &&
                            chkUser.Stages < item.Stages)
                        {
                        }
                    }
                }
            }
            return(GetTopTen(item.UId));
        }
Ejemplo n.º 5
0
        internal WorldScore GetTopTen(int?uid = 0)
        {
            WorldScore ret = new WorldScore();

            ret.TopTen = new List <RankUser>();
            ret.UId    = uid.Value;

            List <User> allData = new List <User>();

            using (bnbEntities ctx = new bnbEntities())
            {
                allData = ctx.User.OrderByDescending(x => x.RankScore).ToList();
                //ret.TopTen =
            }

            var maxCount = (allData.Count < 7) ? allData.Count : 7;

            for (int i = 0; i < maxCount; i++)
            {
                var item = ConvertUserToRank(allData[i]);
                item.Rank = i + 1;
                ret.TopTen.Add(item);
            }

            if (uid.HasValue && uid > 0)
            {
                ret.CurrentUserList = new List <RankUser>();
                for (int i = 0; i < maxCount; i++)
                {
                    if (allData[i].UId == uid.Value)
                    {
                        if (i == 0)
                        { // for topper
                            var item = ConvertUserToRank(allData[i]);
                            item.Rank          = i + 1;
                            item.IsCurrentUser = true;
                            ret.CurrentUserList.Add(item);

                            for (int x = i + 1; x < i + 4; x++)
                            {
                                if (x < maxCount)
                                {
                                    item      = ConvertUserToRank(allData[x]);
                                    item.Rank = x + 1;
                                    ret.CurrentUserList.Add(item);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;
                        }
                        else if (i == maxCount - 1)
                        {// for last
                            var item = ConvertUserToRank(allData[i]);
                            for (int x = i - 4; x < i; x++)
                            {
                                if (x < maxCount)
                                {
                                    item      = ConvertUserToRank(allData[x]);
                                    item.Rank = x + 1;
                                    ret.CurrentUserList.Add(item);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            item               = ConvertUserToRank(allData[i]);
                            item.Rank          = i;
                            item.IsCurrentUser = true;
                            ret.CurrentUserList.Add(item);

                            break;
                        }
                        else if (i > 0)
                        {// for in bw
                            var item = ConvertUserToRank(allData[i - 1]);
                            item.Rank = i;
                            ret.CurrentUserList.Add(item);

                            item               = ConvertUserToRank(allData[i]);
                            item.Rank          = i + 1;
                            item.IsCurrentUser = true;
                            ret.CurrentUserList.Add(item);

                            for (int x = i + 1; x < i + 3; x++)
                            {
                                if (x < maxCount)
                                {
                                    item      = ConvertUserToRank(allData[x]);
                                    item.Rank = x + 1;
                                    ret.CurrentUserList.Add(item);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
            }

            //int maxStars = ret.TopTen[0]
            return(ret);
        }