public bool update(QUESTION t) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedQuestion = (from p in db.QUESTIONs where p.QUESTION_ID == t.QUESTION_ID select p).SingleOrDefault(); if (selectedQuestion != null) { selectedQuestion.CATEGORY = t.CATEGORY; selectedQuestion.QUESTION1 = t.QUESTION1; selectedQuestion.POINT = t.POINT; if (db.SaveChanges() == 0) { return(false); } return(true); } else { throw new Exception(); } } } catch (Exception ex) { throw; } }
public List <CustomApplication> findCustomApplicationsWithCondition(int condition) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedApplications = (from p in db.GET_RESULT_WITH_APPLY() select p).ToList(); List <CustomApplication> list = new List <CustomApplication>(); if (selectedApplications != null) { foreach (var a in selectedApplications) { if (a.APPROVE_STATUS == condition) { CustomApplication application = new CustomApplication() { APPLY_ID = a.APPLY_ID, NAME = a.NAME, APPROVE_STATUS = a.APPROVE_STATUS, TEST_INDEX = a.TEST_INDEX, TEST_RESULT_1 = a.TEST_RESULT_1, TEST_RESULT_2 = a.TEST_RESULT_2, TEST_RESULT_3 = a.TEST_RESULT_3 }; list.Add(application); } } } return(list); } } catch (Exception ex) { throw; } }
public bool update(TEST t) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedTest = (from p in db.TESTs where p.TEST_ID == t.TEST_ID select p).SingleOrDefault(); if (selectedTest != null) { selectedTest.POST_ID = t.POST_ID; selectedTest.START_TIME = t.START_TIME; selectedTest.END_TIME = t.END_TIME; selectedTest.TEST_NAME = t.TEST_NAME; if (db.SaveChanges() == 0) { return(false); } return(true); } else { throw new Exception(); } } } catch (Exception ex) { return(false); } }
public bool deleteById(string username) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedUser = (from p in db.USRs where p.USERNAME == username select p).SingleOrDefault(); if (selectedUser != null) { db.USRs.Remove(selectedUser); if (db.SaveChanges() == 0) { throw new Exception(); } } else { throw new NotImplementedException(); } return(true); } } catch (Exception ex) { throw; } }
public bool deleteById(string questionId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { int id = Int32.Parse(questionId); var selectedQuestion = (from p in db.QUESTIONs where p.QUESTION_ID == id select p).SingleOrDefault(); if (selectedQuestion != null) { db.QUESTIONs.Remove(selectedQuestion); if (db.SaveChanges() == 0) { throw new Exception(); } } else { throw new NotImplementedException(); } return(true); } } catch (Exception ex) { throw; } }
public bool deleteById(string applyId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { int id = Int32.Parse(applyId); var selectedApplication = (from p in db.JOB_APPLICATION where p.APPLY_ID == id select p).SingleOrDefault(); if (selectedApplication != null) { db.JOB_APPLICATION.Remove(selectedApplication); if (db.SaveChanges() == 0) { throw new Exception(); } } else { throw new NotImplementedException(); } return(true); } } catch (Exception ex) { throw; } }
public List <JOB_APPLICATION> getApplications(int testId, string key) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { ApplicationService applicationService = new ApplicationService(); List <JOB_APPLICATION> applications = new List <JOB_APPLICATION>(); var selectedResults = (from p in db.RESULTs where p.TEST_ID == testId select p).ToList(); foreach (var r in selectedResults) { if (key == "high") { } var selectedApplication = (from p in db.JOB_APPLICATION where p.APPLY_ID == r.APPLY_ID select p).SingleOrDefault(); applications.Add(selectedApplication); } return(applications); } } catch (Exception ex) { throw; } }
public bool apply(string applyId, int status) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { int id = Int32.Parse(applyId); var selectedApplication = (from p in db.JOB_APPLICATION where p.APPLY_ID == id select p).SingleOrDefault(); if (selectedApplication != null) { if (status == 1) { selectedApplication.APPROVE_STATUS = 1; } else { selectedApplication.APPROVE_STATUS = -1; } if (db.SaveChanges() == 0) { throw new Exception(); } return(true); } else { throw new NotImplementedException(); } } } catch (Exception ex) { throw; } }
public bool update(JOB_POST t) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedPost = (from p in db.JOB_POST where p.POST_ID == t.POST_ID select p).SingleOrDefault(); if (selectedPost != null) { selectedPost.POST = t.POST; selectedPost.CREATED = t.CREATED; selectedPost.TITLE = t.TITLE; selectedPost.END_DATE = t.END_DATE; if (db.SaveChanges() == 0) { return(false); } return(true); } else { throw new Exception(); } } } catch (Exception ex) { throw; } }
public List <RESULT> findResultMiddle(string category) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { if (category == "GENERAL KNOWLEDGE") { return((from p in db.RESULTs where p.TEST_RESULT_1 >= 50 && p.TEST_RESULT_1 < 80 select p).ToList()); } else if (category == "MATHEMATICS") { return((from p in db.RESULTs where p.TEST_RESULT_2 >= 50 && p.TEST_RESULT_2 < 80 select p).ToList()); } else { return((from p in db.RESULTs where p.TEST_RESULT_3 >= 50 && p.TEST_RESULT_3 < 80 select p).ToList()); } } } catch (Exception ex) { throw; } }
public List <JOB_POST> getPostNotCreated() { List <JOB_POST> posts = new List <JOB_POST>(); using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { TestService testService = new TestService(); foreach (var post in this.findAll()) { int check = 0; foreach (var test in testService.findAll()) { if (test.POST_ID == post.POST_ID) { check = 1; break; } } if (check == 0) { posts.Add(post); } } return(posts); } }
public bool deleteById(string postId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { int id = Int32.Parse(postId); var selectedPost = (from p in db.JOB_POST where p.POST_ID == id select p).SingleOrDefault(); if (selectedPost != null) { db.JOB_POST.Remove(selectedPost); if (db.SaveChanges() == 0) { throw new Exception(); } } else { throw new NotImplementedException(); } return(true); } } catch (Exception ex) { throw; } }
public bool AddQuestionToTest(int questionId, int testId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedTest = (from p in db.TESTs where p.TEST_ID == testId select p).SingleOrDefault(); QuestionService questionService = new QuestionService(); var selectedQuestion = (from p in db.QUESTIONs where p.QUESTION_ID == questionId select p).SingleOrDefault(); selectedTest.QUESTIONs.Add(selectedQuestion); if (db.SaveChanges() == 0) { throw new Exception(); } else { return(true); } } } catch (Exception ex) { throw; } }
public bool RemoveQuestionFromTest(int questionId, int testId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedTest = (from p in db.TESTs where p.TEST_ID == testId select p).SingleOrDefault(); foreach (var q in selectedTest.QUESTIONs) { if (q.QUESTION_ID == questionId) { selectedTest.QUESTIONs.Remove(q); if (db.SaveChanges() == 0) { throw new Exception(); } else { return(true); } } } return(false); } } catch (Exception ex) { throw; } }
public List <QUESTION> getQfromT(int id) { try { List <QUESTION> questions = new List <QUESTION>(); using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedTest = (from p in db.TESTs where p.TEST_ID == id select p).SingleOrDefault(); if (selectedTest == null) { throw new Exception(); } foreach (var q in selectedTest.QUESTIONs) { questions.Add(q); } return(questions); } } catch (Exception ex) { throw; } }
public bool update(USR t) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedUser = (from p in db.USRs where p.USERNAME == t.USERNAME select p).SingleOrDefault(); if (selectedUser != null) { selectedUser.PASSWORD = t.PASSWORD; selectedUser.APPLY_ID = t.APPLY_ID; selectedUser.ROLE = t.ROLE; if (db.SaveChanges() == 0) { return(false); } return(true); } else { throw new Exception(); } } } catch (Exception ex) { throw; } }
public bool deleteById(string answerId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { int id = Int32.Parse(answerId); var selectedAnswer = (from p in db.ANSWERs where p.ANSWER_ID == id select p).SingleOrDefault(); if (selectedAnswer != null) { db.ANSWERs.Remove(selectedAnswer); if (db.SaveChanges() == 0) { throw new Exception(); } } else { throw new NotImplementedException(); } return(true); } } catch (Exception ex) { throw; } }
public bool updateByApplyIdAndTestId(RESULT t) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedResult = (from p in db.RESULTs where p.APPLY_ID == t.APPLY_ID && p.TEST_ID == t.TEST_ID select p).SingleOrDefault(); if (selectedResult != null) { selectedResult.TEST_INDEX = t.TEST_INDEX; selectedResult.TEST_RESULT_1 = t.TEST_RESULT_1; selectedResult.TEST_RESULT_2 = t.TEST_RESULT_2; selectedResult.TEST_RESULT_3 = t.TEST_RESULT_3; if (db.SaveChanges() == 0) { return(false); } return(true); } else { throw new Exception(); } } } catch (Exception ex) { throw; } }
public bool update(ANSWER t) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedAnswer = (from p in db.ANSWERs where p.ANSWER_ID == t.ANSWER_ID select p).SingleOrDefault(); if (selectedAnswer != null) { selectedAnswer.QUESTION_ID = t.QUESTION_ID; selectedAnswer.ANSWER1 = t.ANSWER1; selectedAnswer.STATUS = t.STATUS; if (db.SaveChanges() == 0) { return(false); } return(true); } else { throw new Exception(); } } } catch (Exception ex) { throw; } }
public int getTestIdByApplyId(string applyId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { int id = Int32.Parse(applyId); var selectedPost = (from p in db.JOB_APPLICATION where p.APPLY_ID == id select p).SingleOrDefault(); int postId = selectedPost.POST_ID; var selectedTest = (from t in db.TESTs where t.POST_ID == postId select t).SingleOrDefault(); if (selectedTest != null) { return(selectedTest.TEST_ID); } else { throw new Exception(); } } } catch (Exception ex) { return(0); } }
public List <QUESTION> GetQuestionsExceptTestQ(int testId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { var selectedTest = (from p in db.TESTs where p.TEST_ID == testId select p).SingleOrDefault(); List <QUESTION> questions = new List <QUESTION>(); var selectedQuestions = (from q in db.QUESTIONs select q).ToList(); foreach (var q in selectedQuestions) { int check = 0; foreach (var qu in selectedTest.QUESTIONs) { if (q.QUESTION_ID == qu.QUESTION_ID) { check = 1; break; } } if (check == 0) { questions.Add(q); } } return(questions); } } catch (Exception ex) { throw; } }
public bool deleteByApplyIdAndTestId(string applyId, string testId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { int aid = Int32.Parse(applyId); int tid = Int32.Parse(testId); var selectedResult = (from p in db.RESULTs where p.APPLY_ID == aid && p.TEST_ID == tid select p).SingleOrDefault(); if (selectedResult != null) { db.RESULTs.Remove(selectedResult); if (db.SaveChanges() == 0) { throw new Exception(); } } else { throw new Exception(); } return(true); } } catch (Exception ex) { throw; } }
//background service to delete all user is finished test public static void deletebackgroundUsrNotAvailable() { try { while (true) { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { DateTime t1 = DateTime.Now; DateTime t2 = t1.AddMinutes(-1); var list = db.FIND_USR_BY_TEST_END(t1, t2); foreach (var i in list) { var temp = (from p in db.USRs where p.USERNAME == i.USERNAME select p).SingleOrDefault(); db.USRs.Remove(temp); } if (db.SaveChanges() == 0) { throw new Exception("CAN NOT DELETE USR"); } } //sleep for 1 minute Thread.Sleep(60000); } } catch (Exception) { throw; } }
public static List <TestQuestion> getQuestionByUsernameAndIndex(String username, int index) { APTECH_SEM_3Entities db = new APTECH_SEM_3Entities(); try { List <TestQuestion> returnList = new List <TestQuestion>(); String category = ""; if (index == 1) { category = "GENERAL KNOWLEDGE"; } else if (index == 2) { category = "MATHEMATICS"; } else if (index == 3) { category = "COMPUTER TECHNOLOGY"; } foreach (var i in db.FIND_QID_FROM_USERNAME(username)) { int result = i ?? 0; //throw if result == 0 cause i can not be null or == 0 if (result == 0) { throw new Exception("CAN NOT FOUND QUESTION ID"); } //get question int QuestionID = new int(); try { QuestionID = (from p in db.QUESTIONs where p.QUESTION_ID == i && p.CATEGORY == category select p).SingleOrDefault().QUESTION_ID; } catch (Exception) { continue; } // if question not in index type continue if (QuestionID == 0) { continue; } returnList.Add(new TestQuestion(QuestionID)); } return(returnList); } catch (Exception) { return(null); } }
public static int getIndexByApplyId(int apply_id) { try { APTECH_SEM_3Entities db = new APTECH_SEM_3Entities(); return((from p in db.RESULTs where p.APPLY_ID == apply_id select p).Single().TEST_INDEX); } catch (Exception) { throw; } }
public List <RESULT> findAll() { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { return((from p in db.RESULTs select p).ToList()); } } catch (Exception ex) { throw; } }
public List <RESULT> FindResultByTestId(int testId) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { return((from p in db.RESULTs where p.TEST_ID == testId select p).ToList()); } } catch (Exception ex) { throw; } }
public List <JOB_APPLICATION> findByStatus(int status) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { return((from p in db.JOB_APPLICATION where p.APPROVE_STATUS == status select p).ToList()); } } catch (Exception ex) { throw; } }
public List <JOB_APPLICATION> findAll() { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { return((from p in db.JOB_APPLICATION select p).ToList()); } } catch (Exception ex) { throw; } }
public List <USR> findByRole(string role) { try { using (APTECH_SEM_3Entities db = new APTECH_SEM_3Entities()) { return((from p in db.USRs where p.ROLE == role select p).ToList()); } } catch (Exception ex) { throw; } }