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));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Rate(Oylama rate)
        {
            var user    = Session["KULLANICIADI"] as Kullanıcılar;
            var sAlındı = (from s in db.Sepet
                           where user.KullanıcıID == s.KullanıcıID && s.SatınAlındı == 1 &&
                           rate.ProductID == s.UrunID
                           select new { s, }
                           ).FirstOrDefault();

            var oKullan = (from k in db.Kullanıcılar
                           join o in db.Oylama on rate.ProductID
                           equals o.ProductID where user.KullanıcıID == o.UserID
                           select new { k, o, }).FirstOrDefault();

            if (user != null)
            {
                if (sAlındı != null)
                {
                    if (oKullan == null)
                    {
                        rate.UserID = user.KullanıcıID;
                        db.Oylama.Add(rate);
                        db.SaveChanges();


                        var ortalama = (from k in db.Kullanıcılar
                                        join o in db.Oylama
                                        on k.KullanıcıID equals o.UserID
                                        where o.ProductID == rate.ProductID
                                        group o by o.ProductID into g
                                        let ortSatis = g.Average(m => m.Score)
                                                       select new
                        {
                            SatilanUrunSayisi = g.Average(i => i.Score)
                        }).First().ToString();

                        ortalama = ortalama.Replace("{", "").Replace("}", "").Replace("SatilanUrunSayisi", "").Replace("=", "");
                        var result = db.Urunler.SingleOrDefault(b => b.UrunID == rate.ProductID);
                        if (result != null)
                        {
                            result.Score = ortalama;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        //return Content("<script>alert('Bu Urünü Daha Once Oyladiginiz Icin Tekrar Oylayamazsiniz.');window.location='/Detay/DetayGoster';</script>", "text/html", new {id=rate.Score });
                        return(RedirectToAction("DetayGoster", "Detay", new { id = rate.ProductID }));
                    }
                }

                else
                {
                    //return Content("<script>alert('Satin Almadginiz Urun Icin Oylamaya Katilamazsiniz.');window.location='/Home/Index';</script>", "text/html");
                    return(RedirectToAction("DetayGoster", "Detay", new { id = rate.ProductID }));
                }
            }
            else
            {
                return(Content("<script>alert('Lutfen Uye Girisi Yapiniz.');window.location='/Kullanıcılar/Gırıs';</script>", "text/html"));
            }
            //return PartialView("RateHomeView", rate);
            //return View("~/Views/Detay/DetayGoster.cshtml", urun);
            return(RedirectToAction("DetayGoster", "Detay", new { id = rate.ProductID }));
        }