public async Task <IActionResult> Index() { var identityUser = await _userManager.GetUserAsync(HttpContext.User); Uyedetay kullanici = _uyedetayService.GetById(identityUser.uyeDetayId); Uye uye = _uyeService.GetById(identityUser.uyeId); string rolName = _rolService.GetById(kullanici.rol_id).rol_adi; List <Calisma> calismalar = _calismaService.GetListByUyeId(identityUser.uyeDetayId); CalismaBilgileri studyInfo = studyInfos(calismalar); List <Sinav> sinavlar = _sinavService.GetListByStatus(1); _model = new PanelModel { userDetail = new Entities.Dtos.UserDetail { uyedetay_id = identityUser.uyeDetayId, uye_id = identityUser.uyeId, kullanici_adi = identityUser.kullaniciAdi, kullanici_mail = identityUser.kullaniciMail, tema_id = 1, kayit_tarihi = kullanici.kayit_tarihi, uye_ad = uye.uye_ad, uye_soyad = uye.uye_soyad, }, rolAdi = rolName, toplamCalisilanZaman = studyInfo.toplamCalisilanZaman, sonCalisilanSinav = studyInfo.sonCalisilanSinav, sonCalismaTarihi = studyInfo.sonCalismaTarihi, sinavaCalisilanToplamZaman = studyInfo.sinavaCalisilanZaman, sinavTarihi = studyInfo.sinavTarihi, sonCalisilanDers = studyInfo.sonCalisilanDers, derseCalisilanToplamZaman = studyInfo.derseCalisilanZaman, derseSonCalisilanZaman = studyInfo.derseSonCalisilanZaman, aktifSinavlar = sinavlar }; return(View(_model)); }
public async Task <IActionResult> Index(string ad, string soyad, string kullaniciAdi, string sifre, string email) { try { if (ad == null || soyad == null) { throw new RequiredFieldsException("Ad/Soyad boş bırakılamaz!"); } else if (kullaniciAdi == null) { throw new RequiredFieldsException("Kullanıcı adı boş bırakılamaz!"); } else if (sifre == null) { throw new RequiredFieldsException("Şifre boş bırakılamaz!"); } if (await _userManager.FindByNameAsync(kullaniciAdi) != null || await _userManager.FindByEmailAsync(email) != null) //veri asp.users tablosunda var mı { throw new Exception("Bu kullanıcı zaten mevcut"); //var } else//yok { var kullanici = _uyedetayService.GetAll().Where(k => k.kullanici_adi == kullaniciAdi || k.kullanici_mail == email).FirstOrDefault(); //veri uyedetay tablosunda var mı if (kullanici != null) //var { throw new Exception("Bu kullanıcı bilgileri masaüstü uygulamasında zaten mevcut. Bu kullanıcı ile Giriş yapmayı deneyin yada farklı bilgiler ile kayıt olun!"); } else //yok { using (StudyCheckContext context = new StudyCheckContext()) { using (var transaction = context.Database.BeginTransaction())//transaction'a başla ve tabloları kilitle { try { Uye uyemiz = new Uye { uye_ad = ad, uye_soyad = soyad }; Uye createdUye = context.Uyeler.Add(uyemiz).Entity; context.SaveChanges(); Uyedetay kullanicimiz = new Uyedetay { uye_id = createdUye.id, kullanici_adi = kullaniciAdi, kullanici_sifre = sifre, kullanici_mail = email, guncelleyen_id = 1, guncelleme_tarihi = DateTime.Now, kayit_tarihi = DateTime.Now, rol_id = 1, sil_id = 1, tema_id = 1 }; var createdUyedetay = context.UyeDetay.Add(kullanicimiz).Entity; context.SaveChanges(); User createdLogin = new User { kullaniciAdi = kullaniciAdi, kullaniciSifre = sifre, kullaniciMail = email, uyeAdi = ad, uyeSoyadi = soyad, rolId = 1, uyeId = createdUye.id, uyeDetayId = createdUyedetay.id, UserName = kullaniciAdi, Email = email, PasswordHash = sifre }; IdentityResult createResult = await _userManager.CreateAsync(createdLogin, sifre); if (createResult.Succeeded) { ViewBag.IdentityResult = "Kullanıcı başarıyla oluşturuldu fakat giriş yapabilmek için onaylanmasını bekleyin(Code:06)"; } else { ViewBag.IdentityErrors = createResult; throw new Exception("Hata! İşlem iptal edildi"); } } catch (Exception ex) { transaction.Rollback();//değişiklikleri geri al throw new Exception(ex.Message); } transaction.Commit();//tablo kilitlerini aç } } } } } catch (Exception ex) { ViewBag.Exceptions = ex.Message; //red } return(View()); }
public async Task <IActionResult> KullaniciDuzenle(string uyeDetayId, string uyeId, string kayitTarihi, string kullaniciAdi, string sifre, string mail, int durum, int rol, string uyeAd, string uyeSoyad) { try { if (uyeAd == null || uyeSoyad == null) { throw new RequiredFieldsException("Üye bilgileri boş bırakılamaz!"); } else if (kullaniciAdi == null || sifre == null || mail == null) { throw new RequiredFieldsException("Kullanıcı bilgileri boş bırakılamaz!"); } var kullanici = _uyedetayService.GetAll().Where(k => k.kullanici_adi == kullaniciAdi || k.kullanici_mail == mail).ToList(); if (kullanici.Count > 1) { throw new Exception("Bu kullanıcı adı / mail zaten mevcut!"); } else { using (StudyCheckContext context = new StudyCheckContext()) { using (var transaction = context.Database.BeginTransaction()) { try { var oldUser = _uyedetayService.GetById(Convert.ToInt32(uyeDetayId)); var updatedUser = await _userManager.FindByNameAsync(oldUser.kullanici_adi); if (oldUser.kullanici_sifre != sifre) { IdentityResult passResult = await _userManager.ChangePasswordAsync(updatedUser, oldUser.kullanici_sifre, sifre); if (!passResult.Succeeded) { throw new Exception(passResult.Errors.First().Description); } } updatedUser.UserName = kullaniciAdi; updatedUser.NormalizedUserName = kullaniciAdi.ToUpper(); updatedUser.Email = mail; updatedUser.NormalizedEmail = mail.ToUpper(); updatedUser.uyeAdi = uyeAd; updatedUser.uyeSoyadi = uyeSoyad; updatedUser.kullaniciAdi = kullaniciAdi; updatedUser.kullaniciSifre = sifre; updatedUser.kullaniciMail = mail; updatedUser.rolId = rol; IdentityResult result = await _userManager.UpdateAsync(updatedUser); if (!result.Succeeded) { throw new Exception(result.Errors.First().Description); } else { Uye updatedUye = new Uye { id = Convert.ToInt32(uyeId), uye_ad = uyeAd, uye_soyad = uyeSoyad }; context.Uyeler.Update(updatedUye); context.SaveChanges(); var identityUser = await _userManager.GetUserAsync(HttpContext.User); Uyedetay updatedKullanici = new Uyedetay { id = Convert.ToInt32(uyeDetayId), kullanici_adi = kullaniciAdi, kullanici_sifre = sifre, kullanici_mail = mail, kayit_tarihi = Convert.ToDateTime(kayitTarihi), guncelleyen_id = identityUser.uyeDetayId, guncelleme_tarihi = DateTime.Now, uye_id = Convert.ToInt32(uyeId), rol_id = rol, tema_id = 1, sil_id = durum }; context.UyeDetay.Update(updatedKullanici); context.SaveChanges(); } } catch (Exception transException) { transaction.Rollback(); throw new Exception(transException.Message); } TempData["Sonuc"] = "Kullanıcı güncellendi"; transaction.Commit(); } } } } catch (Exception ex) { TempData["Exception"] = ex.Message; } return(RedirectToAction("KullaniciListesi")); }
public async Task <IActionResult> KullaniciEkle(string kullaniciAdi, string sifre, string mail, int durum, int rol, string uyeAd, string uyeSoyad) { try { if (kullaniciAdi == null || sifre == null || mail == null) { throw new RequiredFieldsException("Kullanıcı bilgileri boş bırakılamaz!"); } else if (uyeAd == null || uyeSoyad == null) { throw new RequiredFieldsException("Üye bilgileri boş bırakılamaz!"); } var user = _uyedetayService.GetAll().Where(k => k.kullanici_adi == kullaniciAdi || k.kullanici_mail == mail).FirstOrDefault(); //uyedetay tablosunda var mı if (user != null) //var { throw new Exception("Bu kullanıcı adı / mail zaten mevcut!"); } else //yok { using (StudyCheckContext context = new StudyCheckContext()) { using (var transaction = context.Database.BeginTransaction()) { try { Uye uyemiz = new Uye { uye_ad = uyeAd, uye_soyad = uyeSoyad }; Uye createdUye = context.Uyeler.Add(uyemiz).Entity; context.SaveChanges(); var identityUser = await _userManager.GetUserAsync(HttpContext.User); Uyedetay kullanicimiz = new Uyedetay { uye_id = createdUye.id, kullanici_adi = kullaniciAdi, kullanici_sifre = sifre, kullanici_mail = mail, kayit_tarihi = DateTime.Now, guncelleme_tarihi = DateTime.Now, sil_id = durum, tema_id = 1, rol_id = rol, guncelleyen_id = identityUser.uyeDetayId }; var createdKullanici = context.UyeDetay.Add(kullanicimiz).Entity; context.SaveChanges(); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message); } ViewBag.Message = "Kullanıcı Oluşturuldu"; transaction.Commit(); } } } } catch (Exception ex) { ViewBag.Exceptions = ex.Message; } _entityListModel = new EntityListModel { roller = _rolService.GetListByStatus(1) }; return(View(_entityListModel)); }
public Uyedetay UpdateUyedetay(Uyedetay uyedetay) { _uyeDetayDal.Update(uyedetay); return(uyedetay); }
public void DeleteUyedetay(Uyedetay uyedetay) { _uyeDetayDal.Delete(uyedetay); }
public Uyedetay AddUyedetay(Uyedetay uyedetay) { _uyeDetayDal.Add(uyedetay); return(uyedetay); }