public async Task <IActionResult> Update(int id, [FromBody] ProfilYazDto yazDto) { return(await KullaniciVarsaCalistir <IActionResult>(async() => { if (!ModelState.IsValid) { return BadRequest(ModelState); } var userFromRepo = await kullaniciRepo.BulAsync(aktifKullaniciNo); if (userFromRepo == null) { return NotFound($"{id} numaralı kullanıcı bulunamadı!"); } if (aktifKullaniciNo != userFromRepo.Id) { return Unauthorized(); } KullaniciMappers.Kopyala(yazDto, userFromRepo); userFromRepo.SonAktifOlmaTarihi = DateTime.Now; if (await kullaniciRepo.KaydetAsync()) { return Ok(Sonuc.Tamam); } else { throw new Exception($"{id} numaralı kullanıcı bilgileri kaydedilemedi!"); } })); }
public async Task <IActionResult> Update(int id, [FromBody] KullaniciYazDto yazDto) { return(await KullaniciVarsaCalistir <IActionResult>(async() => { if (!ModelState.IsValid) { return BadRequest(ModelState); } var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var userFromRepo = await kullaniciRepo.BulAsync(currentUserId); if (userFromRepo == null) { return NotFound($"{id} numaralı kullanıcı bulunamadı!"); } if (currentUserId != userFromRepo.Id) { return Unauthorized(); } KullaniciMappers.Kopyala(yazDto, userFromRepo); if (await kullaniciRepo.KaydetAsync()) { return NoContent(); } else { throw new Exception($"{id} numaralı kullanıcı bilgileri kaydedilemedi!"); } })); }
public async Task <IActionResult> Update(int id, [FromBody] ProfilYazDto yazDto) { return(await KullaniciVarsaCalistir <IActionResult>(async() => { Sonuc sonuc = null; var userFromRepo = await repo.BulAsync(aktifKullaniciNo); if (userFromRepo == null) { sonuc = Sonuc.Basarisiz(new Hata[] { new Hata { Kod = "", Tanim = $"{id} numaralı kullanıcı bulunamadı!" } }); return Ok(sonuc); } if (aktifKullaniciNo != userFromRepo.Id) { sonuc = Sonuc.Basarisiz(new Hata[] { new Hata { Kod = "", Tanim = "Sizin dışınızdaki kullanıcıyı değiştirme yetkiniz yok!" } }); return Ok(sonuc); } KullaniciMappers.Kopyala(yazDto, userFromRepo); if (await repo.KaydetAsync()) { sonuc = Sonuc.Tamam; sonuc.Mesajlar[0] = "Kullanıcı bilgileri kaydedildi."; return Ok(); } sonuc = Sonuc.Basarisiz(new Hata[] { new Hata { Kod = "", Tanim = $"{id} numaralı kullanıcı bilgileri kaydedilemedi!" } }); return Ok(sonuc); })); }