public ActionResult DetailPost(int id, int?page) { POST Post = postsModels.GetItem(id); ViewBag.Post = postsModels.GetItem(id); ViewBag.SamePost = postsModels.GetItemActiveSame(1, 5, Post.ID_CATEGORY, id); ViewBag.RencentPost = postsModels.GetItemActive(1, 5, id); ViewBag.Active = "category"; ViewBag.Vote = 0; if (User.GetType() == typeof(CustomPrincipal)) { CustomPrincipal prin = (CustomPrincipal)User; VOTE Vote = voteModels.GetItemPostUser(Post.ID, prin.ID); if (Vote != null) { ViewBag.Vote = 1; } else { ViewBag.Vote = 2; } } IPagedList ListCommentPost = commentsModels.GetItemsPost(page ?? 1, 12, id); return(View(ListCommentPost)); }
public ActionResult VotePost(int idPost) { if (User.GetType() == typeof(CustomPrincipal)) { CustomPrincipal prin = (CustomPrincipal)User; VOTE Vote = voteModels.GetItemPostUser(idPost, prin.ID); if (Vote == null) { VOTE VoteAdd = new VOTE(); VoteAdd.ID_POST = idPost; VoteAdd.ID_USER = prin.ID; int i = voteModels.Add(VoteAdd); } } return(Redirect(Request.UrlReferrer.ToString())); }
public int Add(VOTE Vote) { db.VOTEs.Add(Vote); return(db.SaveChanges()); }
private void SaveInfo(string strLink = "") { try { int Cat_Parent_Id = Utils.CIntDef(ddlCategory.SelectedValue, 0); int Cat_Rank = 1; if (Cat_Parent_Id > 0) { var CatParent = DB.GetTable <VOTE>().Where(c => c.VOTE_OID == Cat_Parent_Id); Cat_Rank = Utils.CIntDef(CatParent.Single().VOTE_RANK) + 1; } if (m_cat_id == 0) { //insert VOTE vo_insert = new VOTE(); vo_insert.VOTE_RANK = Cat_Rank; vo_insert.VOTE_PARENT_ID = Cat_Parent_Id; vo_insert.VOTE_QUESTION = txtques.Value; vo_insert.VOTE_DATE = DateTime.Now; vo_insert.VOTE_ACTIVE = Utils.CIntDef(Dractive.SelectedValue); vo_insert.VOTE_COUNT = 0; DB.VOTEs.InsertOnSubmit(vo_insert); DB.SubmitChanges(); var _cat = DB.GetTable <VOTE>().OrderByDescending(g => g.VOTE_OID).Take(1); m_cat_id = _cat.Single().VOTE_OID; strLink = "vote.aspx?vote_id=" + m_cat_id; strLink = string.IsNullOrEmpty(strLink) ? "vote-list.aspx" : strLink; } else { //update var c_update = DB.GetTable <VOTE>().Where(g => g.VOTE_OID == m_cat_id); if (c_update.ToList().Count > 0) { c_update.First().VOTE_RANK = Cat_Rank; c_update.First().VOTE_PARENT_ID = Cat_Parent_Id; c_update.First().VOTE_QUESTION = txtques.Value; c_update.First().VOTE_DATE = DateTime.Now; c_update.First().VOTE_ACTIVE = Utils.CIntDef(Dractive.SelectedValue); DB.SubmitChanges(); strLink = string.IsNullOrEmpty(strLink) ? "vote-list.aspx" : strLink; } } } catch (Exception ex) { clsVproErrorHandler.HandlerError(ex); } finally { if (!string.IsNullOrEmpty(strLink)) { Response.Redirect(strLink); } } }
private void updateVotes(IEnumerable <Collection1> v) { using (AgendaEntities db = new AgendaEntities()) { var context = System.Web.HttpContext.Current; //ErrorLog.GetDefault(context).Log(new Error(new Exception("updateVotes-before Collection1 vote_item"))); foreach (Collection1 vote_item in v) { if (string.IsNullOrEmpty(vote_item.oknessetBill.text)) { throw new ArgumentNullException(); } // find if bill exist, if so find it and get the id, else create it //int billOknessetId = int.Parse(vote_item.oknessetBill.text.Replace("https://oknesset.org/bill/","").Replace("/","")); BILL bill = db.BILL.Where(b => (b.oknesset_url == vote_item.oknessetBill.text)).FirstOrDefault(); int billId = (bill != null?bill.Id : 0); DateTime voteDate = DateTime.ParseExact(vote_item.voteDate, "MM/dd/yyyy", CultureInfo.InvariantCulture); VOTE vote = db.VOTE.Where(b => (b.bill.Value == billId && b.meeting == voteDate)).FirstOrDefault(); if (bill == null || bill.Id == 0) { bill = new BILL(); bill.name = vote_item.billName; bill.date = voteDate; bill.oknesset_url = vote_item.oknessetBill.text; //ErrorLog.GetDefault(context).Log(new Error(new Exception("updateVotes-before BILL.Add"))); db.BILL.Add(bill); db.SaveChanges(); //db.Database.Connection. //bill = db.BILL.Where(b => (b.oknesset_url == vote_item.oknessetBill.text)).FirstOrDefault(); } if (vote == null) { VOTE newVote = new VOTE(); //newVote.meeting = DateTime.Parse(vote_item.voteDate);// 06/07/2015 newVote.meeting = voteDate; newVote.bill = bill.Id; newVote.mk = int.Parse(vote_item.minister_id); newVote.source = 1; // from public vote // if (vote_item.ministerVote == "בעד" || vote_item.ministerVote == "׳‘׳¢׳“" || vote_item.ministerVote == "בעד") { newVote.vote1 = 1; } else if (vote_item.ministerVote == "נגד" || vote_item.ministerVote == "׳ ׳’׳“" || vote_item.ministerVote == "× ×ž× ×¢") { newVote.vote1 = 2; } else { // we will take the vote from the commitie vote if the minister didn't publish it if (vote_item.passed == "בעד" || vote_item.passed == "׳‘׳¢׳“" || vote_item.passed == "בעד") { newVote.vote1 = 1; } else if (vote_item.passed == "נגד" || vote_item.ministerVote == "׳ ׳’׳“" || vote_item.passed == "× ×ž× ×¢") { newVote.vote1 = 2; } else { ErrorLog.GetDefault(context).Log(new Error(new Exception("vote_item.ministerVote:" + vote_item.ministerVote))); ErrorLog.GetDefault(context).Log(new Error(new Exception("vote_item.passed:" + vote_item.passed))); newVote.vote1 = 0; } } ErrorLog.GetDefault(context).Log(new Error(new Exception("updateVotes-before VOTE.Add"))); db.VOTE.Add(newVote); db.SaveChanges(); } else { // vote. } //ViewBag.mk = new SelectList(db.MK, "Id", "mk_name", mK_SCORE.mk); //ViewBag.agendaId = new SelectList(db.AGENDA, "Id", "name", mK_SCORE.agendaId); //return View(mK_SCORE); } } }
/// <summary> /// generate Shadow Vote From Committee vote To the Agenda using the bills table /// for any bill without a vote for mk generate one /// </summary> private void generateShadowVoteFromCommitteeToAgenda() { var context = System.Web.HttpContext.Current; // b. add/update the data for score on every bill for any agenda using (AgendaEntities db = new AgendaEntities()) { try { List <BILL> existBills4AllMks = (from b2d in db.BILL join v in db.VOTE on b2d.Id equals v.bill.Value join m in db.MK on v.mk.Value equals m.Id where !string.IsNullOrEmpty(b2d.oknesset_url) select b2d).ToList(); foreach (BILL b in db.BILL.ToList()) { foreach (MK m in db.MK.ToList()) { //ErrorLog.GetDefault(context).Log(new Error(new Exception(" before existBills4AllMks.Contains,m.Id:" + m.Id))); // if bill has votes for all ms continue if (existBills4AllMks.Contains(b) && b.VOTE.Where(v_exist => v_exist.mk == m.Id).Count() > 0) { continue; } //ErrorLog.GetDefault(context).Log(new Error(new Exception(" after existBills4AllMks.Contains"))); VOTE v = new VOTE(); v.meeting = b.date; v.bill = b.Id; v.mk = m.Id; if (b.committee_vote.HasValue) { v.vote1 = b.committee_vote.Value; } v.source = 2; // committee_vote db.VOTE.Add(v); db.SaveChanges(); } // find bills which at least one mk missing a vote for it //var existVotes = db.BILL.Where(b2d => (!string.IsNullOrEmpty(b2d.oknesset_url && ))); //foreach (OknessetBillAgendaList a in votesToAgenda.agendas.agenda_list.ToList()) //{ // using (AgendaEntities db = new AgendaEntities()) // { // // find if vote already updated // //db.Entry(aGENDA).State = EntityState.Modified; // //db.SaveChanges(); // int agnId = int.Parse(a.resource_uri.Replace("api/v2/agenda/", "").Replace("/", "")); // VOTE_TO_AGENDA v2a = db.VOTE_TO_AGENDA.Where(va => va.agenda == agnId && va.vote == v.Id).FirstOrDefault(); // if (v2a == null) // { // v2a = new VOTE_TO_AGENDA(); // v2a.vote = v.Id; // v2a.agenda = agnId; // v2a.score = (decimal)a.score; // v2a.volume = (decimal)a.importance; // db.VOTE_TO_AGENDA.Add(v2a); // db.SaveChanges(); // } // else // { // v2a.vote = v.Id; // v2a.agenda = agnId; // v2a.score = (decimal)a.score; // v2a.volume = (decimal)a.importance; // //db.VOTE_TO_AGENDA.e(v2a); // db.SaveChanges(); // } // } //} } } catch (Exception e) { ErrorLog.GetDefault(context).Log(new Error(e)); } } }