Пример #1
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);
                    }
                }
            }
        }
Пример #2
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();
            }
        }
Пример #3
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();
         }
     }
 }
Пример #4
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();
            }
        }
Пример #5
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();
            }
        }
Пример #6
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);
            }
        }