public ViewResult missionFAQs(string Mission)//loads facts for the selcted mission. Also has form for new question. { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); //get the user id from the cookie int userID = int.Parse(ticket.Name); //go to the mission given in the parameter Missions mission = db.Missions.Find(int.Parse(Mission)); //this object is the one we'll pass to the view. it has user, misison, questions MissionMissionQuestions mmq = new MissionMissionQuestions(); mmq.missions = mission;//set model mission = url mission //assing user to question mmq.user = new Users(); mmq.user.UserID = userID; //get questions for this mission IEnumerable <MissionQuestions> questions = db.Database.SqlQuery <MissionQuestions>("select * from MissionQuestions where MissionID = " + mmq.missions.MissionID); //add questions to model mmq.missionQuestions = questions; return(View(mmq)); }
public ActionResult questionEdit(MissionMissionQuestions mmq) { if (mmq.question.Question != null) //as long as there is a question to add { MissionQuestions mq = new MissionQuestions(); //the new/updated question we will add mq.MissionID = mmq.missions.MissionID; //mission parameter from url mq.UserID = 1; //hard coded for now. but it needs to be the logged in user. mq.Question = mmq.question.Question; //question from the form mq.UserID = mmq.user.UserID; //set the current user as the asker db.MissionQuestions.Add(mq); //add the new question db.SaveChanges(); //save to DB return(RedirectToAction("missionFAQs", new { Mission = mmq.missions.MissionID.ToString() })); } return(View(mmq)); }