public ActionResult CreateQuiz(int id) { Quiz pe = new Quiz(); pe.FormationId = id; pe.Score = 0; pe.Type = "En cours"; Ps.Add(pe); Ps.Commit(); var message1 = new MimeMessage(); message1.From.Add(new MailboxAddress("*****@*****.**")); message1.To.Add(new MailboxAddress("*****@*****.**")); message1.Subject = "Application"; message1.Body = new TextPart("plain") { Text = "Dear Employe, \nYour Quiz has been successfully registered on " + DateTime.Now + ". We will come back to you to indicate the date of the interview and the quiz. \n Best regards." }; using (var client = new SmtpClient()) { client.Connect("smtp.gmail.com", 465, true); client.AuthenticationMechanisms.Remove("XOAUTH"); client.Authenticate("*****@*****.**", "At066bn1!"); client.Send(message1); client.Disconnect(true); } // Use your account SID and authentication token instead // of the placeholders shown here. const string accountSID = "ACcb5274125fc2ebcbc47aef71d5738ac4"; const string authToken = "429ff7a2f0c90a0800d964bfbd1830e4"; // Initialize the TwilioClient. TwilioClient.Init(accountSID, authToken); // Use the Twilio-provided site for the TwiML response. var url = "https://twimlets.com/message"; url = $"{url}?Message%5B0%5D=Hello%20World"; try { // Send an SMS message. var message = MessageResource.Create( to: new PhoneNumber("+21621646533"), from: new PhoneNumber("+15628884113"), body: "Your application has been validated successfully \nThe " + DateTime.Now + "\n We will come back to you in order to pass your quiz \n Best regards."); } catch (TwilioException ex) { // An exception occurred making the REST call Console.WriteLine(ex.Message); } return(RedirectToAction("Index")); }
public ActionResult Create(quizModel qzv) { try { // if (ModelState.IsValid) // { quiz q = new quiz(); q.QuizName = qzv.QuizName; // q.formation = (System.Collections.Generic.ICollection<Data.formation>)qzv.formation; q.id_Quiz = qzv.id_Quiz; q.formation_id_for = qzv.formation_id_for; qz.Add(q); qz.Commit(); // return RedirectToAction("Create", "Question", new { id = "id_Quiz", otherParam = "foo" }); // } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult loadQuiz(QuizQuestionAnswers qqa) { try { //TempData["score"] = 0; //TempData["score_quest"] = 0; if (qqa != null) { quiz quiz = qz.GetById((int)qqa.quizId); var id = quiz.id_Quiz; var questions = qqa.Questions; var answers = qqa.answers; List <float> scores = new List <float>(); List <float> score_quests = new List <float>(); // quiz.Result = 0; foreach (var quest in questions) { var qId = quest.id_Question; question q = new question(); q = qts.GetById(qId); q.userchoice = quest.userchoice; qts.Commit(); //quest.userchoice= questions.Find(x=>x.id_Question==qId).userchoice; // foreach (var answ in answers) //{ //answer s = new answer(); //s = ans.GetById(answ.id_Answer); // s.id_Answer = answ.id_Answer; // s.flag = answ.flag; // s.question_id_Question = answ.question_id_Question; if (q.userchoice.Equals(true)) { score += 100 / questions.Count(); } score = score + 0; // } // score_quests.Add(scores.Sum()); //TempData["score_quest"] = Convert.ToInt32(TempData["score"]) + Convert.ToInt32(TempData["score_quest"]); } qqa.score = (int)score; // quiz.Result+= Convert.ToInt32(TempData["score_quest"]); quiz.Result = qqa.score; qz.Commit(); SendEmail(quiz.Result); // qz.Update(quiz); return(RedirectToAction("Details", new { id = qqa.quizId, otherParam = score_quests.Sum() })); // return RedirectToAction("Index"); // return View(quiz); } else { return(new HttpNotFoundResult()); } } catch { return(View()); } }
public ActionResult ValiderQuiz(FormCollection collection) { int o = int.Parse(collection["ido"].ToString()); string c = ""; string c1 = ""; string c2 = ""; string c3 = ""; string quizzradio = ""; string quizzradio1 = ""; string quizzradio2 = ""; string quizzradio3 = ""; int i = 0; int j = 1; var listquestion = Ps.GetMany(); listquestion = listquestion.Where(m => m.QuizId == o).ToList(); foreach (var item1 in listquestion) { if (i == 0) { c = item1.QuestionCorrectAnswer; quizzradio = collection["response" + j].ToString(); } if (i == 1) { c1 = item1.QuestionCorrectAnswer; quizzradio1 = collection["response" + j].ToString(); } if (i == 2) { c2 = item1.QuestionCorrectAnswer; quizzradio2 = collection["response" + j].ToString(); } if (i == 3) { c3 = item1.QuestionCorrectAnswer; quizzradio3 = collection["response" + j].ToString(); } i++; j++; } int score = 0; if (quizzradio == c) { score += 5; } if (quizzradio1 == c1) { score += 5; } if (quizzradio2 == c2) { score += 5; } if (quizzradio3 == c3) { score += 5; } Quiz pn; pn = Pq.GetById(o); pn.Score = score; if (score >= 10) { pn.Type = "Valider"; } else { pn.Type = "Refuser"; } Pq.Update(pn); Pq.Commit(); Question p; foreach (var item1 in listquestion) { p = item1; Ps.Delete(p); Ps.Commit(); } return(RedirectToAction("../Quiz/Index")); // return View(); }