Exemplo n.º 1
0
        public void RateItem(Ratings obj,bool isRated)
        {
            

            String q;
            SqlConnection con = new SqlConnection(new ProjectUtilities().cons());
            SqlCommand c;
            con.Open();

            if (isRated)
            {
                //Ratings obj = new Ratings().getRated(id);
                //obj.totalraters++;
                //obj.totalratings += rated;
                q = "Update Ratings Set TotalRatings=@tr,TotalRaters=@trr Where Pid=@id";
                c = new SqlCommand(q, con);
                c.Parameters.Add("@tr", obj.totalratings);
                c.Parameters.Add("@trr", obj.totalraters);
                c.Parameters.Add("@id", obj.id);
                c.ExecuteNonQuery();
                con.Close();
            }

            else
            {
                q = "Insert into Ratings Values(@id,@tr,@trr)";
                c = new SqlCommand(q, con);
                c.Parameters.Add("@tr", obj.totalratings);
                c.Parameters.Add("@trr", 1);
                c.Parameters.Add("@id", id);
                c.ExecuteNonQuery();
                con.Close();
            }
        }
Exemplo n.º 2
0
 public Ratings getRated(int id)
 {
     String q = "Select * from Ratings  where Pid=@id";
     SqlConnection con = new SqlConnection(new ProjectUtilities().cons());
     SqlCommand c = new SqlCommand(q, con);
     con.Open();
     c.Parameters.Add("@id", id);
     SqlDataReader r = c.ExecuteReader();
     r.Read();
     Ratings obj = new Ratings();
     obj.id = id;
     obj.totalratings = int.Parse(r["TotalRatings"].ToString());
     obj.totalraters = int.Parse(r["TotalRaters"].ToString());
     obj.netratings = 0;
     con.Close();
     return obj;
 }
Exemplo n.º 3
0
 protected void ProdRating_Changed()
 {
     int rating = ProdRating.CurrentRating;
     Ratings o = new Ratings();
     int id = int.Parse(Request.QueryString["pid"].ToString());
     bool isRated = o.isRated(id);
     o.id = id;
     if (isRated)
     {
         o = o.getRated(id);
         o.totalraters++;
         o.totalratings += rating;
         o.RateItem(o, isRated);
     }
     else
     {
         o.totalratings = rating;
         o.totalraters = 1;
         o.RateItem(o, isRated);
     }
     //ProdRating.Enabled = false;
     ProdRating.ReadOnly = true;
 }
Exemplo n.º 4
0
 private void setRatings()
 {
     String s = Request.QueryString["pid"].ToString();
     Ratings o = new Ratings();
     if (o.isRated(int.Parse(s)))
     {
         o = o.getRated(int.Parse(s));
         ProdRating.CurrentRating = (int)(o.totalratings / o.totalraters);
         RatingLabel.InnerText = "Average User Ratings : ";
     }
     else
     {
         RatingLabel.InnerText = "Be The First To Rate This Product !";
     }
 }