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 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 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 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); }