Exemplo n.º 1
0
        public List <QuestionGroupList> GetQuestionGroupId()
        {
            List <QuestionGroupList> questionGroup = new List <QuestionGroupList>();

            try
            {
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    // academyEntity
                    LogWrite("entity open");
                    questionGroup = (from quesgroup in academyEntity.QuestionGroups
                                     where quesgroup.IsValid == true
                                     select new QuestionGroupList
                    {
                        QuestionGroupId = quesgroup.QuestionGroupID,
                        QuestionGroupname = quesgroup.QuestionGroupName
                    }).ToList();
                    LogWrite("fetched data");
                }
            }
            catch (Exception ex)
            {
                questionGroup = null;
                LogWrite(ex.Message);
                LogWrite(ex.InnerException.ToString());
                LogWrite(ex.StackTrace.ToString());
            }
            return(questionGroup);
        }
Exemplo n.º 2
0
        public string StudentRegister(Students studentDetails)
        {
            string isRegisterSuccess = "false";

            try
            {
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    bool isALreadyRegistered = (from stu in academyEntity.Students
                                                where stu.IsActive == true && stu.Email == studentDetails.UserName
                                                select stu.StudentID).Any();
                    if (isALreadyRegistered)
                    {
                        isRegisterSuccess = "false";
                    }
                    else
                    {
                        Student student = new Student();
                        student.Email       = studentDetails.UserName;
                        student.Password    = studentDetails.PassWord;
                        student.StudentName = studentDetails.StudentName;
                        student.CreatedDate = DateTime.Now;
                        student.IsActive    = true;
                        academyEntity.Students.Add(student);
                        academyEntity.SaveChanges();
                        isRegisterSuccess = "true";
                    }
                }
            }
            catch (Exception ex)
            {
                isRegisterSuccess = "dberror";
            }
            return(isRegisterSuccess);
        }
        public JsonResult QuestionsSubmit(int questionGroup, int questionType, string question, HttpPostedFileBase[] uploadQuestion, string option1, HttpPostedFileBase[] uploadOption1, string option2, HttpPostedFileBase[] uploadOption2, string option3, HttpPostedFileBase[] uploadOption3, string option4, HttpPostedFileBase[] uploadOption4, int correctAnswer)
        {
            int insertCheck = 0;

            try
            {
                string questionPath = "~/Images/Questions/";
                if (!System.IO.Directory.Exists(questionPath))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(questionPath));
                }
                if (uploadQuestion != null)
                {
                    uploadQuestion[0].SaveAs(Server.MapPath(questionPath + uploadQuestion[0].FileName));
                }
                string optionsPath = "~/Images/Options/";
                if (!System.IO.Directory.Exists(optionsPath))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(optionsPath));
                }
                if (uploadOption1 != null)
                {
                    uploadOption1[0].SaveAs(Server.MapPath(optionsPath + uploadOption1[0].FileName));
                }

                if (uploadOption2 != null)
                {
                    uploadOption2[0].SaveAs(Server.MapPath(optionsPath + uploadOption2[0].FileName));
                }

                if (uploadOption3 != null)
                {
                    uploadOption3[0].SaveAs(Server.MapPath(optionsPath + uploadOption3[0].FileName));
                }

                if (uploadOption4 != null)
                {
                    uploadOption4[0].SaveAs(Server.MapPath(optionsPath + uploadOption4[0].FileName));
                }

                question = question + (uploadQuestion != null ? " ImageName: " + uploadQuestion[0].FileName : "");
                option1  = option1 + (uploadOption1 != null ? " ImageName: " + uploadOption1[0].FileName : "");
                option2  = option2 + (uploadOption2 != null ? " ImageName: " + uploadOption2[0].FileName : "");
                option3  = option3 + (uploadOption3 != null ? " ImageName: " + uploadOption3[0].FileName : "");
                option4  = option4 + (uploadOption4 != null ? " ImageName: " + uploadOption4[0].FileName : "");
                using (ATCACADEMYEntities db = new ATCACADEMYEntities())
                {
                    db.Database.Connection.Open();
                    insertCheck = db.PROC_InsertQuestions(questionGroup, questionType, question, option1, option2, option3, option4, correctAnswer);
                    db.Database.Connection.Close();
                }

                return(Json(insertCheck, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(insertCheck, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 4
0
        public int?CheckQuestionAnswers(SubmittedAnswers answerSheet)
        {
            int?result     = 0;
            int resultVlue = 0;
            List <GetQuestionAnswers> questionandanswers = new List <GetQuestionAnswers>();

            try
            {
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    questionandanswers = (from ques in academyEntity.Questions
                                          where ques.IsValid == true
                                          select new GetQuestionAnswers
                    {
                        QuestionsList = ques.QuestionID,
                        AnswersList = ques.Answer
                    }).ToList();

                    for (int i = 0; i < questionandanswers.Count; i++)
                    {
                        if (questionandanswers[i].AnswersList == answerSheet.AnswersList[i])
                        {
                            result     += 1;
                            resultVlue += 1;
                        }
                    }
                    int?   minusValue    = questionandanswers.Count - result;
                    double?modulateValue = minusValue * 0.33;
                    result = result - ((int)modulateValue);
                    int    minusValueOne    = questionandanswers.Count - resultVlue;
                    double modulateValueOne = minusValueOne * 0.33;
                    resultVlue = resultVlue - ((int)modulateValueOne);

                    Result res = new Result();
                    res.StudentID       = int.Parse(System.Web.HttpContext.Current.Request.Cookies["UserCookie"]["UserId"]);
                    res.QuestionGroupID = answerSheet.QuestionGroupId;
                    res.Marks           = resultVlue;
                    res.wronganswers    = minusValue;
                    academyEntity.Results.Add(res);
                    academyEntity.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result = null;
            }
            return(result);
        }
 public ActionResult QuestionsCreation()
 {
     try
     {
         using (ATCACADEMYEntities academyEntity = new ATCACADEMYEntities())
         {
             academyEntity.Database.Connection.Open();
             ViewBag.QuestionGroup = new SelectList(academyEntity.PROC_GetQuestionGroup().ToList(), "QuestionGroupID", "QuestionGroupName");
             ViewBag.QuestionType  = new SelectList(academyEntity.PROC_GetQuestionType().ToList(), "QuestionTypeID", "QuestionTypeName");
             academyEntity.Database.Connection.Close();
         }
     }
     catch
     {
     }
     return(View());
 }
Exemplo n.º 6
0
        public string StudenLogin(Students student)
        {
            string isLogginSuccess = "false";

            try
            {
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    var studentDetails = (from userdetails in academyEntity.Students
                                          where userdetails.Email == student.UserName &&
                                          userdetails.Password == student.PassWord
                                          select userdetails.StudentID).FirstOrDefault();
                    if (studentDetails != 0)
                    {
                        isLogginSuccess = "true";
                        var userId = (from user in academyEntity.Students
                                      where user.IsActive == true && user.Email == student.UserName
                                      select user.StudentID).FirstOrDefault();
                        HttpCookie userInfo = new HttpCookie("UserCookie");
                        userInfo["UserId"] = userId.ToString();
                        userInfo.Expires.Add(new TimeSpan(24, 0, 0));
                        System.Web.HttpContext.Current.Response.Cookies.Add(userInfo);
                        var isAdmin = (from user in academyEntity.Students
                                       where user.IsActive == true && user.Email == student.UserName
                                       select user.isAdmin).FirstOrDefault();
                        HttpCookie userInfoone = new HttpCookie("AdminCookie");
                        userInfoone["IsAdmin"] = isAdmin.ToString();
                        userInfoone.Expires.Add(new TimeSpan(24, 0, 0));
                        System.Web.HttpContext.Current.Response.Cookies.Add(userInfoone);
                    }
                    else
                    {
                        isLogginSuccess = "false";
                    }
                }
            }
            catch (Exception ex)
            {
                isLogginSuccess = "dberror";
            }
            return(isLogginSuccess);
        }
Exemplo n.º 7
0
        public int?GetTestResult(int groupId)
        {
            int?result = 0;

            try
            {
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    int userId = int.Parse(System.Web.HttpContext.Current.Request.Cookies["UserCookie"]["UserId"]);
                    result = (from res in academyEntity.Results
                              where res.StudentID == userId && res.QuestionGroupID == groupId
                              select res.Marks).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                result = null;
            }
            return(result);
        }
Exemplo n.º 8
0
        public bool IsStudentAlreadyTestDone()
        {
            bool isTestDone = false;
            int  userId     = int.Parse(System.Web.HttpContext.Current.Request.Cookies["UserCookie"]["UserId"]);

            try
            {
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    isTestDone = (from result in academyEntity.Results
                                  where userId == result.StudentID
                                  select result.ResultID).Any();
                }
            }
            catch (Exception ex)
            {
                isTestDone = false;
            }
            return(isTestDone);
        }
        public JsonResult QuestionGroupSubmit(string questionGroup)
        {
            int insertCheck = 0;

            try
            {
                using (ATCACADEMYEntities db = new ATCACADEMYEntities())
                {
                    db.Database.Connection.Open();
                    insertCheck = db.PROC_InsertQuestionGroup(questionGroup);
                    db.Database.Connection.Close();
                }

                return(Json(insertCheck, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json(insertCheck, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 10
0
 public List <QuestionList> GetQuestionList(int groupId)
 {
     //List<QuestionList> questionList = new List<QuestionList>();
     try
     {
         using (var academyEntity = new ATCACADEMYEntities())
         {
             allQuestions = (from questions in academyEntity.Questions
                             from questiongroup in academyEntity.QuestionGroups
                             where questions.IsValid == true && questions.QuestionGroupID == groupId
                             select new QuestionList
             {
                 questionId = questions.QuestionID,
                 question = questions.Question1,
                 questionType = questions.QuestionTypeID,
                 testGroupName = questiongroup.QuestionGroupName,
                 isHaveImage = questions.IsHaveImage
                               // OptionAnswers = suggested.OptionAnswer.Where(suggested.QuestionID => suggested.QuestionID  == questions.QuestionID)
             }).ToList();
             foreach (var x in allQuestions)
             {
                 x.OptionAnswers = (from suggested in academyEntity.Options
                                    where suggested.QuestionID == x.questionId
                                    select new OptionalAnswers
                 {
                     sequence = suggested.Sequence,
                     optionList = suggested.OptionAnswer,
                     isHaveImage = suggested.IsHaveImage
                 }).ToList();
             }
         }
     }
     catch (Exception ex)
     {
         allQuestions = null;
     }
     return(allQuestions);
 }
Exemplo n.º 11
0
        public string AddContactUsValues(ContactFormValues contactForm)
        {
            string isContactAdded = string.Empty;

            try
            {
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    Contactu contactus = new Contactu();
                    contactus.ContactName        = contactForm.Name;
                    contactus.ContactEmail       = contactForm.Email;
                    contactus.ContactPhone       = contactForm.Phone;
                    contactus.ContactInformation = contactForm.Info;
                    academyEntity.Contactus.Add(contactus);
                    academyEntity.SaveChanges();
                    isContactAdded = "saved";
                }
            }
            catch (Exception ex)
            {
                isContactAdded = null;
            }
            return(isContactAdded);
        }
Exemplo n.º 12
0
        public string GeneratePDF(int groupId)
        {
            string isPdfWrited = "false";

            try
            {
                int studentId = int.Parse(System.Web.HttpContext.Current.Request.Cookies["UserCookie"]["UserId"]);
                using (var academyEntity = new ATCACADEMYEntities())
                {
                    var pdfDocumentDetails = (from res in academyEntity.Results
                                              from stu in academyEntity.Students
                                              from questionGroup in academyEntity.QuestionGroups
                                              where res.StudentID == studentId && stu.StudentID == studentId &&
                                              questionGroup.QuestionGroupID == groupId
                                              select new PdfWritterDetails
                    {
                        testGroupname = questionGroup.QuestionGroupName,
                        studentName = stu.StudentName,
                        studentId = studentId,
                        WrongAnswers = res.wronganswers,
                        resultMark = res.Marks
                    }).ToList();


                    using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
                    {
                        Document document = new Document(PageSize.A4, 10, 10, 10, 10);

                        PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
                        document.Open();

                        string imageURL = System.Configuration.ConfigurationManager.AppSettings["imglocation"] + "\\atclogo.jpg";
                        LogWrite(imageURL);
                        iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);

                        //Resize image depend upon your need

                        jpg.ScaleToFit(140f, 120f);

                        //Give space before image

                        jpg.SpacingBefore = 10f;

                        //Give some space after the image

                        jpg.SpacingAfter = 1f;

                        jpg.Alignment = Element.ALIGN_CENTER;

                        document.Add(jpg);

                        string    text      = @"ATC Educational Institution";
                        Paragraph paragraph = new Paragraph();
                        paragraph.SpacingBefore = 30;
                        paragraph.SpacingAfter  = 10;
                        paragraph.Alignment     = Element.ALIGN_CENTER;
                        paragraph.Font          = FontFactory.GetFont(FontFactory.HELVETICA, 20f, BaseColor.BLACK);
                        paragraph.Add(text);
                        document.Add(paragraph);

                        string    text1      = pdfDocumentDetails[0].testGroupname;
                        Paragraph paragraph1 = new Paragraph();
                        paragraph1.SpacingBefore = 10;
                        paragraph1.SpacingAfter  = 50;
                        paragraph1.Alignment     = Element.ALIGN_CENTER;
                        paragraph1.Font          = FontFactory.GetFont(FontFactory.HELVETICA, 20f, BaseColor.BLACK);
                        paragraph1.Add(text1);
                        document.Add(paragraph1);

                        string    text2      = "Student ID : " + pdfDocumentDetails[0].studentId.ToString();
                        Paragraph paragraph2 = new Paragraph();
                        paragraph2.SpacingBefore = 10;
                        paragraph2.SpacingAfter  = 20;
                        paragraph2.Alignment     = Element.ALIGN_CENTER;
                        paragraph2.Font          = FontFactory.GetFont(FontFactory.HELVETICA, 20f, BaseColor.BLACK);
                        paragraph2.Add(text2);
                        document.Add(paragraph2);

                        string    text3      = "Student Name : " + pdfDocumentDetails[0].studentName;
                        Paragraph paragraph3 = new Paragraph();
                        paragraph3.SpacingBefore = 10;
                        paragraph3.SpacingAfter  = 20;
                        paragraph3.Alignment     = Element.ALIGN_CENTER;
                        paragraph3.Font          = FontFactory.GetFont(FontFactory.HELVETICA, 20f, BaseColor.BLACK);
                        paragraph3.Add(text3);
                        document.Add(paragraph3);

                        string    text4      = "Wrong Answers : " + pdfDocumentDetails[0].WrongAnswers.ToString();
                        Paragraph paragraph4 = new Paragraph();
                        paragraph4.SpacingBefore = 10;
                        paragraph4.SpacingAfter  = 20;
                        paragraph4.Alignment     = Element.ALIGN_CENTER;
                        paragraph4.Font          = FontFactory.GetFont(FontFactory.HELVETICA, 20f, BaseColor.BLACK);
                        paragraph4.Add(text4);
                        document.Add(paragraph4);

                        string    text5      = "Result : " + pdfDocumentDetails[0].resultMark.ToString();
                        Paragraph paragraph5 = new Paragraph();
                        paragraph5.SpacingBefore = 10;
                        paragraph5.SpacingAfter  = 20;
                        paragraph5.Alignment     = Element.ALIGN_CENTER;
                        paragraph5.Font          = FontFactory.GetFont(FontFactory.HELVETICA, 20f, BaseColor.BLACK);
                        paragraph5.Add(text5);
                        document.Add(paragraph5);


                        document.Close();
                        byte[] bytes = memoryStream.ToArray();
                        memoryStream.Close();
                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.ContentType = "application/pdf";

                        string pdfName = pdfDocumentDetails[0].studentName + "_score";
                        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + pdfName + ".pdf");
                        HttpContext.Current.Response.ContentType = "application/pdf";
                        HttpContext.Current.Response.Buffer      = true;
                        HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
                        HttpContext.Current.Response.BinaryWrite(bytes);
                        HttpContext.Current.Response.End();
                        HttpContext.Current.Response.Close();
                        isPdfWrited = "true";
                    }
                }
            }
            catch (Exception ex)
            {
                LogWrite(ex.Message);
                LogWrite(ex.StackTrace.ToString());
                isPdfWrited = "error";
            }
            return(isPdfWrited);
        }