public ActionResult SetPoliticalStance(PoliticalStanceViewModel model) { var userId = System.Web.HttpContext.Current.User.Identity.GetUserId(); _billsService.SetBillStance(model.VerticalAvarage, model.HorizontalAvarage, model.BillId, userId); return(RedirectToAction("Details", new { id = model.BillId })); }
public PoliticalStanceViewModel GetPoliticalStance(int id, string userId) { var stance = new PoliticalStanceViewModel(); decimal verticalAvarage = 50; decimal horizontalAvarage = 50; var bill = _db.Single <BillDataModel>(b => b.Id == id); stance.BillId = id; stance.Title = bill.Title; var allStanceRecordsForBill = _db.All <BillStanceDateModel>().Where(s => s.BillId == id); if (allStanceRecordsForBill.Any()) { verticalAvarage = allStanceRecordsForBill.Sum(s => s.VerticalValue) / allStanceRecordsForBill.Count(); horizontalAvarage = allStanceRecordsForBill.Sum(s => s.HorizontalValue) / allStanceRecordsForBill.Count(); } var range = 360; var horizontalLowerBound = -141; var verticalLowerBound = -276; var targetHorizontalGraphValue = (horizontalAvarage / 100) * range - Math.Abs(horizontalLowerBound); var targetVerticalGraphValue = ((100 - verticalAvarage) / 100) * range - Math.Abs(verticalLowerBound); stance.HorizontalAvarage = targetHorizontalGraphValue; stance.VerticalAvarage = targetVerticalGraphValue; var hasUserSetStance = allStanceRecordsForBill.Any(s => s.UserId == userId); if (hasUserSetStance) { stance.AlreadySet = true; } else { stance.AlreadySet = false; } return(stance); }