Click here to Skip to main content
14,217,388 members
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

177.1K views
6.1K downloads
189 bookmarked

YouGrade - Asp.NET MVC Multimedia Exam Suite

,
Rate this:
4.93 (98 votes)
Please Sign up or sign in to vote.
4.93 (98 votes)
8 Jun 2011     CPOL    
A multimedia exam suite built on Asp.NET and Youtube
YouGrade
App_Data
YouGrade.mdf
YouGrade_log.LDF
Assemblies
AutoMapper.dll
bin
Content
Images
Buttons.PNG
Buttons2.png
Paper.jpg
ui-bg_diagonals-thick_18_b81900_40x40.png
ui-bg_diagonals-thick_20_666666_40x40.png
ui-bg_flat_10_000000_40x100.png
ui-bg_glass_100_f6f6f6_1x400.png
ui-bg_glass_100_fdf5ce_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_gloss-wave_35_f6a828_500x100.png
ui-bg_highlight-soft_100_eeeeee_1x100.png
ui-bg_highlight-soft_75_ffe45c_1x100.png
ui-icons_222222_256x240.png
ui-icons_228ef1_256x240.png
ui-icons_ef8c08_256x240.png
ui-icons_ffd27a_256x240.png
ui-icons_ffffff_256x240.png
YouGrade.PNG
themes
base
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
Controllers
DBScripts
Dtos
Model
YouGrade.edmx
Models
obj
Debug
Properties
Scripts
Views
Account
Home
Shared
Site.Master
YouGrade.csproj.user
YouGradeService.svc
YouGrade.mdf
YouGrade_log.LDF
AutoMapper.dll
Buttons.PNG
Buttons2.png
Paper.jpg
ui-bg_diagonals-thick_18_b81900_40x40.png
ui-bg_diagonals-thick_20_666666_40x40.png
ui-bg_flat_10_000000_40x100.png
ui-bg_glass_100_f6f6f6_1x400.png
ui-bg_glass_100_fdf5ce_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_gloss-wave_35_f6a828_500x100.png
ui-bg_highlight-soft_100_eeeeee_1x100.png
ui-bg_highlight-soft_75_ffe45c_1x100.png
ui-icons_222222_256x240.png
ui-icons_228ef1_256x240.png
ui-icons_ef8c08_256x240.png
ui-icons_ffd27a_256x240.png
ui-icons_ffffff_256x240.png
YouGrade.PNG
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
YouGrade.edmx
Site.Master
YouGrade.csproj.user
YouGradeService.svc
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YouGrade.Model;
using YouGrade.Dtos;
using AutoMapper;

namespace YouGrade
{
    public class ExamManager
    {
        static ExamManager instance = null;
        ExamDef examDef;
        ExamTakeDto examTakeDto;
        int questionId = 1;
        private ExamManager()
        {
            var service = new YouGradeService();
            examDef = service.GetExamDef();

            var examDefDto = new ExamDefDto();
            Mapper.Map(examDef, examDefDto);

            examTakeDto = new ExamTakeDto();
            examTakeDto.ExamId = 1;
            examTakeDto.UserId = 1;
            examTakeDto.Answers = new List<AnswerDto>();
            examTakeDto.StartDateTime = DateTime.Now;
            examTakeDto.Status = ExamTakeStatus.Open.ToString();
            foreach (var q in examDefDto.Questions)
            {
                foreach (var a in q.Alternatives)
                {
                    examTakeDto.Answers.Add(new AnswerDto()
                    {
                        QuestionId = q.Id,
                        AlternativeId = a.Id,
                        ExamTakeId = 0,
                        IsChecked = false
                    });
                }
            }
        }

        public static ExamManager Instance
        {
            get
            {
                if (instance == null)
                    instance = new ExamManager();
                return instance;
            }
        }

        public ExamDefDto GetExam()
        {
            var examDefDto = new ExamDefDto();
            Mapper.Map(examDef, examDefDto);

            return examDefDto;
        }

        public QuestionDefDto GetQuestion()
        {
            var questionDef = examDef.QuestionDef.Where(e => e.Id == questionId).First();
            var questionDefDto = new QuestionDefDto();
            Mapper.Map(questionDef, questionDefDto);
            var query = from alt in questionDefDto.Alternatives
                        join ans in examTakeDto.Answers
                            on new { qId = alt.QuestionId, aId = alt.Id }
                            equals new { qId = ans.QuestionId, aId = ans.AlternativeId }
                        select new { ans = ans, alt = alt };

            foreach (var a in query)
            {
                a.alt.IsChecked = a.ans.IsChecked;
            }
                        
            return questionDefDto;
        }

        public void SaveAnswer(int questionId, string answers)
        {
            var question = examDef.QuestionDef.Where(e => e.Id == questionId).First();

            var query = from ans in examTakeDto.Answers
                        where ans.QuestionId == questionId
                        select ans;

            foreach (var a in query)
            {
                a.IsChecked = (answers.ToCharArray().Contains(a.AlternativeId[0]));
            }
        }

        public bool MoveToPreviousQuestion()
        {
            bool canMove = false;

            if (questionId > 1)
            {
                questionId--;
                canMove = true;
            }

            return canMove;
        }

        public bool MoveToNextQuestion()
        {
            bool canMove = false;

            if (examDef.QuestionDef.Count > questionId)
            {
                questionId++;
                canMove = true;
            }

            return canMove;
        }

        public int EndExam()
        {
            var result = 0d;
            var service = new YouGradeService();
            var examDefDto = new ExamDefDto();
            Mapper.Map(examDef, examDefDto);

            result = service.SaveExamTake(examTakeDto);

            return (int)((100 * result) / examDefDto.Questions.Count());
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author