public static void ShowExample() { Calendar cal = new Calendar(); #region Проверка календаря по умолчанию ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); Log(); Console.ReadKey(); #region Добавляем выходной день Log("Добавляем выходной день"); cal.AddHoliday(new DateTime(2017, 02, 23)); ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); #endregion Log(); Console.ReadKey(); #region Добавляем рабочий день Log("Добавляем рабочий день"); cal.RemoveHoliday(new DateTime(2017, 02, 26)); ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); #endregion Log(); Console.ReadKey(); #region Добавляем ошибки Log("Добавляем ошибки"); cal.RemoveHoliday(new DateTime(2017, 02, 26)); ShowDayPeriod(cal, new DateTime(2017, 02, 13), 14); #endregion #endregion #region Полиморфизм методов Calendar cal1 = new Calendar(); Calendar cal2 = new USCalendar(); Log(cal1.Name); Log(cal2.Name); Log(((USCalendar)cal2).Name); #endregion #region Скрытие метода ExA exref = new ExA(); Log($"ExA.ShowMessage: {exref.ShowMessage()}"); // -> ExA exref = new ExB(); Log($"ExB.ShowMessage: {exref.ShowMessage()}"); // -> ExB exref = new ExC(); Log($"ExC.ShowMessage: {exref.ShowMessage()}"); // -> ExA exref = new ExD(); Log($"ExD.ShowMessage: {exref.ShowMessage()}"); // -> ExA ExC exref2 = (ExC)exref; Log($"ExD.ShowMessage: {exref2.ShowMessage()}"); // -> ExD #endregion //функция вывода в консоль void Log(string inMes = "") { Console.WriteLine(inMes); } }
public IActionResult Submit(ExA ExA) { var qno = ExA.QuestionNummber + 1; Answer answer = new Answer(); answer.Id = ExA.Id; answer.QuestionId = ExA.QuestionId; answer.Question = ExA.Question; answer.Answers = ExA.Answers; answer.Status = ExA.Status; answer.isDelete = ExA.isDelete; answer.ExamId = ExA.ExamId; answer.Examination = ExA.Examination; var json = JsonConvert.SerializeObject(answer); var buffer = System.Text.Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = client.PutAsync("answers/" + answer.Id, byteContent).Result; return(RedirectToAction("ExamPage", new{ @qno = qno })); }
public IActionResult ExamPage(int qno) { //Validasi Pagination if (qno > 9) { var sectioncek = HttpContext.Session.GetString("section"); if (sectioncek == "Section1") { return(Redirect("/examinations/usersection")); } else { return(Redirect("/ExamResult")); } } else if (qno < 0) { qno = 0; } //Load data soal List <Answer> answ = null; ExA ExA = new ExA(); var id = HttpContext.Session.GetString("examid"); var resTask = client.GetAsync("examinations/loadsoal/" + id); resTask.Wait(); var result = resTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <List <Answer> >(); readTask.Wait(); answ = readTask.Result; } else { ModelState.AddModelError(string.Empty, "Server Error."); } var sectionsession = HttpContext.Session.GetString("section");; Answer answer = null; List <Answer> sectionAnswer = null; if (sectionsession == "Section1") { //Masukan ID SECTION BASIC PROGRAMMING DISINI sectionAnswer = answ.Where(x => x.Question.SectionId == "543f2732-7f2c-457e-8040-c37b7093a7ad").ToList(); Question question = null; var resTask2 = client.GetAsync("questions/loadquestion/" + sectionAnswer[qno].QuestionId); resTask2.Wait(); var result2 = resTask2.Result; var json = JsonConvert.DeserializeObject(result2.Content.ReadAsStringAsync().Result).ToString(); question = JsonConvert.DeserializeObject <Question>(json); answer = sectionAnswer[qno]; answer.Question = question; } else { //TAMBAHKAN SECTION OOP DI SINI sectionAnswer = answ.Where(x => x.Question.SectionId == "73270830-2b1b-445e-879b-17096bef7b81").ToList(); Question question = null; var resTask2 = client.GetAsync("questions/loadquestion/" + sectionAnswer[qno].QuestionId); resTask2.Wait(); var result2 = resTask2.Result; var json = JsonConvert.DeserializeObject(result2.Content.ReadAsStringAsync().Result).ToString(); question = JsonConvert.DeserializeObject <Question>(json); answer = sectionAnswer[qno]; answer.Question = question; } //Set data soal ExA.Id = answer.Id; ExA.QuestionId = answer.QuestionId; ExA.Question = answer.Question; ExA.Answers = answer.Answers; ExA.Status = answer.Status; ExA.isDelete = answer.isDelete; ExA.ExamId = answer.ExamId; ExA.Examination = answer.Examination; ExA.QuestionNummber = qno; //Validasi waktu ujian ViewBag.TimeExpired = answer.Examination.ExpiredDate; var date1 = DateTime.UtcNow; var date2 = answer.Examination.ExpiredDate.Value; var date3 = answer.Examination.CreatedDate.UtcDateTime; var available = DateTime.Compare(date1, date2); var created = answer.Examination.CreatedDate.UtcDateTime; var available2 = DateTime.Compare(date1, created.AddHours(6)); var available3 = DateTime.Compare(date1, date3); if (available < 0 && available2 < 0 && available3 > 0) { var roleName = HttpContext.Session.GetString("role"); if (roleName == "Trainee") { return(View(ExA)); } return(Redirect("/notfound")); } else if (available3 <= 0) { return(Redirect("/notfound")); } else if (sectionsession == "Section1") { return(Redirect("/examinations/usersection")); } else if (sectionsession == "Section2") { return(Redirect("/ExamResult")); } return(Redirect("/notfound")); }