public async Task <ActionResult> GetTest() { // GetUser(userModel.kullaniciAdi); var boslink = _context.Testler.Where(t => t.TestLinki == null); _context.RemoveRange(boslink); _context.SaveChanges(); var currentUsername = HttpContext.Session.GetString("username"); ViewData["username"] = currentUsername; var testModel = await _context.Testler.Where(t => t.TestSahibi.Equals(currentUsername)).ToListAsync(); foreach (var a in testModel) { a.TestCozulmeSayisi = _context.CozulenTest.Where(c => c.testId == a.TestId).Count(); } _context.SaveChanges(); if (currentUsername == null) { return(RedirectToAction("noLogin", "Login", new { url = "http://kankammisin.tashteam/test/gettest" })); } var s = new HttpClient(); return(View(testModel.ToList())); }
public async Task <ActionResult> AnonymusRegister(UserForRegisterDto userForRegisterDto) { var cozen = HttpContext.Session.GetString("uuid"); if (userForRegisterDto.Email == null || userForRegisterDto.KullaniciAdi == null || userForRegisterDto.ad == null || userForRegisterDto.soyad == null) { ModelState.AddModelError("kullanicihata", "Lütfen Heryeri Doldurunuz"); return(RedirectToAction("Index", "Register")); } var hasKullaniciAdi = _context.Users.Where(u => u.KullaniciAdi == userForRegisterDto.KullaniciAdi); if (hasKullaniciAdi.Count() != 0) { ModelState.AddModelError("kullanicihata", "Kullanıcı Adı Bulunmaktadır"); return(RedirectToAction("Index", "Register")); } byte[] passwordSalt, passworHash; HashingHelper.CreatePasswordHash(userForRegisterDto.password, out passworHash, out passwordSalt); var user = new UserdbModel { KullaniciAdi = userForRegisterDto.KullaniciAdi, Email = userForRegisterDto.Email, Ad = userForRegisterDto.ad, Soyad = userForRegisterDto.soyad, SifreHash = passworHash, SifreSalt = passwordSalt, Status = true }; _context.Users.Add(user); _context.SaveChanges(); var current = _context.Users.Where(u => u.KullaniciAdi == userForRegisterDto.KullaniciAdi).FirstOrDefault(); UserOperationClaim userOperation = new UserOperationClaim { UserId = current.ID, OperationClaimId = 2 }; _context.UserOperationClaims.Add(userOperation); _context.SaveChanges(); var result = _context.Users.Where(u => u.KullaniciAdi == user.KullaniciAdi) as UserdbModel; HttpContext.Session.SetString("username", user.KullaniciAdi); _jwtHelper = new JwtHelper(Configuration); var claims = _efUser.GetClaims(user); var token = _jwtHelper.CreateToken(user, claims); HttpContext.Session.SetString("JWToken", token.Token); _context.CozulenTest.Where(c => c.cozen == cozen).FirstOrDefault().cozen = user.KullaniciAdi; _context.Istatistik.Where(c => c.cozen == cozen).FirstOrDefault().cozen = user.KullaniciAdi; _context.SaveChanges(); HttpContext.Session.Remove("uuid"); return(RedirectToAction("GetTest", "Test")); }
public ActionResult Aistatistik(UserClaimModel userClaimModel) { var a = _kankammisinContext.UserOperationClaims.Where(k => k.UserId == userClaimModel.userModel.Id); if (a.FirstOrDefault().OperationClaimId == 2) { a.FirstOrDefault().OperationClaimId = 1; userClaimModel.kullaniciTuru = "Admin"; } else { a.FirstOrDefault().OperationClaimId = 2; userClaimModel.kullaniciTuru = "Kullanici"; } _kankammisinContext.SaveChanges(); var u = _kankammisinContext.Users.Find(userClaimModel.userModel.Id); userClaimModel.userModel.kullaniciAdi = u.KullaniciAdi; userClaimModel.userModel.ad = u.Ad; userClaimModel.userModel.soyad = u.Soyad; userClaimModel.userModel.email = u.Email; userClaimModel.userModel.Id = u.ID; return(RedirectToAction("Admin", "Admin")); }
public async Task <ActionResult> Index() { _context.RemoveRange(_context.CozulenTest.Where(c => c.cozen.Contains("anonim")).ToList()); _context.RemoveRange(_context.Istatistik.Where(c => c.cozen.Contains("anonim")).ToList()); _context.SaveChanges(); var currentUsername = HttpContext.Session.GetString("username"); ViewData["username"] = currentUsername; var istatistikModels = await _context.Istatistik.Where(i => i.cozulen == currentUsername).ToListAsync(); return(View(istatistikModels)); }
public void ClaimAdds(UserForRegisterDto userForRegisterDto) { var k = _userService.GetByUsername(userForRegisterDto.KullaniciAdi); UserOperationClaim userOperationClaim = new UserOperationClaim { UserId = k.ID, OperationClaimId = 1 }; context.UserOperationClaims.Add(userOperationClaim); context.SaveChanges(); }
public IActionResult setTest(TestModel testModels) { var currentUsername = HttpContext.Session.GetString("username"); ViewData["username"] = currentUsername; if (testModels.TestSoruSayisi > 12 || testModels.TestSoruSayisi < 3) { ModelState.AddModelError("sorusayisi", "Min Soru Sayısı 3, Max Soru Sayısı 12 Olmalıdır"); return(View()); } if (testModels.TestAdi.IsNullOrEmpty()) { ModelState.AddModelError("sorusayisi", "Lütfen Testinize Bir İsim Veriniz"); return(View()); } // string testLinki = "https://localhost:44310/Test/TestCoz?link=" + currentUsername + "-" + testModels.TestId; TestModel testModel = new TestModel { TestCozulmeSayisi = 0, TestSahibi = currentUsername, TestSoruSayisi = testModels.TestSoruSayisi, TestAdi = testModels.TestAdi }; ExistCheck e = new ExistCheck(_context); if (e.testExist(testModels.TestAdi, currentUsername)) { ModelState.AddModelError("testExist", "Aynı İsimde Testiniz Bulunmaktadır."); return(setTest()); } _context.Testler.Add(testModel); _context.SaveChanges(); HttpContext.Session.SetInt32("baslik", testModel.TestId); return(RedirectToAction("YeniTest", "TestOlustur", new { soruSayisi = testModels.TestSoruSayisi }));; }
public IActionResult Index(UserdbModel userModel) { var currentUsername = HttpContext.Session.GetString("username"); userModel.KullaniciAdi = currentUsername; ViewData["username"] = currentUsername; if (userModel.Ad.IsNullOrEmpty() || userModel.Soyad.IsNullOrEmpty() || userModel.Email.IsNullOrEmpty()) { ModelState.AddModelError("bos", "Lütfen Boş Bırakmayınız"); return(View(userModel)); } _context.Entry(userModel).State = EntityState.Modified; _context.SaveChanges(); return(View(userModel)); }
public void TestSil(TestModel testModel) { c.Remove <TestModel>(testModel); var soru = c.Sorular.Where(s => s.testId == testModel.TestId).ToList(); var ct = c.CozulenTest.Where(ct => ct.testId == testModel.TestId).FirstOrDefault(); var ista = c.Istatistik.Where(i => i.testAdi == testModel.TestAdi) .Where(i => i.cozulen == testModel.TestSahibi).FirstOrDefault(); c.RemoveRange(soru); if (ct != null) { c.Remove <CozulenTestModel>(ct); c.Remove <IstatistikModel>(ista); } c.SaveChanges(); }
public async Task <ActionResult> Index(LoginsModel loginsModel) { var cozen = HttpContext.Session.GetString("uuid"); if (loginsModel.password.IsNullOrEmpty() || loginsModel.id.IsNullOrEmpty()) { ModelState.AddModelError("kullanicihata", "Lütfen Boş Bırakmayınız"); return(View()); } var userToCheck = _context.Users.Where(u => u.KullaniciAdi == loginsModel.id).FirstOrDefault(); if (userToCheck == null) { ModelState.AddModelError("kullanicihata", "Kullanıcı Bulunamadı"); return(View()); } else { if (!HashingHelper.VerifyPasswordHash(loginsModel.password, userToCheck.SifreHash, userToCheck.SifreSalt)) { ModelState.AddModelError("kullanicihata", "sifre yanlış"); return(View()); } else { var result = _context.Users.Where(u => u.KullaniciAdi == loginsModel.id).FirstOrDefault(); HttpContext.Session.SetString("username", loginsModel.id); var claims = _efUser.GetClaims(result); _jwtHelper = new JwtHelper(Configuration); var token = _jwtHelper.CreateToken(result, claims); HttpContext.Session.SetString("JWToken", token.Token); var intentUrl = HttpContext.Session.GetString("intentUrl"); HttpContext.Session.Remove("intentUrl"); if (!intentUrl.IsNullOrEmpty()) { Redirect(intentUrl); } if (!cozen.IsNullOrEmpty()) { var c = _context.Istatistik.Where(a => a.cozen == loginsModel.id) .Where(c => c.testAdi == HttpContext.Session.GetString("testadi")).FirstOrDefault(); HttpContext.Session.Remove("testadi"); if (c != null) { string hata1 = "Bu Testi Daha Önce Çözmüşsünüz."; return(RedirectToAction("Error", "Error", new { hata = hata1 })); } _context.CozulenTest.Where(c => c.cozen == cozen).FirstOrDefault().cozen = loginsModel.id; _context.Istatistik.Where(c => c.cozen == cozen).FirstOrDefault().cozen = loginsModel.id; _context.SaveChanges(); HttpContext.Session.Remove("uuid"); } return(RedirectToAction("GetTest", "Test")); } } }