protected void btn_Like_Click(object sender, ImageClickEventArgs 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); }
private void RateThis(int rate) { using (TriglavBL temp = new TriglavBL()) { user_likes = temp.getUserLikes(korisnik.id, post.id); if (user_likes == null) //ako ne postoji zapis { 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 = 0; user_likes.Rate = rate; // setujemo rate temp.SaveUser_Likes_Rates(user_likes); } else { Int32 RateBefore = temp.getRateUserLikes(user_likes.UserId.Value, user_likes.PostId.Value); user_likes.DaumRated = DateTime.Now; user_likes.Rate = rate; temp.UpdateUser_Likes_Rates(user_likes, RateBefore); } } LoadClanak(post.id); }
/// <summary> /// USER VOTES POSTS///////////////////////////////////////////////////////////////////////////// /// </summary> /// private void GetVotesInfo() { using (TriglavBL temp = new TriglavBL()) { if (korisnik != null) { user_likes = temp.getUserLikes(korisnik.id, post.id); if (user_likes != null) { if (temp.getUserLikes(korisnik.id, post.id) == null) { lbl_Likes.Text = Convert.ToString(post.Likes.Value) + " osoba je glasovalo za! "; lbl_Unlikes.Text = Convert.ToString(post.Unlikes.Value) + " osoba je glasovalo protiv! "; btn_Like.Enabled = true; // btn vote up btn_Unlike.Enabled = true; // btn vote down } else { user_likes = temp.getUserLikes(korisnik.id, post.id); if (user_likes.isLiked == 0) { lbl_Likes.Text = Convert.ToString(post.Likes.Value) + " osoba je glasovalo za! "; lbl_Unlikes.Text = Convert.ToString(post.Unlikes.Value) + " osoba je glasovalo protiv! "; btn_Like.Enabled = true; btn_Unlike.Enabled = true; } if (user_likes.isLiked == 1) { lbl_Likes.Text = "Vi i još " + Convert.ToString(post.Likes.Value - 1) + " osoba je glasovalo za! "; lbl_Unlikes.Text = Convert.ToString(post.Unlikes.Value) + " osoba je glasovalo protiv! "; btn_Like.Enabled = false; btn_Unlike.Enabled = true; } if (user_likes.isLiked == 2) { lbl_Likes.Text = Convert.ToString(post.Likes.Value) + " osoba je glasovalo za! "; lbl_Unlikes.Text = "Vi i još " + Convert.ToString(post.Unlikes.Value - 1) + " osoba ste glasovali protiv! "; btn_Like.Enabled = true; btn_Unlike.Enabled = false; } } } else { lbl_Likes.Text = Convert.ToString(post.Likes.Value) + " osoba je glasovalo za! "; lbl_Unlikes.Text = Convert.ToString(post.Unlikes.Value) + " osoba je glasovalo protiv! "; btn_Like.Enabled = true; btn_Unlike.Enabled = true; } } else { lbl_Likes.Text = Convert.ToString(post.Likes.Value) + " osoba je glasovalo za! "; lbl_Unlikes.Text = Convert.ToString(post.Unlikes.Value) + " osoba je glasovalo protiv! "; btn_Like.Enabled = false; btn_Unlike.Enabled = false; } } }
protected void btn_Unlike_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 = 2; user_likes.Rate = 0; temp.SaveUser_Unlikes(user_likes); } else { Int32 LikesBefore = temp.getVoteUserLikes(user_likes.UserId.Value, user_likes.PostId.Value); user_likes.DatumLajkanja = DateTime.Now; user_likes.isLiked = 2; temp.UpdateUser_Likes(user_likes, LikesBefore); } } LoadClanak(post.id); }
protected void btn_oUnlike_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 = post.id; user_likes.UserId = korisnik.id; user_likes.DaumRated = DateTime.Now; user_likes.DatumLajkanja = DateTime.Now; user_likes.isLiked = 2; user_likes.Rate = 0; temp.SaveUser_Unlikes(user_likes); } else { Int32 LikesBefore = temp.getVoteUserLikes(user_likes.UserId.Value, user_likes.PostId.Value); user_likes.DatumLajkanja = DateTime.Now; user_likes.isLiked = 2; temp.UpdateUser_Likes(user_likes, LikesBefore); } } } LoadClanak(post.id); } else { ClientScript.RegisterStartupScript(this.GetType(), "", "Login()", true); } }
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); } }
private void RateThis(int rate) { using (TriglavBL temp = new TriglavBL()) { user_likes = temp.getUserLikes(korisnik.id, post.id); if (user_likes == null) //ako ne postoji zapis { user_likes = new Data.EntityFramework.DAL.User_Likes(); user_likes.PostId = post.id; user_likes.UserId = korisnik.id; user_likes.DatumLajkanja = DateTime.Now; user_likes.DaumRated = DateTime.Now; user_likes.isLiked = 0; user_likes.Rate = rate; // setujemo rate temp.SaveUser_Likes_Rates(user_likes); } else { Int32 RateBefore = temp.getRateUserLikes(user_likes.UserId.Value, user_likes.PostId.Value); user_likes.DatumLajkanja = DateTime.Now; user_likes.DaumRated = DateTime.Now; user_likes.Rate = rate; temp.UpdateUser_Likes_Rates(user_likes, RateBefore); } } LoadClanak(post.id); }
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; } } }
public void UpdateUser_Likes(User_Likes user_likes, int LikesBefore) { User_Likes uli = context.User_Likes.Where(x => x.id == user_likes.id && x.UserId == user_likes.UserId && x.PostId == user_likes.PostId).FirstOrDefault(); uli.isLiked = user_likes.isLiked; uli.PostId = user_likes.PostId.Value; uli.UserId = user_likes.UserId.Value; if (user_likes.Rate == null) uli.Rate = 0; else uli.Rate = user_likes.Rate.Value; uli.DatumLajkanja = user_likes.DatumLajkanja.Value; uli.DaumRated = user_likes.DaumRated.Value; context.SaveChanges(); Post post = context.Post.First(p => p.id == user_likes.PostId.Value); Korisnik korisnik = context.Korisnik.First(p => p.id == post.VlasnikID); User_Likes ul = context.User_Likes.Where(x => x.id == user_likes.id && x.UserId == user_likes.UserId && x.PostId == user_likes.PostId).FirstOrDefault(); if (LikesBefore == 0) { if (ul.isLiked == 1) { post.Likes++; post.BrojPoena = post.Likes.Value - post.Unlikes.Value; UpdatePost(post); korisnik.Likes++; korisnik.Reputacija = korisnik.Likes.Value - korisnik.Unlikes.Value; UpdateKorisnik(korisnik); KalkulirajMedaljePostaKorisnikaUP(korisnik, post); } if (ul.isLiked == 2) { post.Unlikes++; post.BrojPoena = post.Likes.Value - post.Unlikes.Value; UpdatePost(post); korisnik.Unlikes++; korisnik.Reputacija = korisnik.Likes.Value - korisnik.Unlikes.Value; UpdateKorisnik(korisnik); KalkulirajMedaljePostaKorisnikaDOWN(korisnik, post); } } else { if (ul.isLiked == 1) { post.Likes++; post.BrojPoena = post.Likes.Value - post.Unlikes.Value; UpdatePost(post); KalkulirajMedaljePostaKorisnikaUP(korisnik, post); post.Unlikes--; post.BrojPoena = post.Likes.Value - post.Unlikes.Value; UpdatePost(post); KalkulirajMedaljePostaKorisnikaUP(korisnik, post); korisnik.Likes++; korisnik.Unlikes--; korisnik.Reputacija = korisnik.Likes.Value - korisnik.Unlikes.Value; UpdateKorisnik(korisnik); } if (ul.isLiked == 2) { post.Likes--; post.BrojPoena = post.Likes.Value - post.Unlikes.Value; UpdatePost(post); KalkulirajMedaljePostaKorisnikaDOWN(korisnik, post); post.Unlikes++; post.BrojPoena = post.Likes.Value - post.Unlikes.Value; UpdatePost(post); KalkulirajMedaljePostaKorisnikaDOWN(korisnik, post); korisnik.Likes--; korisnik.Unlikes++; korisnik.Reputacija = korisnik.Likes.Value - korisnik.Unlikes.Value; UpdateKorisnik(korisnik); } } context.SaveChanges(); }
public void SaveUser_Unlikes(User_Likes user_likes) { context.User_Likes.Add(user_likes); Post post = context.Post.First(p => p.id == user_likes.PostId.Value); Korisnik korisnik = context.Korisnik.First(p => p.id == post.VlasnikID); if (user_likes.isLiked == 2) { post.Unlikes++; post.BrojPoena = post.Likes.Value - post.Unlikes.Value; UpdatePost(post); korisnik.Unlikes++; korisnik.Reputacija = korisnik.Likes.Value - korisnik.Unlikes.Value; UpdateKorisnik(korisnik); } KalkulirajMedaljePostaKorisnikaDOWN(korisnik, post); context.SaveChanges(); }
public void SaveUser_Likes_Rates(User_Likes user_likes) { context.User_Likes.Add(user_likes); context.SaveChanges(); Post post = context.Post.First(p => p.id == user_likes.PostId.Value); post.BrojOmiljenih = post.BrojOmiljenih.Value + user_likes.Rate.Value; post.BrojRangiranja++; UpdatePost(post); }
public void UpdateUser_Likes_Rates(User_Likes user_likes, int RateBefore) { User_Likes ul = context.User_Likes.Where(x => x.id == user_likes.id && x.UserId == user_likes.UserId && x.PostId == user_likes.PostId).FirstOrDefault(); ul.isLiked = user_likes.isLiked; ul.PostId = user_likes.PostId.Value; ul.UserId = user_likes.UserId.Value; if (user_likes.Rate == null) ul.Rate = 0; else ul.Rate = user_likes.Rate.Value; ul.DatumLajkanja = user_likes.DatumLajkanja.Value; ul.DaumRated = user_likes.DaumRated.Value; context.SaveChanges(); Post post = context.Post.First(p => p.id == user_likes.PostId.Value); post.BrojOmiljenih = post.BrojOmiljenih.Value - RateBefore + user_likes.Rate.Value; ul = context.User_Likes.Where(x => x.id == user_likes.id && x.UserId == user_likes.UserId && x.PostId == user_likes.PostId).FirstOrDefault(); if (RateBefore == 0) post.BrojRangiranja++; UpdatePost(post); }