//////// //End Teacher// /////////// //////// //For all Forms extensions// /////////// //Sends message to the chose person public static void SendMessage(string _to, string _title, string _body) { EducationProjectEntities db = new EducationProjectEntities(); Message message = new Message() { MessageFrom = WelcomeScreen.UserEmail, MessageTo = _to, MessageTitle = _title, MessageBody = _body }; db.Messages.Add(message); db.SaveChanges(); }
//Deletes Task from the database static public void DeleteTask(int _TaskId) { EducationProjectEntities db = new EducationProjectEntities(); try { foreach (var item in db.Tasks.ToList()) { if (item.TaskId == _TaskId) { db.Tasks.Remove(item); db.SaveChanges(); } } } catch (Exception) { MessageBox.Show("You can't delete this task , because it has been assigned to a student"); } }
//"Library"- option// //Chooses and copy a pdf file to the our PdfSource folder static public void AddPdfFile() { EducationProjectEntities db = new EducationProjectEntities(); if (fileDialog.ShowDialog() == DialogResult.OK) { //set paths rootPath = Directory.GetCurrentDirectory().ToString(); PdfSource = Path.Combine(rootPath, "PdfSource"); ChosedFile = fileDialog.FileName; FileName = Path.GetFileName(ChosedFile); if (Path.GetExtension(FileName) == ".pdf") { //Check if this name is already exist in the database if (db.PdfSources.All(e => e.PdfSourceName != FileName)) { PdfSource pdf = new PdfSource() { PdfSourceName = FileName.ToString() }; //Copy the file to the PdfSource folder File.Copy(ChosedFile, Path.Combine(PdfSource, FileName)); db.PdfSources.Add(pdf); db.SaveChanges(); } else { MessageBox.Show("This name is exist in the database, please change the name or choose another one"); } } else { MessageBox.Show("Selected file must be in a pdf format"); } } }