Exemplo n.º 1
0
 public IActionResult SubmitResponse([FromBody] ExamDetailModel model)
 {
     //ModelState["File"].Errors.Clear();
     if (ModelState["File"].Errors.Count > 0)
     {
         ModelState["File"].Errors.Clear();
         ModelState.ClearValidationState("File");
         ModelState.MarkFieldValid("File");
     }
     if (ModelState.IsValid)
     {
         var path = Path.Combine(env.WebRootPath, "TestFiles");
         // var path = currentContext.HttpContext.Current.Server.MapPath("~/TestFiles/");
         var result = testManager.SubmittedTest(model, path);
         if (result.status)
         {
             if (model.Questions != null)
             {
                 examAnswerManager.Save(model.Questions, model.Id);
             }
             return(Ok("ThankYou"));
         }
         else
         {
             return(BadRequest(result.message));
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Exemplo n.º 2
0
        public ActionResult SubmitResponse(int examdetailId)
        {
            ExamDetailModel model = new ExamDetailModel();

            model.Id = examdetailId;
            return(View(model));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Start the test method
        /// </summary>
        /// <param name="examdetailId"></param>
        /// <returns></returns>
        public ActionResult TestStart()
        {
            var result = testManager.GetTestDetails(examId);

            if (result.status)
            {
                ExamDetailModel model = new ExamDetailModel();
                model.Id             = examId;
                ViewBag.examdetailId = examId;
                model.Questions      = result.Data.Questions;
                model.ExamTitle      = result.Data.TestName;
                model.IsAttachment   = result.Data.IsAttachment;
                //if (string.IsNullOrEmpty(OfficeAccessSession.AccessCode))
                //{
                //    string url = OfficeAccessSession.GetLoginUrl("onedrive.readwrite");
                //    Session["examdetailId"] = examdetailId;
                //    return new RedirectResult(url);
                //}
                return(View(model));
            }
            else
            {
                ViewBag.ErrorMessage = result.message;
                return(View("Error"));
            }
        }
Exemplo n.º 4
0
        public bool submitDetail(ExamDetailModel model)
        {
            try
            {
                if (model != null)
                {
                    tbl_ExamDetail objTest = new tbl_ExamDetail();
                    objTest.EmailId      = model.EmailId;
                    objTest.SubjectId    = model.SubjectId;
                    objTest.CategoryId   = model.CategoryId;
                    objTest.TestDuration = model.TestDuration;
                    objTest.Createdate   = DateTime.Now;
                    db.tbl_ExamDetail.Add(objTest);
                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult submitDetail(ExamDetailModel model)
        {
            bool result = false;

            if (ModelState.IsValid)
            {
                result = _examDetail.submitDetail(model);
            }
            return(Ok(result));
        }
Exemplo n.º 6
0
        private void SendEmail(string email, string name, int id, ExamDetailModel model, string Timetaken)
        {
            try
            {
                StringBuilder strAnswer = new StringBuilder();
                foreach (var item in model.Questions)
                {
                    var question = _context.ExamQuestions.Where(x => x.QuestionId == item.Id).FirstOrDefault().Question;
                    strAnswer.Append("<p><b>Question: " + question + "</b></p>");
                    strAnswer.Append("<p><b>Answer: </b></p>");
                    strAnswer.Append("<p>" + item.Name + "</p>");
                    strAnswer.Append("</br>");
                }
                var client = new SendGridClient(ADAuthUtils.AppSettings.SendGrid_AppId);

                var recipients = new List <EmailAddress>
                {
                    new EmailAddress(ADAuthUtils.AppSettings.WashingtonSendToEmail, "Washington Leon-Jordan"),
                    new EmailAddress(ADAuthUtils.AppSettings.JeffSendToEmail, "Jeff Vanzant"),
                };

                foreach (var recipient in recipients)
                {
                    var msg = new SendGridMessage()
                    {
                        From        = new EmailAddress("*****@*****.**", "Test Update"),
                        Subject     = "Test Completed",
                        HtmlContent = $"<strong>Hello {recipient.Name},</strong><br/> <p>Test has been completed by " + name + ". <p>" +
                                      "<p>Email: " + email + "!</p>" +
                                      "<p>Time Taken:" + Timetaken + "</p> " +
                                      strAnswer.ToString() +
                                      "<a href='https://techview.azurewebsites.net/CreateSession/View/" + id + "'>Click here to view the test</a><p>Thank you.</p>"
                                      //HtmlContent = $"<strong>Hello {recipient.Name},</strong><br/> <p>Test has been completed by " + name + " email is " + email + "!</p>
                                      //<a href='http://createsession.azurewebsites.net/CreateSession/View/" + id + "'>Click here to view the test</a><p>Thank you.</p>"
                    };
                    msg.AddTo(recipient);
                    var response = client.SendEmailAsync(msg);
                }
            }
            catch (Exception ex)
            {
                //
                //return false;
            }
        }
Exemplo n.º 7
0
        public ActionResult ExamCreate(ExamDetailModel exam)
        {
            ViewBag.Result = "Save successful.";
            var validation = ValidateModelForExam(exam);

            if (string.IsNullOrEmpty(validation))
            {
                EnrichExamDetailModel(exam);
                var result = _examModelClient.SaveExamDetail(exam);
                if (!result.IsSuccess)
                {
                    ViewBag.Result = result.Message;
                }
            }
            else
            {
                ViewBag.Result = validation;
            }

            return(PartialView("ExamCreate", exam));
        }
Exemplo n.º 8
0
        // [ValidateInput(false)]
        public ActionResult TestStart(ExamDetailModel model)
        {
            var webRoot = _env.WebRootPath;
            var path    = System.IO.Path.Combine(webRoot, "TestFiles");
            // var path = Server.MapPath("~/TestFiles/");
            var result = testManager.SubmittedTest(model, path);

            if (model.Questions != null)
            {
                examAnswerManager.Save(model.Questions, model.Id);
            }
            if (result.status)
            {
                return(View("ThankYou"));
            }
            else
            {
                ViewBag.ErrorMessage = result.message;
                return(View(model));
            }
        }
Exemplo n.º 9
0
        private void EnrichExamDetailModel(ExamDetailModel exam)
        {
            exam.LastUpdateUser = CurrentUserUniqueId;

            for (int i = 0; i < exam.Questions.Count; i++)
            {
                var question = exam.Questions[i];
                question.No = (short)(i + 1);

                for (int j = 0; j < question.Choices.Count; j++)
                {
                    var choice = question.Choices[j];
                    choice.Choice = (byte)(j + 1);
                }

                var answers = question.Choices.Where(u => u.IsAnswer).ToList();
                question.CorrectAnswer = answers.Select(u => u.Choice).JoinStrings(",");
                question.Category      = answers.Count == 1
                    ? (byte)ExamQuestionCategory.SingleOption
                    : (byte)ExamQuestionCategory.MultiOptions;
            }
        }
Exemplo n.º 10
0
 private string ValidateModelForExam(ExamDetailModel exam)
 {
     return(string.Empty);
 }
Exemplo n.º 11
0
        /// <summary>
        /// save the exam response in exam details like enddate, endime , status, solution file etc..
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel <int> SubmittedTest(ExamDetailModel model, string Serverpath)
        {
            ResponseModel <int> result = null;

            try
            {
                string FileName = string.Empty;
                if (model.IsAttachment)
                {
                    if (model.File != null)
                    {
                        var examDetailModel = _context.ExamDetails.Include("ExamSesson").Where(e => e.Id == model.Id && e.Status == false).Select(e => e).FirstOrDefault();
                        if (examDetailModel != null)
                        {
                            if (model.File != null)
                            {
                                FileName = examDetailModel.ExamSesson.Firstname + "-" + examDetailModel.ExamSesson.Lastname + "_" + Guid.NewGuid().ToString() + Path.GetExtension(model.File.FileName);
                                var path = Path.Combine(Serverpath, Path.GetFileName(FileName.ToString()));
                                using (var fileStream = new FileStream(path, FileMode.Create))
                                {
                                    model.File.CopyTo(fileStream);
                                }
                            }
                            examDetailModel.Enddate  = DateTime.Now;
                            examDetailModel.Endtime  = DateTime.Now.TimeOfDay;
                            examDetailModel.FileName = FileName;
                            examDetailModel.Status   = true;
                            _context.SaveChanges();
                            var      TestEnd  = examDetailModel.Enddate.Value.Date.Date.ToString();
                            TimeSpan timeSpan = examDetailModel.Enddate.Value.Date.Date.Add(examDetailModel.Endtime.Value).Subtract(examDetailModel.Startdate.Value.Add(examDetailModel.Starttime.Value));

                            // var Timetaken = (int)timeSpan.TotalHours + " hour " + timeSpan.ToString("mm") + " min";
                            var resultTime = timeSpan.Days > 0 ? Convert.ToInt32(timeSpan.Hours + (24 * timeSpan.Days)) + " hour " + timeSpan.ToString("mm") + " min" : Convert.ToInt32(timeSpan.Hours) + " hour " + timeSpan.ToString("mm") + " min";
                            SendEmail(examDetailModel.ExamSesson.EmailAddress, examDetailModel.ExamSesson.Firstname + " " + examDetailModel.ExamSesson.Lastname, examDetailModel.Id, model, resultTime);
                            result = new ResponseModel <int> {
                                status = true, message = "Success", Data = 1
                            };
                        }
                        else
                        {
                            result = new ResponseModel <int> {
                                status = false, message = "Test does not exists"
                            };
                        }
                    }

                    else if (model != null && !string.IsNullOrWhiteSpace(model.Filebase64))
                    {
                        var examDetailModel = _context.ExamDetails.Include("ExamSesson").Where(e => e.Id == model.Id && e.Status == false).Select(e => e).FirstOrDefault();

                        if (examDetailModel != null)
                        {
                            if (!string.IsNullOrWhiteSpace(model.Filebase64))
                            {
                                //  FileName = examDetailModel.ExamSesson.Firstname + "-" + examDetailModel.ExamSesson.Lastname + "_" + Guid.NewGuid().ToString() + Path.GetExtension(model.File.FileName);
                                //  var path = Path.Combine(Serverpath, Path.GetFileName(FileName.ToString()));
                                //using (var fileStream = new FileStream(path, FileMode.Create))
                                //{
                                //    model.File.CopyTo(fileStream);
                                //}


                                //sFileName = model.FileName;
                                FileName = examDetailModel.ExamSesson.Firstname + "-" + examDetailModel.ExamSesson.Lastname + "_" + Guid.NewGuid().ToString() + "." + Convert.ToString(model.FileName.Split('.')[1]);
                                var path = Path.Combine(Serverpath, FileName.ToString());
                                //Convert Base64 Encoded string to Byte Array.
                                byte[] imageBytes = Convert.FromBase64String(model.Filebase64);
                                File.WriteAllBytes(path, imageBytes);
                            }
                            examDetailModel.Enddate  = DateTime.Now;
                            examDetailModel.Endtime  = DateTime.Now.TimeOfDay;
                            examDetailModel.FileName = FileName;
                            examDetailModel.Status   = true;
                            _context.SaveChanges();

                            var      TestEnd  = examDetailModel.Enddate.Value.Date.Date.ToString();
                            TimeSpan timeSpan = examDetailModel.Enddate.Value.Date.Date.Add(examDetailModel.Endtime.Value).Subtract(examDetailModel.Startdate.Value.Add(examDetailModel.Starttime.Value));

                            // var Timetaken = (int)timeSpan.TotalHours + " hour " + timeSpan.ToString("mm") + " min";
                            var resultTime = timeSpan.Days > 0 ? Convert.ToInt32(timeSpan.Hours + (24 * timeSpan.Days)) + " hour " + timeSpan.ToString("mm") + " min" : Convert.ToInt32(timeSpan.Hours) + " hour " + timeSpan.ToString("mm") + " min";


                            // var TestEnd = examDetailModel.Enddate.Value.Add(examDetailModel.Endtime.Value).ToString();
                            // TimeSpan timeSpan = examDetailModel.Enddate.Value.Add(examDetailModel.Endtime.Value).Subtract(examDetailModel.Startdate.Value.Add(examDetailModel.Starttime.Value));
                            // var Timetaken = (int)timeSpan.TotalHours + " hour " + timeSpan.ToString("mm") + " min";
                            //  var resultTime = timeSpan.Days > 0 ? Convert.ToInt32(timeSpan.Hours + (24 * timeSpan.Days)) + " hour " + timeSpan.ToString("mm") + " min" : Convert.ToInt32(timeSpan.Hours) + " hour " + timeSpan.ToString("mm") + " min";

                            SendEmail(examDetailModel.ExamSesson.EmailAddress, examDetailModel.ExamSesson.Firstname + " " + examDetailModel.ExamSesson.Lastname, examDetailModel.Id, model, resultTime);
                            result = new ResponseModel <int> {
                                status = true, message = "Success", Data = 1
                            };
                        }
                        else
                        {
                            result = new ResponseModel <int> {
                                status = false, message = "Test does not exists"
                            };
                        }
                    }
                    else
                    {
                        result = new ResponseModel <int> {
                            status = false, message = "please upload the file "
                        };
                    }
                }
                else
                {
                    var examDetailModel = _context.ExamDetails.Include("ExamSesson").Where(e => e.Id == model.Id && e.Status == false).Select(e => e).FirstOrDefault();
                    if (examDetailModel != null)
                    {
                        if (!string.IsNullOrWhiteSpace(model.Filebase64))
                        {
                            FileName = examDetailModel.ExamSesson.Firstname + "-" + examDetailModel.ExamSesson.Lastname + "_" + Guid.NewGuid().ToString() + "." + Convert.ToString(model.FileName.Split('.')[1]);
                            var path = Path.Combine(Serverpath, FileName.ToString());
                            //Convert Base64 Encoded string to Byte Array.
                            byte[] imageBytes = Convert.FromBase64String(model.Filebase64);
                            File.WriteAllBytes(path, imageBytes);
                        }
                        if (model.File != null)
                        {
                            FileName = examDetailModel.ExamSesson.Firstname + "-" + examDetailModel.ExamSesson.Lastname + "_" + Guid.NewGuid().ToString() + Path.GetExtension(model.File.FileName);
                            var path = Path.Combine(Serverpath, Path.GetFileName(FileName.ToString()));
                            using (var fileStream = new FileStream(path, FileMode.Create))
                            {
                                model.File.CopyTo(fileStream);
                            }
                        }
                        examDetailModel.Enddate  = DateTime.Now;
                        examDetailModel.Endtime  = DateTime.Now.TimeOfDay;
                        examDetailModel.FileName = FileName;
                        examDetailModel.Status   = true;
                        _context.SaveChanges();
                        var      TestEnd  = examDetailModel.Enddate.Value.Date.Date.ToString();
                        TimeSpan timeSpan = examDetailModel.Enddate.Value.Date.Date.Add(examDetailModel.Endtime.Value).Subtract(examDetailModel.Startdate.Value.Add(examDetailModel.Starttime.Value));

                        // var Timetaken = (int)timeSpan.TotalHours + " hour " + timeSpan.ToString("mm") + " min";
                        var resultTime = timeSpan.Days > 0 ? Convert.ToInt32(timeSpan.Hours + (24 * timeSpan.Days)) + " hour " + timeSpan.ToString("mm") + " min" : Convert.ToInt32(timeSpan.Hours) + " hour " + timeSpan.ToString("mm") + " min";
                        SendEmail(examDetailModel.ExamSesson.EmailAddress, examDetailModel.ExamSesson.Firstname + " " + examDetailModel.ExamSesson.Lastname, examDetailModel.Id, model, resultTime);
                        result = new ResponseModel <int> {
                            status = true, message = "Success", Data = 1
                        };
                    }
                    else
                    {
                        result = new ResponseModel <int> {
                            status = false, message = "Test does not exists"
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                result.message = ex.Message;
            }

            return(result);
        }
Exemplo n.º 12
0
 public bool submitDetail(ExamDetailModel model)
 {
     return(new DAL.ExamDetailDAL().submitDetail(model));
 }