public ActionResult Index(string respondentId)
        {
            var user = UserSession.SessionFactory(respondentId);
            var db = new FederalSpendingDataContext(ConfigurationManager.ConnectionStrings["FederalBudgetSpendingConnectionString"].ConnectionString);

            SessionUtility.User = db.UserSessions.Single(x => x.UserSessionId == user.UserSessionId);
            return RedirectToAction("Task");
        }
Exemplo n.º 2
0
        public int GetRandomPrompt()
        {
            Random rand = new Random();
            var db = new FederalSpendingDataContext(Connection.String);

            int totalWeight = db.Prompts.Sum(x => x.Probability);

            int randomNumber = rand.Next(0, totalWeight);

            Prompt selectedPrompt = null;
            foreach (var prompt in db.Prompts.OrderByDescending(x => x.Probability))
            {
                if (randomNumber < prompt.Probability)
                {
                    selectedPrompt = prompt;
                    break;
                }

                randomNumber = randomNumber - prompt.Probability;
            }

            return selectedPrompt.PromptId;
        }
        public ActionResult Task(List<BudgetTaskCategory> taskCategories)
        {
            int sum = 0;
            var db = new FederalSpendingDataContext(ConfigurationManager.ConnectionStrings["FederalBudgetSpendingConnectionString"].ConnectionString);

            foreach (var category in taskCategories)
            {
                var categoryToSave = db.BudgetTaskCategories.Single(x => x.BudgetTaskCategoryId == category.BudgetTaskCategoryId);
                categoryToSave.Value = category.Value;

                sum += category.Value;
            }

            if (sum != 100)
            {
                ModelState.AddModelError("DoesntEqual100", "The values provided do not add up to 100%.  Please correct them and try again.");

                return View(User.BudgetTask);
            }

            db.SubmitChanges();
            return View("Success");
        }
 public void PostValueChange(int id, int previous, int current)
 {
     var db = new FederalSpendingDataContext(ConfigurationManager.ConnectionStrings["FederalBudgetSpendingConnectionString"].ConnectionString);
     db.BudgetTaskCategoryHistories.InsertOnSubmit(new BudgetTaskCategoryHistory { BudgetTaskCategoryId = id, PreviousValue = previous, CurrentValue = current, CreateDate = DateTime.Now });
     db.SubmitChanges();
 }