Esempio n. 1
0
 //user tests
 public List<Model.Statistic> getUserTests()
 {
     using (db = new Model.KeynerContext())
     {
         return db.StatisticSet.Where(s => s.Id_User == CurrentUser.Id).ToList();
     }
 }
Esempio n. 2
0
        private void fillUserTests()
        {
            UserTest.Clear();

            //list of all tests
            using (db = new Model.KeynerContext())
            {
                int j = 1;
                foreach (var item in db.TestSet)
                {
                    UserTest.Add(new UserTests() { IdTest = item.Id, TestName = "Тест №" + j, BestTime = item.BestTime, Mark = SetMarkStar(0) });
                    j++;
                }

                List<Model.Statistic> tmp = getUserTests();
                //filling list of user tests
                for (int i = 0; i < tmp.Count; i++)
                {
                    UserTest[i].Mark = SetMarkStar(tmp[i].Mark);
                    UserTest[i].Mistakes = tmp[i].CountMistakes;
                    UserTest[i].Time = tmp[i].Time;
                    UserTest[i].IsPassed = tmp[i].IsPassed;
                }
            }
        }
Esempio n. 3
0
 //number of all tests in db
 public int getTestCount()
 {
     using (db = new Model.KeynerContext())
     {
         return db.TestSet.Count();
     }
 }
Esempio n. 4
0
 private void SetCurrentUser(int id)
 {
     using (context = new Model.KeynerContext())
     {
         CurrentUser = context.UserSet.Find(id);
     }
 }
Esempio n. 5
0
 public string GetPass(int id)
 {
     using (context = new Model.KeynerContext())
     {
         Model.User user = context.UserSet.Find(id);
         return(user.Password);
     }
 }
Esempio n. 6
0
 public void PasswordChange(int idUser, string newpass)
 {
     using (context = new Model.KeynerContext())
     {
         Model.User user = context.UserSet.Find(idUser);
         user.Password = newpass;
         context.SaveChanges();
     }
 }
Esempio n. 7
0
        //get list of all certain monster images by monsterID
        public List <Model.MonsterLevel> MonsterImage(int id)
        {
            using (context = new Model.KeynerContext())
            {
                var list = context.MonsterLevelSet.Where(m => m.Id_Monster == id);

                return(list.ToList());
            }
        }
Esempio n. 8
0
 //check if there if already statistic for test
 public bool StatisticTestCheck(int id_test)
 {
     using (db = new Model.KeynerContext())
     {
         if (db.StatisticSet.Where(s => s.Id_Test == id_test && s.Id_User == CurrentUser.Id).ToList().Count == 1)
             return true;
         return false;
     }
 }
Esempio n. 9
0
 public Model.User getUser(int id)
 {
     using (db = new Model.KeynerContext())
     {
         return db.UserSet.Find(id);
     }
     //test
     //return new Model.User() { Name = "Lastname Firstname"};
 }
Esempio n. 10
0
 //main monster handler
 public void SetMainMonster(int idMon)
 {
     using (context = new Model.KeynerContext())
     {
         Model.User user = context.UserSet.Find(CurrentUser.Id);
         user.Id_Monster = idMon;
         CurrentUser     = user;
         context.SaveChanges();
     }
 }
Esempio n. 11
0
 //get byte array from db
 private byte[] getMonsterImageByteArray(int index)
 {
     using (db = new Model.KeynerContext())
     {
         var list = db.MonsterLevelSet.Where(l => l.Id_Monster == CurrentUser.Id_Monster).ToList();
         if (list.Count > 0)
             return list[index].NeutralImage;
         return null;
     }
 }
Esempio n. 12
0
 //all monster bougth by user
 public List <MonsterItem> getUserMonsters()
 {
     using (context = new Model.KeynerContext())
     {
         return(context.PurchaseSet.Where(p => p.Id_User == CurrentUser.Id).Join(
                    context.MonsterSet, p => p.Id_Monster, m => m.Id, (p, m) => new MonsterItem
         {
             Id_Monster = m.Id
         }).ToList());
     }
 }
Esempio n. 13
0
 //all monsters in db
 public List <MonsterItem> getAllMonsters()
 {
     using (context = new Model.KeynerContext())
     {
         return(context.MonsterSet.Join(context.ShopSet, m => m.Id, s => s.Id_Monster,
                                        (m, s) => new MonsterItem
         {
             Id_Monster = m.Id,
             Name = m.Name,
             Price = s.Cost,
         }).ToList());
     }
 }
Esempio n. 14
0
        private void Con()
        {
            keynerContext = new Model.KeynerContext();
            aar           = new Controller.AutorizAndRegistr();

            comboBoxGroup.DisplayMemberPath = "Name";
            comboBoxGroup.SelectedValue     = "Id";
            comboBoxGroup.ItemsSource       = aar.GetGroupList().OrderBy(g => g.Name);


            //comboBoxUser.DataContext = keynerContext.UserSet.ToList();
            //comboBoxUser.DisplayMemberPath = "Name";
            //comboBoxUser.SelectedValue = "Id";
        }
Esempio n. 15
0
 public bool CurrentPassCheck(int idUser, string pass)
 {
     using (context = new Model.KeynerContext())
     {
         Model.User user = context.UserSet.Find(idUser);
         if (user.Password == pass)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 16
0
        public bool payForMonster(int money)
        {
            try
            {
                using (context = new Model.KeynerContext())
                {
                    context.UserSet.Find(CurrentUser.Id).Money -= money;
                    context.SaveChanges();

                    CurrentUser = context.UserSet.Find(CurrentUser.Id);
                    return(true);
                }
            }
            catch { return(false); }
        }
Esempio n. 17
0
        public double GetUserLevel(int currentTest)
        {
            int testCount = getTestCount(); //count of all tests
            using (db = new Model.KeynerContext()) {

                int count_of_passed_tests = currentTest;  //count of passed tests

                int levelCount = db.MonsterLevelSet.Count(m => m.Id_Monster == CurrentUser.Id_Monster);     //count of levels in certain monster

                double lvlStep = (double)testCount / levelCount;   
                double index = (double)count_of_passed_tests / lvlStep;     //approximate user level

                return index;
                //return Math.Round(index, MidpointRounding.AwayFromZero);
            }
        }
Esempio n. 18
0
 public bool BuyMonster(int id_monster)
 {
     try
     {
         using (context = new Model.KeynerContext())
         {
             Model.Purchase p = new Model.Purchase();
             p.Id_Monster = id_monster;
             p.Id_User    = CurrentUser.Id;
             context.PurchaseSet.Add(p);
             context.SaveChanges();
         }
         return(true);
     }
     catch { return(false); }
 }
Esempio n. 19
0
        public void DeleteUserInfo(int id)
        {
            using (context = new Model.KeynerContext())
            {
                context.StatisticSet.RemoveRange(context.StatisticSet.Where(s => s.Id_User == id));
                context.PurchaseSet.RemoveRange(context.PurchaseSet.Where(p => p.Id_User == id));

                Model.User user = context.UserSet.Find(id);
                user.Money      = 500;
                user.Id_Monster = context.MonsterSet.Where(m => m.Name == "Monster1").First().Id;

                Model.Purchase purchase = new Model.Purchase();
                purchase.Id_Monster = user.Id_Monster;
                purchase.Id_User    = user.Id;
                context.PurchaseSet.Add(purchase);

                context.SaveChanges();
            }
        }