Пример #1
0
 public void deleteRealisation(Realisation r)
 {
     try
     {
         using (var db = new DataContext())
         {
             var orig = db.Realisations.Find(r.RealisationID);
             if (orig != null)
             {
                 db.Realisations.Remove(orig);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw;
     }
     catch (DbUpdateException)
     {
         MessageBox.Show("You can not delete used realisation.", "Realisation Deletion Error");
         return;
     }
     catch (DbEntityValidationException)
     { throw; }
 }
Пример #2
0
 public void createRealisation(int semId, int subId)
 {
     try
     {
         using (var db = new DataContext())
         {
             var semester = db.Semesters.Find(semId);
             var subject = db.Subjects.Find(subId);
             var real = new Realisation { Subject = subject, Semester = semester };
             db.Realisations.Add(real);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     { throw; }
 }
Пример #3
0
 public void deleteRealisation(Realisation r)
 {
     try
     {
         using (var db = new DataContext())
         {
             var orig = db.Realisations.Find(r.RealisationID);
             if (orig != null)
             {
                 db.Realisations.Remove(orig);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Usuwanie realizacji");
     }
     catch (DbUpdateException)
     {
         throw new EresDataContextException("Nie mozna usunac trwajacej realizacji!", "Usuwanie realizacji");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Usuwanie realizacji");
     }
 }
Пример #4
0
 public Boolean isSubInSem(Realisation r)
 {
     try
     {
         using (var db = new DataContext())
         {
             int id = r.RealisationID;
             int subId = r.Subject.SubjectID;
             int semId = r.Semester.SemesterID;
             var orig = db.Realisations.Include("Subject").Include("Semester").Where(o => o.RealisationID == id).FirstOrDefault();
             if (orig.Semester.SemesterID != semId || orig.Subject.SubjectID != subId) //jeśli coś się zmieniło
             {
                 var real = db.Realisations.Where(o => o.Subject.SubjectID == subId).Where(o => o.Semester.SemesterID == semId).FirstOrDefault();
                 if (real == null)
                     return false;
                 else
                     return true;                        
             }
             else
                 return false;
         }
     }
     catch (Exception e)
     { Console.WriteLine("isSubInSem2" + e.Message); return false; }
 }
Пример #5
0
 public void createRealisation(int semId, int subId)
 {
     try
     {
         using (var db = new DataContext())
         {
             var semester = db.Semesters.Find(semId);
             var subject = db.Subjects.Find(subId);
             var real = new Realisation { Subject = subject, Semester = semester };
             db.Realisations.Add(real);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Dodawanie realizacji");
     }
 }