//ADD QUESTION ANSWER/////
 public ActionResult AddAnswer(int qId)
 {
     Answer q = new Answer();
     q.Index = _context.Questions.ToList().Find(x => x.Id == qId).Answers.Count() + 1;
     q.QuestionId = qId;
     return View(q);
 }
        public ActionResult AddAnswer(Answer answer)
        {
            if (ModelState.IsValid)
            {
                _context.Questions.ToList().Find(x => x.Id == answer.QuestionId).Answers.Add(answer);

                Answer entry = _context.Entry(answer).Entity;
                _context.SaveChanges();
                return RedirectToAction("Edit/" + answer.QuestionId);
            }

            return View(answer);
        }
        private void shiftIndexes(Answer entry, int oldIndex, IEnumerable<Answer> dbset)
        {
            if (entry.Index - oldIndex == 1)
            {
                //Move forward by 1 step
                try
                {
                    dbset.First(x => x.Index == entry.Index).Index = oldIndex; //If was last row - it will throw an exception
                }
                catch (Exception e)
                { }
            }
            else if (entry.Index > oldIndex)
            {
                //We moved forward
                foreach (var q in dbset.ToList())
                {
                    if (oldIndex < q.Index && q.Index < entry.Index)
                        q.Index = q.Index - 1;
                }
                entry.Index = entry.Index - 1;
            }
            else if (entry.Index < oldIndex)
            {
                //We moved backwards
                foreach (var q in dbset.ToList())
                {
                    if (entry.Index <= q.Index && q.Index < oldIndex)
                        q.Index = q.Index + 1;
                }
            }

            if (entry.Index > dbset.Count())
                entry.Index = dbset.Count();
            else if (entry.Index < 1)
                entry.Index = 1;
        }
 public ActionResult EditAnswer(Answer answer)
 {
     if (ModelState.IsValid)
     {
         _context.Entry(answer).State = EntityState.Modified;
         _context.SaveChanges();
         return RedirectToAction("Edit", new { id = answer.QuestionId });
     }
     return View(answer);
 }