Пример #1
0
 /// <summary>
 /// Delete An Exam Using the ExamTemplateID
 /// </summary>
 /// <param name="ExamTID">The ExamTemplateID of the exam to be deleted</param>
 public void DeleteExam(string ExamTID)
 {
     EAD.ExamTemplate removedExam = new EAD.ExamTemplate();
     try
     {
         foreach (var item in db.ExamTemplate) //Gets the Exam which will be needed so it can be removed
         {
             if (item.ExamTemplateID.Equals(ExamTID))
             {
                 removedExam = item;
             }
         }
         foreach (var item in db.ExamTemplateQuestions) //Removes all references to the Exam in the database
         {
             if (item.ExamTemplateID == ExamTID)
             {
                 db.ExamTemplateQuestions.Remove(item); //Delete from Junction Table
             }
         }
         db.ExamTemplate.Remove(removedExam); // removes the ExamTemplate from the ExamTemplate table.
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         //TODO
     }
 }
Пример #2
0
 /// <summary>
 /// This Method adds a brand new exam to the database. The Parameters passed in defines the new values in the database
 /// </summary>
 /// <param name="exName">The name of the Exam</param>
 /// <param name="exTID">The Exam Template ID</param>
 /// <param name="ExamType">The Exam Type</param>
 public void AddNewExam(string exName, string exTID, string ExamType)
 {
     EAD.ExamTemplate newExt = new EAD.ExamTemplate();
     newExt.ExamTemplateName = exName;
     newExt.ExamTemplateID   = exTID;
     newExt.ExamTypeID       = db.ExamType.Where(x => x.ExamTypeName == ExamType).Select(x => x.PKID).First(); //
     newExt.CreatedDate      = DateTime.Now;                                                                   //generates the current DateTime
     try
     {
         db.ExamTemplate.Add(newExt); // adds the new exam template to the database
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         // to do
     }
 }