Introduction

EasyQuiz is a quiz application project in ASP.NET Core MVC 5.0 which will help us to learn and implement the features in Real-World Applications.

EasyQuiz

Prerequisites

NuGet packages used in this project

Configure and run the project

Database Structure

The structure of the database is very simple. The result table holds the information for the people taking the test.

Folder Structure

Quiz-Application.Web is the main ASP.NET Core project and Quiz-Application.Services contain all Entities. It is also used to access the database and write business logic. Quiz-Application.Services project can be accessed in Quiz-Application.Web project.

Record the Session

WebRTC is used here to record the entire quiz session. Captured Session is stored in a folder.

Generate Score Report (PDF)

DinkToPdf library is used here which uses Webkit engine to convert HTML to PDF for creating the Score Report.

[HttpPost]
[Route("~/api/CreatePDF")]
public async Task<IActionResult> CreatePDF(ReqCertificate argPDFRpt)
{
   ResPDF obj = null;
   try
   {                
       string html = await _result.GetCertificateString(argPDFRpt);
       string UploadFolder = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "UploadedFiles/Report");
       string UniqueFileName = argPDFRpt.CandidateID + "_Certificate.pdf";
       string UploadPath = Path.Combine(UploadFolder, UniqueFileName);
       var globalSettings = new GlobalSettings
       {
           ColorMode = ColorMode.Color,
           Orientation = Orientation.Landscape,
           PaperSize = PaperKind.A4,
           Margins = new MarginSettings { Top = 10, Bottom = 10 },
           Out = UploadPath
       };
       var objectSettings = new ObjectSettings
       {
           PagesCount = true,
           HtmlContent = html,
           WebSettings = { DefaultEncoding = "utf-8" },
       };
       var htmlToPdfDocument = new HtmlToPdfDocument()
       {
           GlobalSettings = globalSettings,
           Objects = { objectSettings },
       };
       _converter.Convert(htmlToPdfDocument);
       obj = new ResPDF();
       obj.IsSuccess = true;
       obj.Path = "/UploadedFiles/Report/" + UniqueFileName;
   }
   catch (Exception ex)
   {
       obj.IsSuccess = false;
       obj.Path = null;
       throw new Exception(ex.Message, ex.InnerException);                 
   }
   finally
   {
   }
   return Json(obj);
}

Output

EasyQuiz

Please note that W3.CSS is a standard CSS only and used here to make this application responsive and mobile-friendly.

Reference