public string UpdateResultExam(int idUser, int idLesson, int numberRight) { string resultexam = null; try { int totalQuestion = _context.Exams.Where(a => a.Id == idLesson).Select(a => a.NumberQuestion).FirstOrDefault(); //check if not exist is add new else if update point and status if (_context.ExamDetailses.Where(a => a.ExamId == idLesson && a.AccountId == idUser).FirstOrDefault() == null) { _context.ExamDetailses.Add(new ExamDetails { AccountId = _context.Accounts.Where(a => a.Id == idUser).FirstOrDefault().Id, ExamId = _context.Exams.Where(a => a.Id == idLesson).FirstOrDefault().Id, Status = CheckPast(numberRight, totalQuestion) > 75.0 ? true : false, Point = (int)Math.Round(CheckPast(numberRight, totalQuestion), MidpointRounding.AwayFromZero) }); } else { ExamDetails lastExam = _context.ExamDetailses.Where(a => a.ExamId == idLesson && a.AccountId == idUser).FirstOrDefault(); lastExam.Status = CheckPast(numberRight, totalQuestion) > 75.0 ? true : false; lastExam.Point = (int)Math.Round(CheckPast(numberRight, totalQuestion), MidpointRounding.AwayFromZero); lastExam.EditTime = DateTime.Now; _context.ExamDetailses.Update(lastExam); _context.SaveChanges(); } //update progress learn // find column value with idLesson - idUser - idCourses LessonDetails learn = _context.LessonDetailses .Where(a => a.LessonId == _context.Exams.Where(b => b.Id == idLesson).FirstOrDefault().LessonId && a.AccountId == idUser).FirstOrDefault(); if (learn == null) { _context.LessonDetailses.Add(new LessonDetails { AccountId = idUser, LessonId = idLesson, Status = CheckPast(numberRight, totalQuestion) > 75.0 ? true : false, EditTime = DateTime.Now }); resultexam = CheckPast(numberRight, totalQuestion) > 75.0 ? "Chúc mừng. Bạn đã vượt qua" :"Rất tiếc. Bạn chưa đạt yêu cầu"; } else { learn.Status = CheckPast(numberRight, totalQuestion) > 75.0 ? true : false; learn.EditTime = DateTime.Now; resultexam = learn.Status == true ? "Chúc mừng. Bạn đã vượt qua" : "Rất tiếc. Bạn chưa đạt yêu cầu"; _context.LessonDetailses.Update(learn); } _context.SaveChanges(); } catch { resultexam = null; } return(resultexam); }
private IEnumerator GetLesson() { //Get the lesson of the selected topic string url = string.Format("http://127.0.0.1:5000/lessons/?topic_id={0}&lesson_id={1}", PlayerPrefs.GetString("topicID"), PlayerPrefs.GetString("lessonID")); using (UnityWebRequest webRequest = UnityWebRequest.Get(url)) { yield return(webRequest.SendWebRequest()); lessonDetails = JsonUtility.FromJson <LessonDetails>(webRequest.downloadHandler.text); UpdateLesson(); } }
public bool Edit(LessonDetails o) { try { _log.LogInformation("BEGIN => Edit"); _context.LessonDetailses.Update(o); _context.SaveChanges(); _log.LogInformation("END <= Edit"); return(true); } catch (Exception e) { _log.LogError("ERROR => Edit : [%s]", e); return(false); } }
public bool Add(LessonDetails o) { try { _log.LogInformation("BEGIN => Add"); _context.LessonDetailses.Add(o); _context.SaveChanges(); _log.LogInformation("END <= Add"); return(true); } catch (Exception e) { _log.LogError("ERROR <= Add : [%s]", e); return(false); } }