コード例 #1
0
        public IActionResult BegeniDurumunuGuncelle(int id, bool begenildiMi)
        {
            try
            {
                string userId = User.GetUserId();
                var    begeni = new KullaniciSoz()
                {
                    GuzelSozId = id, KullaniciId = userId
                };

                if (begenildiMi)
                {
                    if (!_db.KullaniciSozler.Contains(begeni))
                    {
                        _db.KullaniciSozler.Add(begeni);
                    }
                }
                else
                {
                    if (_db.KullaniciSozler.Contains(begeni))
                    {
                        _db.KullaniciSozler.Remove(begeni);
                    }
                }
                _db.SaveChanges();
                return(new EmptyResult());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
コード例 #2
0
 public IActionResult begenidurumuguncelle(int id, bool begenildiMi)
 {
     try
     {
         string userId = User.GetUserId();
         var    begeni = new KullaniciSoz()
         {
             GuzelSozId = id, KullaniciId = userId
         };
         if (begenildiMi)
         {
             if (!_dbContext.KullaniciSozler.Contains(begeni))
             {
                 _dbContext.KullaniciSozler.Add(begeni);
             }
         }
         else
         {
             if (_dbContext.KullaniciSozler.Contains(begeni))
             {
                 _dbContext.KullaniciSozler.Remove(begeni);
             }
         }
         //_dbContext.Entry(begeni).State = begenildiMi ? EntityState.Added : EntityState.Deleted;
         _dbContext.SaveChanges();
         return(new EmptyResult());
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
コード例 #3
0
        public IActionResult BegeniDurumunuGuncelle(int id, bool begenildiMi)
        {
            try
            {
                string userId = User.GetUserId();
                // Kullanici kul = _db.Users.Find(userId);
                var begeni = new KullaniciSoz()
                {
                    GuzelSozId = id, KullaniciId = userId
                };

                if (begenildiMi)
                {
                    if (!_db.KullaniciSozler.Contains(begeni))
                    {
                        _db.KullaniciSozler.Add(begeni);
                    }
                }
                else
                {
                    if (_db.KullaniciSozler.Contains(begeni))
                    {
                        _db.KullaniciSozler.Remove(begeni);
                    }
                }
                //begeni durumu true gelirse ekle yoksa kaldır
                //_db.Entry(begeni).State = begenildiMi ? EntityState.Added : EntityState.Deleted;
                _db.SaveChanges();
                return(new EmptyResult());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
コード例 #4
0
 public IActionResult BegeniDurumuGuncelle(int id, bool begenildiMi)
 {
     //string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); metodlaştırdık. bkz: extensions
     try
     {
         string userId       = User.GetUserId();
         var    kullaniciSoz = new KullaniciSoz()
         {
             GuzelSozId  = id,
             KullaniciId = userId
         };
         if (begenildiMi)
         {
             if (!_dbContext.KullaniciSozler.Contains(kullaniciSoz))
             {
                 _dbContext.Add(kullaniciSoz);
             }
         }
         else
         {
             if (_dbContext.KullaniciSozler.Contains(kullaniciSoz))
             {
                 _dbContext.KullaniciSozler.Remove(kullaniciSoz);
             }
         }
         _dbContext.SaveChanges();
         return(new EmptyResult());
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }