Exemple #1
0
        public int CreateUserGroup(UserGroupModel UGM)
        {
            try
            {
                using (var context = new MCQ_Quiz_DBEntities())
                {
                    tblUserGroup TUG = new tblUserGroup();

                    TUG.UserId    = UGM.UserId;
                    TUG.QuizId    = UGM.QuizId;
                    TUG.RoleId    = UGM.RoleId;
                    TUG.CreatedON = UGM.CreatedON;
                    TUG.UpdatedON = UGM.UpdatedON;

                    context.tblUserGroups.Add(TUG);
                    context.SaveChanges();

                    return(TUG.UserGrpId);
                }
            }
            catch (Exception)
            {
                return(0);
            }
        }
        public int AddQuiz(QuizModel quizModel)
        {
            try
            {
                using (var context = new MCQ_Quiz_DBEntities())
                {
                    tblQuiz _tblQuiz = new tblQuiz();

                    //  _tblQuiz.QuizId = quizModel.QuizId;
                    _tblQuiz.Title     = quizModel.Title;
                    _tblQuiz.Summary   = quizModel.Summary;
                    _tblQuiz.Type      = quizModel.Type;
                    _tblQuiz.Subject   = quizModel.Subject;
                    _tblQuiz.CreatedON = quizModel.CreatedON;
                    _tblQuiz.CreatedBy = quizModel.CreatedBy;
                    _tblQuiz.IsActive  = quizModel.IsActive;

                    context.tblQuizs.Add(_tblQuiz);
                    context.SaveChanges();

                    return(_tblQuiz.QuizId);
                }
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
Exemple #3
0
        public int Register(UserModel user)
        {
            using (var context = new MCQ_Quiz_DBEntities())
            {
                var IfEmailAlreadyExists = context.tblUsers.Where(x => x.Email_ID == user.Email_ID).FirstOrDefault();

                if (IfEmailAlreadyExists == null)
                {
                    tblUser usertbl = new tblUser
                    {
                        FirstName   = user.FirstName,
                        MiIddleName = user.MiIddleName,
                        LastName    = user.LastName,
                        BirthDate   = user.BirthDate,
                        Email_ID    = user.Email_ID,
                        Type        = user.Type,
                        Password    = user.Password,
                        City        = user.City,
                        State       = user.State,
                        Country     = user.Country,
                        IsActive    = user.IsActive
                    };

                    context.tblUsers.Add(usertbl);
                    context.SaveChanges();

                    return(usertbl.UserId);
                }
                else
                {
                    return(-1);
                }
            }
        }
Exemple #4
0
        public bool EditUserGroup(UserGroupModel UGM)
        {
            try
            {
                using (var context = new MCQ_Quiz_DBEntities())
                {
                    var RecordToEdit = context.tblUserGroups.Where(x => x.UserGrpId == UGM.UserGrpId).FirstOrDefault();

                    RecordToEdit.RoleId    = UGM.RoleId;
                    RecordToEdit.UpdatedON = UGM.UpdatedON;
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public int AddQuestion(QuizQuestionModel _quizQueModel)
        {
            try
            {
                using (var context = new MCQ_Quiz_DBEntities())
                {
                    /// first add question
                    tblQuizQuestion question = new tblQuizQuestion();
                    question.QuizId_fk = _quizQueModel.QuizId_fk;
                    question.Question  = _quizQueModel.Question;
                    question.Type      = _quizQueModel.Type;
                    question.CreatedOn = _quizQueModel.CreatedOn;
                    question.IsActive  = _quizQueModel.IsActive;
                    question.CreatedBy = _quizQueModel.CreatedBy;

                    context.tblQuizQuestions.Add(question);
                    context.SaveChanges();


                    /// second add options

                    //1
                    tblQuizChoice choice1 = new tblQuizChoice();
                    choice1.QuestionId  = question.QuizQuestionId;
                    choice1.OptionTitle = _quizQueModel.option1;
                    choice1.CreatedON   = _quizQueModel.CreatedOn;
                    choice1.CreatedBy   = _quizQueModel.CreatedBy;
                    choice1.IsAnswer    = false;
                    if (_quizQueModel.option1 == _quizQueModel.Answer)
                    {
                        choice1.IsAnswer = true;
                    }
                    context.tblQuizChoices.Add(choice1);
                    context.SaveChanges();

                    //2
                    tblQuizChoice choice2 = new tblQuizChoice();
                    choice2.QuestionId  = question.QuizQuestionId;
                    choice2.OptionTitle = _quizQueModel.option2;
                    choice2.CreatedON   = _quizQueModel.CreatedOn;
                    choice2.CreatedBy   = _quizQueModel.CreatedBy;
                    choice2.IsAnswer    = false;
                    if (_quizQueModel.option2 == _quizQueModel.Answer)
                    {
                        choice2.IsAnswer = true;
                    }

                    context.tblQuizChoices.Add(choice2);
                    context.SaveChanges();

                    //3
                    tblQuizChoice choice3 = new tblQuizChoice();
                    choice3.QuestionId  = question.QuizQuestionId;
                    choice3.OptionTitle = _quizQueModel.option3;
                    choice3.CreatedON   = _quizQueModel.CreatedOn;
                    choice3.CreatedBy   = _quizQueModel.CreatedBy;
                    choice3.IsAnswer    = false;
                    if (_quizQueModel.option3 == _quizQueModel.Answer)
                    {
                        choice3.IsAnswer = true;
                    }

                    context.tblQuizChoices.Add(choice3);
                    context.SaveChanges();

                    //4
                    tblQuizChoice choice4 = new tblQuizChoice();
                    choice4.QuestionId  = question.QuizQuestionId;
                    choice4.OptionTitle = _quizQueModel.option4;
                    choice4.CreatedON   = _quizQueModel.CreatedOn;
                    choice4.CreatedBy   = _quizQueModel.CreatedBy;
                    choice4.IsAnswer    = false;
                    if (_quizQueModel.option4 == _quizQueModel.Answer)
                    {
                        choice4.IsAnswer = true;
                    }
                    context.tblQuizChoices.Add(choice4);
                    context.SaveChanges();
                    return(choice4.Quiz_Choice_Id);
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }