Exemplo n.º 1
0
 public List <Model.Group> GetGroupList()
 {
     using (keyCont = new KeynerContext())
     {
         return(keyCont.GroupSet.ToList());
     }
 }
Exemplo n.º 2
0
 private void GetCurrentTest(int id)
 {
     using (context = new KeynerContext())
     {
         currentTest = context.TestSet.Find(id);
     }
 }
Exemplo n.º 3
0
        public BitmapImage GetMonster(int id_user, int mood)
        {
            BitmapImage  im = new BitmapImage();
            User         user;
            MonsterLevel currentMonster;

            using (context = new KeynerContext())
            {
                user           = context.UserSet.Find(id_user);
                currentMonster = context.MonsterLevelSet.Where(m => m.Id_Monster == user.Id_Monster).ToList()[0];
            }
            switch (mood)
            {
            case 1:
                return(ImageConvert.Convert(currentMonster.HappyImage));

            case 2:
                return(ImageConvert.Convert(currentMonster.NeutralImage));

            case 3:
                return(ImageConvert.Convert(currentMonster.ReadyImage));

            case 4:
                return(ImageConvert.Convert(currentMonster.SadImage));

            default:
                return(ImageConvert.Convert(currentMonster.NeutralImage));
            }
        }
Exemplo n.º 4
0
        ///якщо тест вже існує апдейтимо його статистику
        public void UpdateStatisctic(int id_user, int time, int mistakes, int mark, bool is_passed)
        {
            Statistic statistic;

            using (context = new KeynerContext())
            {
                statistic = context.StatisticSet.Where(s => s.Id_User == id_user && s.Id_Test == currentTest.Id).ToList()[0];

                if (!statistic.IsPassed && is_passed)
                {
                    //якщо тест був не пройденний і ми його пройшли
                    statistic.IsPassed      = is_passed;
                    statistic.Time          = time;
                    statistic.Mark          = mark;
                    statistic.CountMistakes = mistakes;
                    context.SaveChanges();

                    BesTime(time);
                    SetUserMoney(id_user, mark);
                }
                else if (time <= statistic.Time && mistakes <= statistic.CountMistakes && mark >= statistic.Mark)
                {
                    statistic.Time          = time;
                    statistic.Mark          = mark;
                    statistic.CountMistakes = mistakes;
                    context.SaveChanges();

                    ///найкращий час в пройденому тесті
                    if (is_passed)
                    {
                        BesTime(time);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void SetUserMoney(int id_us, int mark)
        {
            using (context = new KeynerContext())
            {
                User user = context.UserSet.Find(id_us);
                user.Money += GetMoney(mark);

                context.SaveChanges();
            }
        }
Exemplo n.º 6
0
 ///найкращий час в тесті
 private void BesTime(int time)
 {
     if (currentTest.BestTime > time || currentTest.BestTime == 0)
     {
         using (context = new KeynerContext())
         {
             context.TestSet.Where(t => t.Id == currentTest.Id).First().BestTime = time;
             context.SaveChanges();
         }
     }
 }
Exemplo n.º 7
0
        //setting first user monster
        private void MakeFirstPurchase(int id_user, int id_monster)
        {
            using (keyCont = new KeynerContext())
            {
                Model.Purchase purchase = new Purchase();
                purchase.Id_Monster = id_monster;
                purchase.Id_User    = id_user;

                keyCont.PurchaseSet.Add(purchase);
                keyCont.SaveChanges();
            }
        }
Exemplo n.º 8
0
 public bool CheckName(string name)
 {
     using (keyCont = new KeynerContext())
     {
         foreach (var item in keyCont.UserSet.ToList())
         {
             if (item.Name == name)
             {
                 return(true);
             }
         }
         return(false);
     }
 }
Exemplo n.º 9
0
 public bool GetPass(int id, string p)
 {
     using (keyCont = new KeynerContext())
     {
         Model.User user = keyCont.UserSet.Find(id);
         if (user.Password == p)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 10
0
        public int GetSpeed(int id_user, int finishTime)
        {
            int time  = finishTime;
            int count = 1;
            List <Statistic> statistic;

            using (context = new KeynerContext())
            { statistic = context.StatisticSet.Where(s => s.Id_User == id_user && s.Id_Test == currentTest.Id).ToList(); }

            foreach (var item in statistic)
            {
                time += item.Time;
                count++;
            }
            return(time / count);
        }
Exemplo n.º 11
0
 public int GetIdUser(string name, string pass)
 {
     using (keyCont = new KeynerContext())
     {
         foreach (var item in keyCont.UserSet)
         {
             if (item.Name == name)
             {
                 if (item.Password == pass)
                 {
                     return(item.Id);
                 }
             }
         }
         return(0);
     }
 }
Exemplo n.º 12
0
 public string GetText()
 {
     collection.Clear();
     using (context = new KeynerContext())
     {
         text = currentTest.Text;
     }
     //RepeatCount = 3;
     //for (int i = 0; i < RepeatCount; i++)
     //{
     for (int j = 0; j < text.Length; j++)
     {
         collection.Add(text[j]);
     }
     //}
     return(text);
 }
Exemplo n.º 13
0
        ///finishTime!!!!     ще не проходили тест - створюємо статистику
        public void FillNewStatistic(int id_user, int time, bool is_passed, int mistakes, int mark)
        {
            Statistic statistic = new Statistic();

            statistic.Id_User       = id_user;
            statistic.Id_Test       = currentTest.Id;
            statistic.Time          = time;
            statistic.Mark          = mark;
            statistic.IsPassed      = is_passed;
            statistic.CountMistakes = mistakes;
            ///найкращий час в пройденому тесті
            if (is_passed)
            {
                BesTime(time);
                SetUserMoney(id_user, mark);
            }
            using (context = new KeynerContext())
            {
                context.StatisticSet.Add(statistic);
                context.SaveChanges();
            }
        }
Exemplo n.º 14
0
        public void AddUser(string name, string pass, int group)
        {
            using (keyCont = new KeynerContext())
            {
                User user = new User();
                user.Name       = name;
                user.Password   = pass;
                user.Id_Group   = group;
                user.Id_Monster = keyCont.MonsterSet.Where(m => m.Name == "Monster1").ToList()[0].Id;
                user.Money      = 500;

                keyCont.UserSet.Add(user);

                //Purchase purchase = new Purchase();
                //purchase.Id_Monster = user.Id_Monster;
                //purchase.Id_User = user.Id;
                //keyCont.PurchaseSet.Add(purchase);

                keyCont.SaveChanges();

                MakeFirstPurchase(user.Id, user.Id_Monster);
            }
        }