the add method of questionnaire created
This commit is contained in:
parent
78ed96237d
commit
59d86a516e
16 changed files with 1083 additions and 105 deletions
|
|
@ -9,16 +9,19 @@ namespace Model
|
|||
{
|
||||
public class Question
|
||||
{
|
||||
public Question()
|
||||
{
|
||||
Answers=new List<Answer>();
|
||||
}
|
||||
public int Id { get; set; }
|
||||
public string? Text { get; set; }
|
||||
public QuestionType Type { get; set; }
|
||||
|
||||
// Foreign key for Questionnaire
|
||||
|
||||
public int QuestionnaireId { get; set; } // Foreign key for Questionnaire
|
||||
public int QuestionnaireId { get; set; }
|
||||
[ForeignKey("QuestionnaireId")]
|
||||
public Questionnaire? Questionnaire { get; set; }
|
||||
|
||||
public List<Answer>? Answers { get; set; }
|
||||
public List<Answer> Answers { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ namespace Model
|
|||
{
|
||||
public class Questionnaire
|
||||
{
|
||||
public Questionnaire()
|
||||
{
|
||||
Questions = new List<Question>();
|
||||
}
|
||||
public int Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
|
|
|
|||
40
Services/Implemnetation/QuestionRepository.cs
Normal file
40
Services/Implemnetation/QuestionRepository.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using Data;
|
||||
using Model;
|
||||
using Services.Interaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Services.Implemnetation
|
||||
{
|
||||
public class QuestionRepository : IQuestionRepository
|
||||
{
|
||||
private readonly SurveyContext _context;
|
||||
|
||||
public QuestionRepository(SurveyContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public void Add(Question question)
|
||||
{
|
||||
_context.Questions.Add(question);
|
||||
}
|
||||
|
||||
public async Task commitAsync()
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public List<Question> GetAllQuestions()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Question GetQuestionById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
20
Services/Interaces/IQuestionRepository.cs
Normal file
20
Services/Interaces/IQuestionRepository.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Services.Interaces
|
||||
{
|
||||
public interface IQuestionRepository
|
||||
{
|
||||
List<Question> GetAllQuestions();
|
||||
|
||||
Question GetQuestionById(int id);
|
||||
|
||||
void Add(Question question);
|
||||
|
||||
Task commitAsync();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Data;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Model;
|
||||
using Services.Interaces;
|
||||
|
|
@ -9,10 +10,14 @@ namespace Web.Areas.Admin.Controllers
|
|||
public class QuestionnaireController : Controller
|
||||
{
|
||||
private readonly IQuestionnaireRepository _questionnaire;
|
||||
private readonly SurveyContext _context;
|
||||
private readonly IQuestionRepository _question;
|
||||
|
||||
public QuestionnaireController(IQuestionnaireRepository Questionnaire)
|
||||
public QuestionnaireController(IQuestionnaireRepository Questionnaire,SurveyContext Context, IQuestionRepository Question)
|
||||
{
|
||||
_questionnaire = Questionnaire;
|
||||
_context = Context;
|
||||
_question = Question;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
|
|
@ -37,20 +42,35 @@ namespace Web.Areas.Admin.Controllers
|
|||
}
|
||||
[HttpGet]
|
||||
public IActionResult Create()
|
||||
|
||||
|
||||
{
|
||||
|
||||
var questionTypes = Enum.GetValues(typeof(QuestionType)).Cast<QuestionType>();
|
||||
|
||||
ViewBag.QuestionTypes = new SelectList(questionTypes);
|
||||
|
||||
var questionnaire = new QuestionnaireViewModel
|
||||
{
|
||||
Questions = new List<Question>()
|
||||
|
||||
Questions = new List<Question>(),
|
||||
Answers = new List<Answer>()
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
return View(questionnaire);
|
||||
}
|
||||
[HttpPost]
|
||||
public IActionResult Create(QuestionnaireViewModel viewmodel)
|
||||
public async Task<IActionResult> Create(QuestionnaireViewModel viewmodel)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
||||
|
|
@ -59,23 +79,76 @@ namespace Web.Areas.Admin.Controllers
|
|||
Id=viewmodel.Id,
|
||||
Title=viewmodel.Title,
|
||||
Description=viewmodel.Description,
|
||||
};
|
||||
|
||||
|
||||
var questions = viewmodel.Questions;
|
||||
|
||||
foreach (var questionViewModel in viewmodel.Questions)
|
||||
{
|
||||
var question = new Question
|
||||
{
|
||||
QuestionnaireId=questionViewModel.QuestionnaireId,
|
||||
Text = questionViewModel.Text,
|
||||
Type = questionViewModel.Type,
|
||||
Answers = new List<Answer>() // Initialize the list of answers for each question
|
||||
};
|
||||
|
||||
foreach (var answerViewModel in questionViewModel.Answers)
|
||||
{
|
||||
var answer = new Answer
|
||||
{
|
||||
Text = answerViewModel.Text,
|
||||
QuestionId=answerViewModel.QuestionId,
|
||||
|
||||
};
|
||||
|
||||
foreach (var item in viewmodel.Questions)
|
||||
{
|
||||
questionnaire.Questions.Add(item);
|
||||
// Add the answer to the list of answers for the current question
|
||||
question.Answers.Add(answer);
|
||||
}
|
||||
|
||||
// Add the question to the list of questions for the questionnaire
|
||||
questionnaire.Questions.Add(question);
|
||||
}
|
||||
|
||||
|
||||
//var answers = questions.Where(x => x.Answers == viewmodel.Answers);
|
||||
|
||||
|
||||
//foreach (var question in questions)
|
||||
//{
|
||||
|
||||
// questionnaire.Questions.Add(new Question
|
||||
// {
|
||||
// Id = question.Id,
|
||||
// Text=question.Text,
|
||||
// Type=question.Type,
|
||||
// QuestionnaireId=questionnaire.Id,
|
||||
|
||||
|
||||
// });
|
||||
|
||||
// //foreach(var answer in answers)
|
||||
// //{
|
||||
// // question.Answers.Add(new Answer
|
||||
// // {
|
||||
// // Id=answer
|
||||
// // });
|
||||
// //}
|
||||
|
||||
|
||||
//}
|
||||
|
||||
_questionnaire.Add(questionnaire);
|
||||
|
||||
_questionnaire.commitAsync();
|
||||
await _questionnaire.commitAsync();
|
||||
TempData["Success"] = "Questionnaire created successfully";
|
||||
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return View(viewmodel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,3 +66,111 @@
|
|||
|
||||
|
||||
|
||||
@* <div class="container mt-4">
|
||||
<div class="card justify-content-center">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Create Survey</h5>
|
||||
|
||||
<div class="row ">
|
||||
<!-- 12 columns for textboxes -->
|
||||
|
||||
<form asp-action="Create" asp-controller="Questionnaire">
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
|
||||
<div class="mb-3 col-12">
|
||||
<label asp-for="Title" class="control-label"></label>
|
||||
<input asp-for="Title" class="form-control" />
|
||||
<span asp-validation-for="Title" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="mb-3 col-12">
|
||||
<label asp-for="Description" class="control-label"></label>
|
||||
<input asp-for="Description" class="form-control" />
|
||||
<span asp-validation-for="Description" class="text-danger"></span>
|
||||
</div>
|
||||
@foreach (var item in Model.Questions)
|
||||
{
|
||||
<label asp-for="@item.Id" class="control-label"></label>
|
||||
<input asp-for="@item.Id" class="form-control" />
|
||||
<label asp-for="@item.Text" class="control-label"></label>
|
||||
<input asp-for="@item.Text" class="form-control" />
|
||||
|
||||
<select name="Questions.Type" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>
|
||||
@foreach (var questionType in ViewBag.QuestionTypes)
|
||||
{
|
||||
<option value="@questionType.Value">@questionType.Text</option>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
<div class="container">
|
||||
<div id="questions-container">
|
||||
<h3>Create Questions</h3>
|
||||
<div class="form-group">
|
||||
@for (int i = 0; i < Model.Questions?.Count; i++)
|
||||
{
|
||||
<div class="question-group">
|
||||
<input type="hidden" name="Questions[0].Id" value="1" />
|
||||
<label>Question @(i + 1)</label>
|
||||
<textarea name="Questions[@i].Text" class="form-control">@Model.Questions[i].Text</textarea>
|
||||
|
||||
<select name="Questions[@i].Type" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>
|
||||
@foreach (var questionType in ViewBag.QuestionTypes)
|
||||
{
|
||||
<option value="@questionType.Value">@questionType.Text</option>
|
||||
}
|
||||
</select>
|
||||
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" id="add-question">Add Question</button> |
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
| <a asp-action="Index" class="btn btn-info">Back to list</a>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
|
||||
|
||||
|
||||
|
||||
@section Scripts {
|
||||
|
||||
@{
|
||||
<partial name="_ValidationScriptsPartial" />
|
||||
}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var Questions = @Model.Questions?.Count;
|
||||
|
||||
$("#add-question").on("click", function () {
|
||||
var newQuestionHtml = '<div class="form-group">' +
|
||||
'<label>Question ' + (++Questions) + '</label>' +
|
||||
'<textarea type="text" name="Questions[' + Questions + '].Text" class="form-control"></textarea>' + '<br>' +
|
||||
'<select name="Questions[' + Questions + '].Type" class="form-control">';
|
||||
|
||||
newQuestionHtml += '<option value="">Select Question Type</option>';
|
||||
|
||||
|
||||
@foreach (var questionType in ViewBag.QuestionTypes)
|
||||
{
|
||||
@:newQuestionHtml += '<option value="@questionType.Value">@questionType.Text</option>';
|
||||
}
|
||||
|
||||
newQuestionHtml += '</select></div>';
|
||||
|
||||
$("#questions-container").append(newQuestionHtml);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
} *@
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
@model Web.ViewModel.QuestionnaireVM.QuestionnaireViewModel
|
||||
|
||||
@model QuestionnaireViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
|
||||
<div class="container mt-4">
|
||||
<div class="card justify-content-center">
|
||||
<div class="card-body">
|
||||
|
|
@ -24,7 +26,6 @@
|
|||
<input asp-for="Description" class="form-control" />
|
||||
<span asp-validation-for="Description" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div id="questions-container">
|
||||
<h3>Create Questions</h3>
|
||||
<div class="form-group">
|
||||
|
|
@ -32,35 +33,71 @@
|
|||
{
|
||||
<div class="question-group">
|
||||
<label>Question @(i + 1)</label>
|
||||
<textarea name="Questions[@i].Text" class="form-control">@Model.Questions[i].Text</textarea>
|
||||
<br />
|
||||
<br />
|
||||
<div class="mt-5">
|
||||
|
||||
<select name="Questions[@i].Type" class="form-control question-type">
|
||||
|
||||
<textarea name="Questions[@i].Text" class="form-control">Write a question</textarea>
|
||||
<select name="Questions[@i].Type" asp-items="ViewBag.QuestionTypes" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>
|
||||
@foreach (var questionType in ViewBag.QuestionTypes)
|
||||
{
|
||||
<option value="@questionType.Value">@questionType.Text</option>
|
||||
<option value="">Select Question Type</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="answers-container" data-question-index="@i">
|
||||
<label>Answers:</label>
|
||||
@for (int j = 0; j < Model.Answers?.Count; j++)
|
||||
{
|
||||
<div class="answer-group">
|
||||
<input type="text" name="Questions[@i].Answers[@j].Text" class="form-control" value="@Model.Answers?[j]?.Text" />
|
||||
<button type="button" class="btn btn-sm btn-danger remove-answer">Remove Answer</button>
|
||||
</div>
|
||||
}
|
||||
<button type="button" class="btn btn-sm btn-success add-answer">Add Answer</button>
|
||||
<!-- Add a hidden field to address the required field validation -->
|
||||
<input type="hidden" name="Questions[@i].Answers" />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="button" id="add-question-btn" class="btn btn-sm btn-primary">Add Question</button>
|
||||
@* <div class="container">
|
||||
<div id="questions-container">
|
||||
<h3>Create Questions</h3>
|
||||
<div class="form-group">
|
||||
@for (int i = 0; i < Model.Questions?.Count; i++)
|
||||
{
|
||||
<div class="question-group">
|
||||
<label>Question @(i + 1)</label>
|
||||
<textarea name="Questions[@i].Text" class="form-control">Write a question</textarea>
|
||||
<select name="Questions[@i].Type" asp-items="ViewBag.QuestionTypes" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
<div class="answers-container">
|
||||
<label>Answers:</label>
|
||||
@for (int j = 1; j < Model.Questions?[i].Answers?.Count; j++)
|
||||
{
|
||||
<div class="answer-group">
|
||||
<input type="text" name="Questions[@i].Answers[@j].Text" class="form-control" value="@Model.Questions?[i]?.Answers?[j]?.Text" />
|
||||
<button type="button" class="btn btn-sm btn-danger remove-answer">Remove Answer</button>
|
||||
</div>
|
||||
}
|
||||
<button type="button" class="btn btn-sm btn-success add-answer">Add Answer</button>
|
||||
<!-- Add a hidden field to address the required field validation -->
|
||||
<input type="hidden" name="Questions[@i].Answers" />
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" id="add-question">Add Question</button> |
|
||||
<button type="button" id="add-question-btn" class="btn btn-success">Add Question</button>
|
||||
|
||||
</div> *@
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
| <a asp-action="Index" class="btn btn-info">Back to list</a>
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -73,36 +110,263 @@
|
|||
|
||||
|
||||
@section Scripts {
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.11.4/ckeditor.js"></script>
|
||||
<script>
|
||||
CKEDITOR.replace("Questions");
|
||||
</script>
|
||||
|
||||
@{
|
||||
<partial name="_ValidationScriptsPartial" />
|
||||
}
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var questionCounter = @Model.Questions?.Count;
|
||||
var questionIndex = @Model.Questions?.Count;
|
||||
|
||||
$("#add-question").on("click", function () {
|
||||
var newQuestionHtml = '<div class="form-group">' +
|
||||
'<label>Question ' + (++questionCounter) + '</label>' +
|
||||
'<textarea type="text" name="Questions[' + questionCounter + '].Text" class="form-control"></textarea>' +'<br>' +
|
||||
'<select name="Questions[' + questionCounter + '].Type" class="form-control">';
|
||||
$("#add-question-btn").click(function () {
|
||||
var newQuestionHtml = `
|
||||
<div class="question-group">
|
||||
<label>Question ${questionIndex + 1}</label>
|
||||
<textarea name="Questions[${questionIndex}].Text" class="form-control"></textarea>
|
||||
<select name="Questions[${questionIndex}].Type" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>`;
|
||||
|
||||
newQuestionHtml += '<option value="">Select Question Type</option>';
|
||||
var questionTypes = @Html.Raw(Json.Serialize(Enum.GetNames(typeof(QuestionType))));
|
||||
|
||||
|
||||
@foreach (var questionType in ViewBag.QuestionTypes)
|
||||
{
|
||||
@:newQuestionHtml += '<option value="@questionType.Value">@questionType.Text</option>';
|
||||
for (var i = 0; i < questionTypes.length; i++) {
|
||||
newQuestionHtml += `<option value="${questionTypes[i]}">${questionTypes[i]}</option>`;
|
||||
}
|
||||
|
||||
newQuestionHtml += '</select></div>';
|
||||
newQuestionHtml += `</select>`;
|
||||
|
||||
$("#questions-container").append(newQuestionHtml);
|
||||
// Add answers input fields
|
||||
newQuestionHtml += `<div class="answers-container" data-question-index="${questionIndex}">`;
|
||||
newQuestionHtml += `<label>Answers:</label>`;
|
||||
newQuestionHtml += `<div class="answer-group" data-answer-index="0">`;
|
||||
newQuestionHtml += `<input type="text" name="Questions[${questionIndex}].Answers[0].Text" class="form-control" placeholder="Answer 1" />`;
|
||||
newQuestionHtml += `<button type="button" class="btn btn-sm btn-success add-answer">Add Answer</button>`;
|
||||
newQuestionHtml += `<button type="button" class="btn btn-sm btn-danger remove-answer" style="display:none">Remove Answer</button>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
$("#questions-container .form-group").append(newQuestionHtml);
|
||||
questionIndex++;
|
||||
});
|
||||
|
||||
// Add answer dynamically without "Add Answer" button
|
||||
$("#questions-container").on("click", ".add-answer", function () {
|
||||
var questionIndex = $(this).closest('.answers-container').data('question-index');
|
||||
var answerIndex = $(this).closest('.answers-container').find('.answer-group').length;
|
||||
var answerGroup = $(this).closest('.answers-container').find('.answer-group:first').clone();
|
||||
answerGroup.find('input').val(''); // Clear input values
|
||||
answerGroup.find('.add-answer').hide(); // Hide the "Add Answer" button
|
||||
answerGroup.find('.remove-answer').show(); // Show the "Remove Answer" button
|
||||
answerGroup.data('answer-index', answerIndex);
|
||||
answerGroup.find('input').attr('name', `Questions[${questionIndex}].Answers[${answerIndex}].Text`);
|
||||
$(this).closest('.answers-container').append(answerGroup);
|
||||
});
|
||||
|
||||
// Remove answer dynamically
|
||||
$("#questions-container").on("click", ".remove-answer", function () {
|
||||
$(this).closest('.answer-group').remove();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@* <script>
|
||||
$(document).ready(function () {
|
||||
var questionIndex = @Model.Questions?.Count;
|
||||
|
||||
$("#add-question-btn").click(function () {
|
||||
var newQuestionHtml = `
|
||||
<div class="question-group">
|
||||
<label>Question ${questionIndex + 1}</label>
|
||||
<textarea name="Questions[${questionIndex}].Text" class="form-control"></textarea>
|
||||
<select name="Questions[${questionIndex}].Type" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>`;
|
||||
|
||||
var questionTypes = @Html.Raw(Json.Serialize(Enum.GetNames(typeof(QuestionType))));
|
||||
|
||||
for (var i = 0; i < questionTypes.length; i++) {
|
||||
newQuestionHtml += `<option value="${questionTypes[i]}">${questionTypes[i]}</option>`;
|
||||
}
|
||||
|
||||
newQuestionHtml += `</select>`;
|
||||
|
||||
// Add answers input fields
|
||||
newQuestionHtml += `<div class="answers-container" data-question-index="${questionIndex}">`;
|
||||
newQuestionHtml += `<label>Answers:</label>`;
|
||||
newQuestionHtml += `<div class="answer-group" data-answer-index="0">`;
|
||||
newQuestionHtml += `<input type="text" name="Questions[${questionIndex}].Answers[0].Text" class="form-control" placeholder="Answer 1" />`;
|
||||
newQuestionHtml += `<button type="button" class="btn btn-sm btn-success add-answer">Add Answer</button>`;
|
||||
newQuestionHtml += `<button type="button" class="btn btn-sm btn-danger remove-answer" style="display:none">Remove Answer</button>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
$("#questions-container .form-group").append(newQuestionHtml);
|
||||
questionIndex++;
|
||||
});
|
||||
|
||||
// Add answer dynamically without "Add Answer" button
|
||||
$("#questions-container").on("click", ".add-answer", function () {
|
||||
var questionIndex = $(this).closest('.answers-container').data('question-index');
|
||||
var answerIndex = $(this).closest('.answer-group').data('answer-index') + 1;
|
||||
var answerGroup = $(this).closest('.answers-container').find('.answer-group:first').clone();
|
||||
answerGroup.find('input').val(''); // Clear input values
|
||||
answerGroup.find('.add-answer').hide(); // Hide the "Add Answer" button
|
||||
answerGroup.find('.remove-answer').show(); // Show the "Remove Answer" button
|
||||
answerGroup.data('answer-index', answerIndex);
|
||||
answerGroup.find('input').attr('name', `Questions[${questionIndex}].Answers[${answerIndex}].Text`);
|
||||
$(this).closest('.answers-container').append(answerGroup);
|
||||
});
|
||||
|
||||
// Remove answer dynamically
|
||||
$("#questions-container").on("click", ".remove-answer", function () {
|
||||
$(this).closest('.answer-group').remove();
|
||||
});
|
||||
});
|
||||
</script> *@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@* <script>
|
||||
$(document).ready(function () {
|
||||
var questionIndex = @Model.Questions?.Count ?? 0;
|
||||
|
||||
function addQuestion() {
|
||||
var newQuestionHtml = `
|
||||
<div class="question-group">
|
||||
<label>Question ${questionIndex + 1}</label>
|
||||
<textarea name="Questions[${questionIndex}].Text" class="form-control"></textarea>
|
||||
<br>
|
||||
<br>
|
||||
<select name="Questions[${questionIndex}].Type" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>`;
|
||||
|
||||
var questionTypes = @Html.Raw(Json.Serialize(Enum.GetNames(typeof(QuestionType))));
|
||||
|
||||
for (var i = 0; i < questionTypes.length; i++) {
|
||||
newQuestionHtml += `<option value="${questionTypes[i]}">${questionTypes[i]}</option>`;
|
||||
}
|
||||
|
||||
newQuestionHtml += `</select>`;
|
||||
|
||||
// Add answers input fields
|
||||
newQuestionHtml += `<div class="answers-container">`;
|
||||
newQuestionHtml += `<label>Answers:</label>`;
|
||||
newQuestionHtml += `<div class="answer-group">`;
|
||||
newQuestionHtml += `<input type="text" name="Questions[${questionIndex}].Answers[0].Text" class="form-control" placeholder="Answer 1" />`;
|
||||
newQuestionHtml += `<button type="button" class="btn btn-sm btn-success add-answer">Add Answer</button>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
$("#questions-container .form-group").append(newQuestionHtml);
|
||||
questionIndex++;
|
||||
}
|
||||
|
||||
function addAnswer(answerGroup) {
|
||||
var newAnswerGroup = answerGroup.clone();
|
||||
newAnswerGroup.find('input').val(''); // Clear input values
|
||||
newAnswerGroup.find('.add-answer').remove(); // Remove the "Add Answer" button
|
||||
answerGroup.closest('.answers-container').append(newAnswerGroup);
|
||||
}
|
||||
|
||||
// Add question dynamically
|
||||
$("#add-question-btn").click(function () {
|
||||
addQuestion();
|
||||
});
|
||||
|
||||
// Add answer dynamically
|
||||
$("#questions-container").on("click", ".add-answer", function () {
|
||||
var answerGroup = $(this).closest('.question-group').find('.answer-group:first');
|
||||
addAnswer(answerGroup);
|
||||
});
|
||||
});
|
||||
</script> *@
|
||||
|
||||
@* <script>
|
||||
$(document).ready(function () {
|
||||
var questionIndex = @Model.Questions?.Count ?? 0;
|
||||
|
||||
$("#add-question-btn").click(function () {
|
||||
var newQuestionHtml = `
|
||||
<div class="question-group">
|
||||
<label>Question ${questionIndex + 1}</label>
|
||||
<textarea name="Questions[${questionIndex}].Text" class="form-control"></textarea>
|
||||
<br>
|
||||
<br>
|
||||
<select name="Questions[${questionIndex}].Type" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>`;
|
||||
|
||||
var questionTypes = @Html.Raw(Json.Serialize(Enum.GetNames(typeof(QuestionType))));
|
||||
|
||||
for (var i = 0; i < questionTypes.length; i++) {
|
||||
newQuestionHtml += `<option value="${questionTypes[i]}">${questionTypes[i]}</option>`;
|
||||
}
|
||||
|
||||
newQuestionHtml += `</select>`;
|
||||
|
||||
// Add answers input fields
|
||||
newQuestionHtml += `<div class="answers-container">`;
|
||||
newQuestionHtml += `<label>Answers:</label>`;
|
||||
newQuestionHtml += `<div class="answer-group">`;
|
||||
newQuestionHtml += `<input type="text" name="Questions[${questionIndex}].Answers[0].Text" class="form-control" placeholder="Answer 1" />`;
|
||||
newQuestionHtml += `<button type="button" class="btn btn-sm btn-success add-answer">Add Answer</button>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
newQuestionHtml += `</div>`;
|
||||
|
||||
$("#questions-container .form-group").append(newQuestionHtml);
|
||||
questionIndex++;
|
||||
});
|
||||
|
||||
// Add answer dynamically without "Add Answer" button
|
||||
$("#questions-container").on("click", ".add-answer", function () {
|
||||
var answerGroup = $(this).closest('.question-group').find('.answer-group:first').clone();
|
||||
answerGroup.find('input').val(''); // Clear input values
|
||||
$(this).closest('.answers-container').append(answerGroup);
|
||||
});
|
||||
});
|
||||
</script> *@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@* <script>
|
||||
$(document).ready(function () {
|
||||
var questionIndex = @Model.Questions.Count;
|
||||
|
||||
$("#add-question-btn").click(function () {
|
||||
var newQuestionHtml = `
|
||||
<div class="question-group">
|
||||
<label>Question ${questionIndex + 1}</label>
|
||||
<textarea name="Questions[${questionIndex}].Text" class="form-control"></textarea>
|
||||
<select name="Questions[${questionIndex}].Type" class="form-control question-type">
|
||||
<option value="">Select Question Type</option>`;
|
||||
|
||||
var questionTypes = @Html.Raw(Json.Serialize(Enum.GetNames(typeof(QuestionType))));
|
||||
|
||||
for (var i = 0; i < questionTypes.length; i++) {
|
||||
newQuestionHtml += `<option value="${questionTypes[i]}">${questionTypes[i]}</option>`;
|
||||
}
|
||||
|
||||
newQuestionHtml += `</select></div>`;
|
||||
|
||||
$("#questions-container .form-group").append(newQuestionHtml);
|
||||
questionIndex++;
|
||||
});
|
||||
});
|
||||
</script> *@
|
||||
|
||||
}
|
||||
|
|
@ -1,47 +1,65 @@
|
|||
@model IEnumerable<Web.ViewModel.QuestionnaireVM.QuestionnaireViewModel>
|
||||
@model IEnumerable<QuestionnaireViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Index";
|
||||
ViewData["Title"] = "Questionnaire";
|
||||
}
|
||||
<div class="container-fluid mt-5">
|
||||
|
||||
<h1>Index</h1>
|
||||
<partial name="_Notification" />
|
||||
|
||||
<div class="card bg-default mb-3 ">
|
||||
<div class="card-header">Questionnaire</div>
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Questionnaire list</h4>
|
||||
<p>
|
||||
<a asp-action="Create">Create New</a>
|
||||
<a asp-action="Create" class="btn btn-primary">Create New</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
||||
<table class="table table-responsive w-100 d-block d-md-table">
|
||||
<thead class="w-auto">
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Id)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Title)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Description)
|
||||
</th>
|
||||
<th></th>
|
||||
|
||||
<th scope="col">Id</th>
|
||||
<th scope="col">Title</th>
|
||||
<th scope="col">Description</th>
|
||||
<th scope="col">Qaustion & Questions Type</th>
|
||||
<th scope="col" class="d-flex justify-content-end">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model) {
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
<tbody class="w-auto">
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr class="table-secondary">
|
||||
|
||||
<td>@item.Id</td>
|
||||
<td> @item.Title</td>
|
||||
<td>@item.Description</td>
|
||||
|
||||
<td class="h5">
|
||||
|
||||
@foreach (var question in item.Questions)
|
||||
{
|
||||
|
||||
<span class="badge bg-primary"> Question:@question.Text</span>
|
||||
<span class="badge bg-info">Type: @question.Type</span>
|
||||
}
|
||||
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Description)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
|
||||
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
|
||||
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
|
||||
|
||||
|
||||
<td class="d-flex justify-content-end">
|
||||
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger btn-s"><i class="bi bi-trash"></i> Delete</a> |
|
||||
<a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-warning btn-s"><i class="bi bi-pencil-square"></i> Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
@using Web
|
||||
@using Model
|
||||
@using Web.Models
|
||||
@using Web.ViewModel
|
||||
@using Web.ViewModel.AddressVM
|
||||
|
|
|
|||
|
|
@ -42,5 +42,9 @@ namespace Web.Extesions
|
|||
{
|
||||
services.AddScoped<IQuestionnaireRepository, QuestionnaireRepository>();
|
||||
}
|
||||
public static void ConfigureQuestion(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IQuestionRepository, QuestionRepository>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
371
Web/Migrations/20240308144608_DifferntTypeofQuestionAdded.Designer.cs
generated
Normal file
371
Web/Migrations/20240308144608_DifferntTypeofQuestionAdded.Designer.cs
generated
Normal file
|
|
@ -0,0 +1,371 @@
|
|||
// <auto-generated />
|
||||
using System;
|
||||
using Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Web.Migrations
|
||||
{
|
||||
[DbContext(typeof(SurveyContext))]
|
||||
[Migration("20240308144608_DifferntTypeofQuestionAdded")]
|
||||
partial class DifferntTypeofQuestionAdded
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Model.Address", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CVR")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("City")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Country")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Mobile")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PostalCode")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("State")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Street")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Addresss");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Answer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("QuestionId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("QuestionId");
|
||||
|
||||
b.ToTable("Answers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Banner", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ImageUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("LinkUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Banners");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Footer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("CreatedBy")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ImageUlr")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Owner")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Sitecopyright")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UpdatedBy")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Footers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.FooterSocialMedia", b =>
|
||||
{
|
||||
b.Property<int>("FooterId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SocialId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("FooterId", "SocialId");
|
||||
|
||||
b.HasIndex("SocialId");
|
||||
|
||||
b.ToTable("FooterSocialMedias");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Page", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BannerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BannerId");
|
||||
|
||||
b.ToTable("Pages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Question", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("QuestionnaireId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("QuestionnaireId");
|
||||
|
||||
b.ToTable("Questions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.QuestionTypeEntities", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("QuestionTypeEntities");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Questionnaire", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Questionnaires");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.SocialMedia", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("SocialMedia");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Answer", b =>
|
||||
{
|
||||
b.HasOne("Model.Question", "Question")
|
||||
.WithMany("Answers")
|
||||
.HasForeignKey("QuestionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Question");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.FooterSocialMedia", b =>
|
||||
{
|
||||
b.HasOne("Model.Footer", "Footer")
|
||||
.WithMany("FooterSocialMedias")
|
||||
.HasForeignKey("FooterId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Model.SocialMedia", "SocialMedia")
|
||||
.WithMany("FooterSocialMedias")
|
||||
.HasForeignKey("SocialId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Footer");
|
||||
|
||||
b.Navigation("SocialMedia");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Page", b =>
|
||||
{
|
||||
b.HasOne("Model.Banner", "banner")
|
||||
.WithMany()
|
||||
.HasForeignKey("BannerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("banner");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Question", b =>
|
||||
{
|
||||
b.HasOne("Model.Questionnaire", "Questionnaire")
|
||||
.WithMany("Questions")
|
||||
.HasForeignKey("QuestionnaireId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Questionnaire");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Footer", b =>
|
||||
{
|
||||
b.Navigation("FooterSocialMedias");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Question", b =>
|
||||
{
|
||||
b.Navigation("Answers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.Questionnaire", b =>
|
||||
{
|
||||
b.Navigation("Questions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Model.SocialMedia", b =>
|
||||
{
|
||||
b.Navigation("FooterSocialMedias");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Web/Migrations/20240308144608_DifferntTypeofQuestionAdded.cs
Normal file
22
Web/Migrations/20240308144608_DifferntTypeofQuestionAdded.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Web.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class DifferntTypeofQuestionAdded : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ builder.Services.ConfigureAddress();
|
|||
builder.Services.ConfigureSocialMedia();
|
||||
builder.Services.ConfigureFooter();
|
||||
builder.Services.ConfigureQuestionnarie();
|
||||
builder.Services.ConfigureQuestion();
|
||||
//builder.Services.AddScoped<SurveyContext>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
|
|
|||
14
Web/ViewModel/AnswerVM/AnswerViewModel.cs
Normal file
14
Web/ViewModel/AnswerVM/AnswerViewModel.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using Model;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Web.ViewModel.AnswerVM
|
||||
{
|
||||
public class AnswerViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Text { get; set; }
|
||||
public int QuestionId { get; set; } // Foreign key for Question
|
||||
[ForeignKey("QuestionId")]
|
||||
public Question? Question { get; set; }
|
||||
}
|
||||
}
|
||||
24
Web/ViewModel/QuestionVM/QuestionViewModel.cs
Normal file
24
Web/ViewModel/QuestionVM/QuestionViewModel.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Model;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Web.ViewModel.AnswerVM;
|
||||
|
||||
|
||||
namespace Web.ViewModel.QuestionVM
|
||||
{
|
||||
public class QuestionViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string? Text { get; set; }
|
||||
public QuestionType Type { get; set; }
|
||||
|
||||
// Foreign key for Questionnaire
|
||||
|
||||
public int QuestionnaireId { get; set; } // Foreign key for Questionnaire
|
||||
[ForeignKey("QuestionnaireId")]
|
||||
public Questionnaire? Questionnaire { get; set; }
|
||||
|
||||
public List<AnswerViewModel>? AnswersViewModel { get; set; }=new List<AnswerViewModel>();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
using Model;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Web.ViewModel.AnswerVM;
|
||||
using Web.ViewModel.QuestionVM;
|
||||
|
||||
namespace Web.ViewModel.QuestionnaireVM
|
||||
{
|
||||
|
|
@ -8,12 +10,21 @@ namespace Web.ViewModel.QuestionnaireVM
|
|||
public QuestionnaireViewModel()
|
||||
{
|
||||
Questions = new List<Question>();
|
||||
|
||||
|
||||
}
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string? Title { get; set; }
|
||||
[Required]
|
||||
public string? Description { get; set; }
|
||||
|
||||
public List<Question>? Questions { get; set; }
|
||||
public List<Answer>? Answers { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue