//user tests public List<Model.Statistic> getUserTests() { using (db = new Model.KeynerContext()) { return db.StatisticSet.Where(s => s.Id_User == CurrentUser.Id).ToList(); } }
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; } } }
//number of all tests in db public int getTestCount() { using (db = new Model.KeynerContext()) { return db.TestSet.Count(); } }
private void SetCurrentUser(int id) { using (context = new Model.KeynerContext()) { CurrentUser = context.UserSet.Find(id); } }
public string GetPass(int id) { using (context = new Model.KeynerContext()) { Model.User user = context.UserSet.Find(id); return(user.Password); } }
public void PasswordChange(int idUser, string newpass) { using (context = new Model.KeynerContext()) { Model.User user = context.UserSet.Find(idUser); user.Password = newpass; context.SaveChanges(); } }
//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()); } }
//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; } }
public Model.User getUser(int id) { using (db = new Model.KeynerContext()) { return db.UserSet.Find(id); } //test //return new Model.User() { Name = "Lastname Firstname"}; }
//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(); } }
//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; } }
//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()); } }
//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()); } }
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"; }
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); } } }
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); } }
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); } }
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); } }
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(); } }