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