Exemplo n.º 1
0
        protected void btn_Like_Click(object sender, EventArgs e)
        {
            using (TriglavBL temp = new TriglavBL())
            {
                user_likes = temp.getUserLikes(korisnik.id, post.id);

                if (user_likes == null)
                {
                    user_likes               = new Data.EntityFramework.DAL.User_Likes();
                    user_likes.PostId        = post.id;
                    user_likes.UserId        = korisnik.id;
                    user_likes.DaumRated     = DateTime.Now;
                    user_likes.DatumLajkanja = DateTime.Now;
                    user_likes.isLiked       = 1;
                    user_likes.Rate          = 0;
                    temp.SaveUser_Likes(user_likes);
                }
                else
                {
                    Int32 LikesBefore = temp.getVoteUserLikes(user_likes.UserId.Value, user_likes.PostId.Value);
                    user_likes.DatumLajkanja = DateTime.Now;
                    user_likes.isLiked       = 1;
                    temp.UpdateUser_Likes(user_likes, LikesBefore);
                }
            }
            LoadClanak(post.id);
        }
        protected void btn_oLike_Click(object sender, ImageClickEventArgs e)
        {
            if (korisnik != null)
            {
                ImageButton _sender = (ImageButton)sender;
                HiddenField hid     = (HiddenField)_sender.FindControl("hf");


                using (TriglavBL temp = new TriglavBL())
                {
                    Post odgovorNaLIsti = temp.getOdgovorByID(Convert.ToInt32(hid.Value));

                    if (odgovorNaLIsti != null)
                    {
                        user_likes = temp.getUserLikes(korisnik.id, odgovorNaLIsti.id);

                        if (user_likes == null)
                        {
                            user_likes               = new Data.EntityFramework.DAL.User_Likes();
                            user_likes.PostId        = odgovorNaLIsti.id;
                            user_likes.UserId        = korisnik.id;
                            user_likes.DaumRated     = DateTime.Now;
                            user_likes.DatumLajkanja = DateTime.Now;
                            user_likes.isLiked       = 1;
                            user_likes.Rate          = 0;
                            temp.SaveUser_Likes(user_likes);
                        }
                        else
                        {
                            Int32 LikesBefore = temp.getVoteUserLikes(user_likes.UserId.Value, user_likes.PostId.Value);
                            user_likes.DatumLajkanja = DateTime.Now;
                            user_likes.isLiked       = 1;
                            temp.UpdateUser_Likes(user_likes, LikesBefore);
                        }
                    }
                }
                LoadClanak(post.id);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "Login()", true);
            }
        }
        protected void dl_odgovori_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            int id = (int)DataBinder.Eval(e.Item.DataItem, "id");



            using (TriglavBL temp = new TriglavBL())
            {
                Post p = temp.getPostByID(id);
                Data.EntityFramework.DAL.Korisnik     k        = temp.getKorisnikByID(p.VlasnikID.Value);
                System.Web.UI.WebControls.ImageButton img_User = (System.Web.UI.WebControls.ImageButton)e.Item.FindControl("img_User");
                img_User.ImageUrl    = k.SlikaURL;
                img_User.PostBackUrl = "/Public/QA_Pitanja.aspx?KorisnikID=" + p.VlasnikID.Value;

                Label reputacija = (Label)e.Item.FindControl("lbl_Reputacija");
                reputacija.Text = "Reputacija: " + k.Reputacija;

                System.Web.UI.WebControls.ImageButton img_Bedz = (System.Web.UI.WebControls.ImageButton)e.Item.FindControl("img_Bedz");
                img_Bedz.ImageUrl    = k.BedzSlika;
                img_Bedz.PostBackUrl = "/Public/QA_Bedz.aspx?BedzID=" + k.BedzID.Value;

                Label lbl_NazivBedza = (Label)e.Item.FindControl("lbl_NazivBedza");
                lbl_NazivBedza.Text    = k.BedzNaziv;
                lbl_NazivBedza.ToolTip = k.BedzOpis;

                Label lbl_BrojPoena = (Label)e.Item.FindControl("lbl_BrojPoena");
                lbl_BrojPoena.Text = Convert.ToString(p.BrojPoena);


                if (p.BrojPoena >= 3)
                {
                    e.Item.BackColor = Color.LightGray;
                }
                if (p.BrojPoena >= 5)
                {
                    e.Item.BackColor = Color.LightYellow;
                }
                if (p.BrojPoena >= 10)
                {
                    e.Item.BackColor = Color.LightGreen;
                }
                if (p.BrojPoena < 3)
                {
                    e.Item.BackColor = Color.White;
                }


                ImageButton like   = (ImageButton)e.Item.FindControl("btn_oLike");
                ImageButton unlike = (ImageButton)e.Item.FindControl("btn_oUnlike");
                if (korisnik != null)
                {
                    User_Likes ulo;
                    if (temp.getUserLikes(korisnik.id, p.id) == null)
                    {
                        ulo               = new Data.EntityFramework.DAL.User_Likes();
                        ulo.PostId        = p.id;
                        ulo.UserId        = korisnik.id;
                        ulo.DatumLajkanja = DateTime.Now;
                        ulo.DaumRated     = DateTime.Now;
                        ulo.isLiked       = 0;
                        temp.SaveUser_Likes(ulo);
                    }
                    else
                    {
                        ulo = temp.getUserLikes(korisnik.id, p.id);
                    }
                    like.Enabled   = false;
                    unlike.Enabled = false;

                    if (ulo.isLiked == 0)
                    {
                        like.Enabled   = true;
                        unlike.Enabled = true;
                    }
                    if (ulo.isLiked == 1)
                    {
                        like.Enabled   = false;
                        unlike.Enabled = true;
                    }
                    if (ulo.isLiked == 2)
                    {
                        like.Enabled   = true;
                        unlike.Enabled = false;
                    }
                }
                else
                {
                    like.Enabled   = false;
                    unlike.Enabled = false;
                }
            }
        }