Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
 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();
     }
 }
Exemple #7
0
        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);
        }
Exemple #8
0
        public string subjectDetailsById(int id)
        {
            tblSubject sub;

            using (BytepadDBEntities db = new BytepadDBEntities())
            {
                sub = db.tblSubjects.FirstOrDefault(x => x.Id == id);
            }
            return(sub.SubjectName);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
 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();
     }
 }
Exemple #11
0
 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();
     }
 }
Exemple #12
0
        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);
            }
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        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);
        }
Exemple #16
0
 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();
         }
     }
 }
Exemple #17
0
        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);
        }
Exemple #18
0
        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);
        }