public ActionResult ConfigureNewSprint(QuestionarieViewModel quest) { if (TempData["newSprint"] != null) { var sprint = TempData["newSprint"] as Sprint; Sprint newSprint = db.Sprints.Find(sprint.Id); if (quest.vision != newSprint.SprintGoal && quest.vision != null) { newSprint.SprintGoal = quest.vision; //Im using vision as the SprintGoal to reuse the previos QuestionnaireViewModel db.SaveChanges(); } var sprintGoals = newSprint.Goals; string goalJoy = quest.goal_1; string goalPassion = quest.goal_2; string goalGB = quest.goal_3; foreach (Goal g in sprintGoals.ToList()) { Goal newGoal = db.Goals.Find(g.Id); if (newGoal.CategoryId == 1 && newGoal.Description != goalJoy && goalJoy != null) { newGoal.Description = goalJoy; db.SaveChanges(); } else if (newGoal.CategoryId == 2 && newGoal.Description != goalPassion && goalPassion != null) { newGoal.Description = goalPassion; db.SaveChanges(); } else if (newGoal.CategoryId == 3 && newGoal.Description != goalGB && goalGB != null) { newGoal.Description = goalGB; db.SaveChanges(); } } return(RedirectToAction("Dashboard", "Users")); } ViewBag.ErrorMsg = "There was an unexpected error while configuring your productivity week, try again later"; return(View("Error")); }
public ActionResult collect_questionnarie(QuestionarieViewModel data) { string name = User.Identity.Name; var user = db.Users.Where(atr => atr.username.ToLower() == name.ToLower()).FirstOrDefault(); if (user != null) { int id = user.Id; var sprint0 = new Sprint(); var g1 = new Goal(); var g2 = new Goal(); var g3 = new Goal(); sprint0.DateFrom = DateTime.Now; sprint0.SprintGoal = data.vision; sprint0.UserId = id; db.Sprints.Add(sprint0); db.SaveChanges(); g1.SprintId = sprint0.Id; g1.Description = data.goal_1; g1.CategoryId = 1; db.Goals.Add(g1); db.SaveChanges(); if (data.goal_2 != null) { g2.SprintId = sprint0.Id; g2.Description = data.goal_2; g2.CategoryId = 2; db.Goals.Add(g2); db.SaveChanges(); } if (data.goal_3 != null) { g3.SprintId = sprint0.Id; g3.Description = data.goal_3; g3.CategoryId = 3; db.Goals.Add(g3); db.SaveChanges(); } user.Vision = data.vision; user.Statement1 = data.activity_1; if (data.activity_2 != null) { user.Statement2 = data.activity_2; } if (data.activity_3 != null) { user.Statement3 = data.activity_3; } user.LifeSuccess = data.determine_success; db.SaveChanges(); ViewBag.questData = data; return(RedirectToAction("UserSetup", "SprintActivities", new { sprint = sprint0 })); } ViewBag.ErrorMsg = "An unexpected error occurred, please try again later"; return(View("Error")); }