public List <Session> GetAllSessions() { List <Session> dataSession = new List <Session>(); try { using (BytepadDBEntities db = new BytepadDBEntities()) { List <tblSession> dataTblSession = new List <tblSession>(); dataTblSession = db.tblSessions.ToList(); foreach (var item in dataTblSession) { dataSession.Add(new Session { Id = item.Id, EachSession = item.Session, }); } } } catch (Exception ex) { string error = ex.ToString(); } return(dataSession); }
public List <Paper> GetAllPapers() { List <Paper> dataPapers = new List <Paper>(); try { using (BytepadDBEntities db = new BytepadDBEntities()) { List <tblPaper> dataTblPapers = new List <tblPaper>(); dataTblPapers = db.tblPapers.ToList(); foreach (var item in dataTblPapers) { dataPapers.Add(new Paper { Id = item.Id, AdminId = item.AdminId, SessionId = item.SessionId, SubjectId = item.SubjectId, ExamTypeId = item.ExamTypeId, SemesterType = Convert.ToInt32(item.SemesterType), FileUrl = item.FileUrl, PaperType = item.PaperType, SubjectName = _subject.subjectDetailsById(item.SubjectId) }); } } } catch (Exception ex) { string error = ex.ToString(); } return(dataPapers); }
public List <Paper> getPapersBySessionAndExamType(int sessionId, int examId) { List <Paper> allPapers = new List <Paper>(); using (BytepadDBEntities db = new BytepadDBEntities()) { List <tblPaper> papers = db.tblPapers.Where(x => x.SessionId == sessionId && x.ExamTypeId == examId).ToList(); foreach (var paper in papers) { Paper newPaper = new Paper { Id = paper.Id, SessionId = paper.SessionId, AdminId = paper.AdminId, SubjectId = paper.SubjectId, ExamTypeId = paper.ExamTypeId, SemesterType = Convert.ToInt32(paper.SemesterType), PaperType = paper.PaperType, FileUrl = paper.FileUrl, SubjectName = _subject.subjectDetailsById(paper.SubjectId) }; allPapers.Add(newPaper); } } return(allPapers); }
public List <ExamType> GetAllExamTypes() { List <ExamType> dataExamType = new List <ExamType>(); try { using (BytepadDBEntities db = new BytepadDBEntities()) { List <tblExamType> dataTblExamType = new List <tblExamType>(); dataTblExamType = db.tblExamTypes.ToList(); foreach (var item in dataTblExamType) { dataExamType.Add(new ExamType { Id = item.Id, Exam = item.ExamType, }); } } } catch (Exception ex) { string error = ex.ToString(); } return(dataExamType); }
public List <Subject> GetAllSubjects() { List <Subject> dataSubject = new List <Subject>(); try { using (BytepadDBEntities db = new BytepadDBEntities()) { List <tblSubject> dataTblSubject = new List <tblSubject>(); dataTblSubject = db.tblSubjects.ToList(); foreach (var item in dataTblSubject) { dataSubject.Add(new Subject { Id = item.Id, SubjectName = item.SubjectName, }); } } } catch (Exception ex) { string error = ex.ToString(); } return(dataSubject); }
public void AddPaper(IPaper dataPaper) { try { using (BytepadDBEntities db = new BytepadDBEntities()) { tblPaper dataTblPaper = new tblPaper { AdminId = 1, SessionId = dataPaper.SessionId, SubjectId = dataPaper.SubjectId, ExamTypeId = dataPaper.ExamTypeId, SemesterType = dataPaper.SemesterType.ToString(), PaperType = dataPaper.PaperType, FileUrl = dataPaper.FileUrl }; db.tblPapers.Add(dataTblPaper); db.SaveChanges(); } } catch (Exception ex) { string error = ex.ToString(); } }
public List <Paper> FindPapersBySubjectId(int id) { List <Paper> PapersOfSameSubject = new List <Paper>(); try { using (BytepadDBEntities db = new BytepadDBEntities()) { foreach (var paper in db.tblPapers.ToList()) { if (paper.SubjectId == id) { PapersOfSameSubject.Add(new Paper { Id = paper.Id, AdminId = paper.AdminId, SessionId = paper.SessionId, SubjectId = paper.SubjectId, ExamTypeId = paper.ExamTypeId, SemesterType = Convert.ToInt32(paper.SemesterType), PaperType = paper.PaperType, FileUrl = paper.FileUrl, SubjectName = _subject.subjectDetailsById(paper.SubjectId) }); } } } } catch (Exception ex) { string error = ex.ToString(); } return(PapersOfSameSubject); }
public string subjectDetailsById(int id) { tblSubject sub; using (BytepadDBEntities db = new BytepadDBEntities()) { sub = db.tblSubjects.FirstOrDefault(x => x.Id == id); } return(sub.SubjectName); }
public bool isValidCredentials(Login data) { bool present = false; using (BytepadDBEntities db = new BytepadDBEntities()) { var temp = db.tblAdmins.Where(a => a.Username == data.Username && a.Password == data.Password).FirstOrDefault(); if (temp != null) { present = true; } } return(present); }
public void DeletePaperByID(int id) { using (BytepadDBEntities db = new BytepadDBEntities()) { tblPaper tempPaper = new tblPaper(); tempPaper = db.tblPapers.First(data => data.Id == id); string physicalPathDeleted = System.Web.HttpContext.Current.Server.MapPath("~\\" + ("Papers") + "/" + tempPaper.FileUrl); if (System.IO.File.Exists(physicalPathDeleted)) { System.IO.File.Delete(physicalPathDeleted); } db.tblPapers.Remove(tempPaper); db.SaveChanges(); } }
public void RemovePaperBySession(int sessionId) { using (BytepadDBEntities db = new BytepadDBEntities()) { var papers = db.tblPapers.Where(x => x.SessionId == sessionId).ToList(); foreach (var paper in papers) { string physicalPathDeleted = System.Web.HttpContext.Current.Server.MapPath("~\\" + ("Papers") + "/" + paper.FileUrl); if (System.IO.File.Exists(physicalPathDeleted)) { System.IO.File.Delete(physicalPathDeleted); } } db.tblPapers.RemoveRange(papers); db.SaveChanges(); } }
public DateTime?getLastAddPaperTime() { tblVersion temp; using (BytepadDBEntities db = new BytepadDBEntities()) { temp = db.tblVersions.FirstOrDefault(data => data.ID == 1); } if (temp == null) { return(null); } else { return(temp.LastAddPaperTime); } }
public string GetExamType(int id) { string foundExamType = ""; try { using (BytepadDBEntities db = new BytepadDBEntities()) { var found = db.tblExamTypes.FirstOrDefault(data => data.Id == id); foundExamType = found.ExamType.ToString(); } } catch (Exception ex) { string error = ex.ToString(); } return(foundExamType); }
public string GetSession(int id) { string foundSession = ""; try { using (BytepadDBEntities db = new BytepadDBEntities()) { var found = db.tblSessions.FirstOrDefault(data => data.Id == id); foundSession = found.Session.ToString(); } } catch (Exception ex) { string error = ex.ToString(); } return(foundSession); }
public int AddSubjects(ISubject dataSubject) { tblSubject dataTblSubject = new tblSubject(); try { using (BytepadDBEntities db = new BytepadDBEntities()) { dataTblSubject.SubjectName = dataSubject.SubjectName; db.tblSubjects.Add(dataTblSubject); db.SaveChanges(); } } catch (Exception ex) { string error = ex.ToString(); } return(dataTblSubject.Id); }
public void updateLastAddPaperTime() { using (BytepadDBEntities db = new BytepadDBEntities()) { tblVersion temp = db.tblVersions.FirstOrDefault(data => data.ID == 1); if (temp == null) { temp = new tblVersion(); temp.ID = 1; temp.LastAddPaperTime = DateTime.Now; db.tblVersions.Add(temp); db.SaveChanges(); } else { temp.LastAddPaperTime = DateTime.Now; db.SaveChanges(); } } }
public bool FindPaper(string fileUrl) { bool present = false; try { using (BytepadDBEntities db = new BytepadDBEntities()) { var check = db.tblPapers.FirstOrDefault(data => data.FileUrl.Equals(fileUrl)); if (check != null) { present = true; } } } catch (Exception ex) { string error = ex.ToString(); } return(present); }
public int FindSubject(ISubject dataSubject) { int id = -1; try { using (BytepadDBEntities db = new BytepadDBEntities()) { var check = db.tblSubjects.FirstOrDefault(data => data.SubjectName.Equals(dataSubject.SubjectName)); if (check != null) { id = check.Id; } } } catch (Exception ex) { string error = ex.ToString(); } return(id); }