Ejemplo n.º 1
0
        public JsonResult VoteVideo(int id, int points)
        {
            try
            {//id için tanımlı olan Article kaydına points kadar puan ekleyelim  (TotalPoints)
                if (Session["HasVoted_" + id] == null || (bool)Session["HasVoted_" + id] != true)
                {
                    OylamaRep rep      = new OylamaRep();
                    Oylama    o        = new Oylama();
                    VideoRep  vRep     = new VideoRep();
                    Video     selected = vRep.GetById(id);
                    if (selected.TotalRate.HasValue)
                    {
                        selected.TotalRate = selected.TotalRate.Value + points;
                    }
                    else
                    {
                        selected.TotalRate = points;
                    }
                    vRep.Update(selected);
                    Session["HasVoted_" + id] = true;

                    return(Json("Thank you for voting"));
                }
                else
                {
                    return(Json("you can't vote again!"));
                }
            }
            catch (Exception ex)
            {
                return(Json("A problem has occured - " + ex.Message));
            }
        }
Ejemplo n.º 2
0
        public JsonResult MakaleOy(int oy, int id)
        {
            try
            {
                if (Session["HasVoted_" + id] == null || (bool)Session["HasVoted_" + id] != true)
                {
                    Oylama    o       = new Oylama();
                    MakaleRep mrep    = new MakaleRep();
                    OylamaRep orep    = new OylamaRep();
                    Makale    secilen = mrep.GetById(id);
                    string    isim    = User.Identity.GetUserName();

                    if (secilen.ToplamOy.HasValue)
                    {
                        secilen.ToplamOy = secilen.ToplamOy.Value + oy;
                        o.MakaleAdi      = secilen.Baslik;
                        o.Oy             = oy;
                        o.KullaniciAdi   = isim;
                        orep.Insert(o);
                    }

                    else
                    {
                        secilen.ToplamOy = oy;
                        o.MakaleAdi      = secilen.Baslik;
                        o.Oy             = oy;
                        o.KullaniciAdi   = isim;
                        orep.Insert(o);
                    }
                    mrep.Update(secilen);
                    Session["Hasvoted_" + id] = true;
                    return(Json("Oy verdiğiniz için teşekkürler."));
                }
                else
                {
                    return(Json("Tekrar oy veremezsiniz."));
                }
            }
            catch (Exception ex)
            {
                return(Json("Bir hata oluştu." + ex.Message));
            }
        }