private StudentAnswers GetData()
    {
        string conStr = "Data Source= .;Initial Catalog=AdvSQL;Integrated Security=True";

        using (SqlConnection con = new SqlConnection(conStr))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = con;
                cmd.CommandText = "getQuestionwithStudentId";
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter par1 = new SqlParameter("@exid", SqlDbType.Int, 4);
                SqlParameter par2 = new SqlParameter("@stid", SqlDbType.Int, 4);
                cmd.Parameters.Add(par1);
                cmd.Parameters.Add(par2);
                par1.Value        = int.Parse(Session["Exam_id_forReport"].ToString());
                par2.Value        = int.Parse(Session["Student_id_forReport"].ToString());
                sda.SelectCommand = cmd;
                using (StudentAnswers dsStudents = new StudentAnswers())
                {
                    sda.Fill(dsStudents, "DataTable1");
                    return(dsStudents);
                }
            }
        }
    }
Example #2
0
        public async Task <IActionResult> PutStudentAnswers([FromRoute] int id, [FromBody] StudentAnswers studentAnswers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != studentAnswers.id)
            {
                return(BadRequest());
            }

            _context.Entry(studentAnswers).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentAnswersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crp = new ReportDocument();

        crp.Load(Server.MapPath("~/CrystalReportStudentAnswers.rpt"));
        StudentAnswers dsStu = GetData();

        crp.SetDataSource(dsStu);
        CrystalReportViewer1.ReportSource = crp;
    }
Example #4
0
        public async Task <IActionResult> PostStudentAnswers([FromBody] StudentAnswers studentAnswers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.StudentAnswers.Add(studentAnswers);

            //Getting into array before the algorithm

            string[] myAnswer = studentAnswers.Answers.Split(" ".ToCharArray());

            var dataExpected = _context.Questions.Where(q => q.Id == studentAnswers.MyQuestionsId).FirstOrDefault();

            var quest = dataExpected.ExpectedAnswers.Split(" ".ToCharArray());

            int all   = 0;
            int count = 0;

            foreach (string rem in myAnswer)
            {
                all += 1;
                if (quest.Contains(rem))
                {
                    count += 1;
                }
            }
            int perc = (int)Math.Round((count * 12.0) / all);



            Answer saveAnswer = new Answer
            {
                Ans              = perc,
                MyQuestionsId    = studentAnswers.MyQuestionsId, // _context.MyQuestions.Where(q => q.Id == 2).FirstOrDefault().Id
                StudentAnswersId = studentAnswers.id,
                StudentId        = studentAnswers.UserId
            };

            _context.Answer.Add(saveAnswer);
            await _context.SaveChangesAsync();

            //This ends where the Answers are saved


            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetStudentAnswers", new { id = studentAnswers.id }, studentAnswers));
        }