public IActionResult Add(int id) { CreateSurveyViewModel model = new CreateSurveyViewModel(); model.CompanyName = dbContext.Companies.Include(c => c.Owner).Where(c => c.Id == id).FirstOrDefault().Title; return(View(model)); }
public async Task <IActionResult> AddOrEditQuestion(CreateSurveyViewModel createSurveyViewModel, Guid id, int?questionId) { if (questionId != null && ModelState.IsValid) { var survey = await _surveyService.EditQuestion(id, questionId ?? 0, createSurveyViewModel.QuestionText); return(RedirectToAction("Index", new { id = survey.Id })); } else if (ModelState.IsValid) { var survey = await _surveyService.AddQuestion(id, createSurveyViewModel.QuestionText); return(RedirectToAction("Index", new { id = survey.Id })); } else { //Get the survey var survey = await _surveyService.Get(id); //Decorate the ViewModel createSurveyViewModel.SurveyId = survey.Id; createSurveyViewModel.QuestionToEdit = questionId; createSurveyViewModel.QuestionText = questionId == null ? "" : survey.Questions[questionId ?? default(int)].Text; createSurveyViewModel.SurveyTitle = survey.Title; createSurveyViewModel.SurveyDescription = survey.Description; createSurveyViewModel.SurveyQuestions = survey.Questions; //Return the Index view return(View("Index", createSurveyViewModel)); } }
private void CreateSurveyMap(CreateSurveyViewModel createSurvey, Survey survey) { survey.Name = createSurvey.Name; survey.SurveyDate = createSurvey.SurveyDate; survey.SurveyQuestion = createSurvey.SurveyQuestion; survey.Description = createSurvey.Description; survey.CreatedBy = createSurvey.CreatedBy; survey.Category = createSurvey.Category; survey.ModifiedDateTime = DateTime.Now; }
public IActionResult Create(int?ownerId = 1) { var surveyViewModel = new CreateSurveyViewModel(); var customers = customerService.GetAll(); var surveyTemplates = surveyTemplateService.GetAll(1); surveyViewModel.Customers = customers.ToList(); surveyViewModel.SurveyTemplates = surveyTemplates.ToList(); return(View(surveyViewModel)); }
public string SaveSurvey(CreateSurveyViewModel createSurvey) { try { Survey survey = new Survey(); CreateSurveyMap(createSurvey, survey); repository.Insert(survey); repository.Commit(); return("Details saved successfully"); } catch (Exception ex) { //Exception return("Email Id or phone number already registered"); } }
public async Task <IActionResult> Index(Guid id, int?questionId) { //Get the relevant survey var survey = await _surveyService.Get(id); //Decorate the ViewModel var createSurveyViewModel = new CreateSurveyViewModel { SurveyId = survey.Id, QuestionToEdit = questionId, QuestionText = questionId == null ? "" : survey.Questions[questionId ?? default(int)].Text, SurveyTitle = survey.Title, SurveyDescription = survey.Description, SurveyQuestions = survey.Questions }; //return the view return(View(createSurveyViewModel)); }
public IActionResult Create(CreateSurveyViewModel createSurveyViewModel) { var identityClaim = User.Claims.Where(claim => claim.Type == ClaimTypes.NameIdentifier); var userId = identityClaim.FirstOrDefault().Value; var survey = new Survey(); var surveyTemplate = surveyTemplateService.GetById(createSurveyViewModel.SurveyTemplateId); if (ModelState.IsValid) { survey.SurveyTemplateId = createSurveyViewModel.SurveyTemplateId; survey.SurveyStateId = 1; survey.CustomerId = createSurveyViewModel.CustomerId; survey.UserId = userId; surveyService.Save(survey); return(RedirectToAction("Index", "AnswerGroups", new { id = survey.Id })); } return(View(survey)); }
public async Task <IActionResult> Add(CreateSurveyViewModel model) { if (ModelState.IsValid) { Survey survey = new Survey(); User user = await userManager.FindByNameAsync(model.Username); survey.UserId = user.Id; survey.Username = User.Identity.Name; survey.Company = dbContext.Companies.Where(c => c.Title == model.CompanyName).FirstOrDefault(); survey.CompanyId = dbContext.Companies.Where(c => c.Title == model.CompanyName).FirstOrDefault().Id; survey.Content = model.Content; dbContext.SaveChanges(); surveyRepository.Add(survey); return(RedirectToAction("Details", "Survey", new { id = survey.Id })); } return(View(model)); }
public IActionResult CreateSurvey([FromBody] CreateSurveyViewModel survey)//CreateProperViewModel { return(Ok(service.SaveSurvey(survey))); }