public ActionResult Update(int Category, int ParentSurveyCompletionId, string PartialSaveKey, int SurveyCompletionId) { var surveysCompletion = modelContext .SurveysCompletion .Include("CategoryObj") .Include("Questions") .FirstOrDefault(x => x.Id == SurveyCompletionId); var questions = modelContext .Questions .Include("Survey") .Where(x => x.Survey.Id == surveysCompletion.SurveyId) .Select(x => new SurveyQuestionDTO { QuestionId = x.Id, Question = x.DemandQuestion, Required = x.DemandRequired, Old = x.Old }) .ToList(); ViewBag.survey = surveysCompletion; ViewBag.Category = Category; ViewBag.ParentSurveyCompletionId = ParentSurveyCompletionId; ViewBag.PartialSaveKey = PartialSaveKey; ViewBag.SurveyCompletionId = SurveyCompletionId; var model = new SurveyUpdateViewModel() { SurveyQuestionDTOs = questions, }; return(View("~/Views/Demanda/Continue/CategoryUpdate.cshtml", model)); }
public ActionResult updateSurvey(int id) { var surveysCompletion = modelContext .SurveysCompletion .Include("CategoryObj") .Include("Questions") .FirstOrDefault(x => x.Id == id); var answeredQuestionIds = new List <int>(); surveysCompletion .Questions .ToList() .ForEach(x => answeredQuestionIds.Add(x.QuestionId)); var questions = modelContext .Questions .Include("Survey") .Where(x => x.Survey.Id == surveysCompletion.SurveyId) // && !answeredQuestionIds.Contains(x.Id) && x.Old == false) .Select(x => new SurveyQuestionDTO { QuestionId = x.Id, Question = x.SupplyQuestion, Required = x.SupplyRequired, Old = x.Old }) .ToList(); ViewBag.survey = surveysCompletion; var userId = this.User.Identity.GetUserId(); var user = modelContext .Users .Single(x => x.Id == userId); if (!user.CompanyId.HasValue) { throw new ArgumentNullException("User company id is null"); } var model = new SurveyUpdateViewModel() { CompanyId = user.CompanyId.Value, SurveyQuestionDTOs = questions, }; return(View("~/Views/Oferta/UpdateSurvey.cshtml", model)); }