Exemplo n.º 1
0
 public void createGrade(int realId, string gradeName, string maxValue)
 {
     try
     {
         using (var db = new DataContext())
         {
             var real = db.Realisations.Find(realId);
             var grade = new Grade { Realisation = real, Name = gradeName, MaxValue = maxValue };
             db.Grades.Add(grade);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Dodawanie oceny");
     }
 }
Exemplo n.º 2
0
 public void updateRegistration(int id, int realId, int studId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var orig = db.Registrations.Include("Realisation").Include("Student").Where(o => o.RegistrationID == id).FirstOrDefault();
             if (orig != null)
             {
                 if (orig.Realisation.RealisationID != realId || orig.Student.StudentID != studId)
                 {
                     if (db.Registrations.Where(o => o.Realisation.RealisationID == realId).Where(o => o.Student.StudentID == studId).FirstOrDefault() != null)
                     {
                         throw new EresDataContextException("Student juz jest dodany do realizacji", "Modyfikacja rejestracji");
                     }
                     else
                     {
                         var real = db.Realisations.Find(realId);
                         orig.Realisation = real;
                         var stud = db.Students.Find(studId);
                         orig.Student = stud;
                         orig.TimeStamp = timestamp;
                         db.Registrations.Attach(orig);
                         db.Entry(orig).State = EntityState.Modified;
                         db.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Modyfikacja rejestracji");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Modyfikacja rejestracji");
     }
     catch (EresDataContextException e)
     {
         throw e;
     }
 }
Exemplo n.º 3
0
 public void deleteRegistration(Registration r)
 {
     try
     {
         using (var db = new DataContext())
         {
             var orig = db.Registrations.Find(r.RegistrationID);
             if (orig != null)
             {
                 db.Registrations.Remove(orig);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Usuwanie rejestracji");
     }
     catch (DbUpdateException)
     {
         throw new EresDataContextException("Nie mozna usunac trwajacej rejestracji!", "Usuwanie rejestracji");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Usuwanie rejestracji");
     }
 }
Exemplo n.º 4
0
        public void updateRealisation(int id, int semId, int subId, byte[] timestamp)
        {
            try
            {
                using (var db = new DataContext())
                {
                    var orig = db.Realisations.Include("Subject").Include("Semester").Where(o => o.RealisationID == id).FirstOrDefault();
                    if (orig != null)
                    {
                        if (orig.Semester.SemesterID != semId || orig.Subject.SubjectID != subId) //jeśli coś się zmieniło
                        {
                            if (db.Realisations.Where(o => o.Subject.SubjectID == subId).Where(o => o.Semester.SemesterID == semId).FirstOrDefault() != null)
                            {
                                throw new EresDataContextException("Jest juz semestr z tym przedmiotem.", "Modyfikacja realizacji");

                            }
                            else
                            {
                                var sem = db.Semesters.Find(semId);
                                orig.Semester = sem;
                                var sub = db.Subjects.Find(subId);
                                orig.Subject = sub;
                                orig.TimeStamp = timestamp;
                                db.Realisations.Attach(orig);
                                db.Entry(orig).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Modyfikacja realizacji");
            }
            catch (DbEntityValidationException)
            {
                throw new EresDataContextException("Blad polaczania z baza danych.", "Modyfikacja realizacji");
            }
            catch (EresDataContextException)
            {
                throw;
            }
        }
Exemplo n.º 5
0
 public void createRegistration(int realId, int studId)
 {
     try
     {
         using (var db = new DataContext())
         {
             var real = db.Realisations.Find(realId);
             var stud = db.Students.Find(studId);
             var reg = new Registration { Realisation = real, Student = stud };
             db.Registrations.Add(reg);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Dodawanie rejestracji");
     }
 }
Exemplo n.º 6
0
 public void createGV(int regId, int gradeId, string value, string date)
 {
     try
     {
         using (var db = new DataContext())
         {
             var reg = db.Registrations.Find(regId);
             var grade = db.Grades.Find(gradeId);
             var gv = new GradeValue { Registration = reg, Grade = grade, Value = value, Date = date };
             db.GradeValues.Add(gv);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Dodawanie wartosci oceny");
     }
 }
Exemplo n.º 7
0
 public void updateStudent(int id, string ind, string first, string last, int groupId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Students.Include("Group").Where(orig => orig.StudentID == id).FirstOrDefault(); 
             if (original != null)
             {
                 if (!string.IsNullOrEmpty(first))
                     original.FirstName = first;
                 if (!string.IsNullOrEmpty(ind))
                     original.IndexNo = ind;
                 if (!string.IsNullOrEmpty(last))
                     original.LastName = last;
                 if (groupId!=original.Group.GroupID )
                 {
                     var group = db.Groups.Find(groupId);
                     original.Group = group;
                 }
                 original.TimeStamp = timestamp;
                 db.Students.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Operacja sie nie powiodla. Sprobuj jeszcze raz za chwile", "Modyfikacja studenta");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Nie mozna modyfikowac studenta. Blad polaczenia z baza danych.", "Modyfikacja studenta");
     }
 }
Exemplo n.º 8
0
 public void createSemester(string NewSemName)
 {
     try
     {
         using (var db = new DataContext())
         {
             var sem = new Semester { Name = NewSemName };
             db.Semesters.Add(sem);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Dodawanie semestru");
     }
 }
Exemplo n.º 9
0
 public void updateSemester(int id, string n, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Semesters.Where(orig => orig.SemesterID == id).FirstOrDefault();
             if (original != null)
             {
                 if (!original.Name.Equals(n))
                 {
                     original.Name = n;
                     original.TimeStamp = timestamp;
                     db.Semesters.Attach(original);
                     db.Entry(original).State = EntityState.Modified;
                     db.SaveChanges();
                 }
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Modyfikacja semestru");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Modyfikacja semestru");
     }
 }
Exemplo n.º 10
0
 public void createSubject(string newName, string newConspect, string newUrl)
 {
     try
     {
         using (var db = new DataContext())
         {
             var subject = new Subject { Name = newName, Conspect = newConspect, url = newUrl };
             db.Subjects.Add(subject);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     { 
         throw new EresDataContextException("Blad polaczenia z baza danych" ,"Dodawanie przedmiotu");
     }
 }
Exemplo n.º 11
0
 public void updateSubject(int id, string NewSubName, string NewConspect, string NewUrl, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Subjects.Where(orig => orig.SubjectID == id).FirstOrDefault();
             if (original != null)
             {
                 if (!string.IsNullOrEmpty(NewSubName))
                     original.Name = NewSubName;
                 if (!string.IsNullOrEmpty(NewConspect))
                     original.Conspect = NewConspect;
                 if (!string.IsNullOrEmpty(NewUrl))
                     original.url = NewUrl;
                 original.TimeStamp = timestamp;
                 db.Subjects.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Modyfikacja przedmiotu");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Modyfikacja przedmiotu");
     }
 }
Exemplo n.º 12
0
 public void deleteGroup(Group gr)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Groups.Find(gr.GroupID);
             if (original != null)
             {
                 db.Groups.Remove(original);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Usuwanie grupy");
     }
     catch (DbUpdateException)
     {
         throw new EresDataContextException("Nie mozna usunac grupy ze studentami", "Usuwanie grupy");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Usuwanie grupy");
     }
 }
Exemplo n.º 13
0
        public void createGroup(string NewGName)
        {
            try
            {
                using (var db = new DataContext())
                {
                    var group = new Group { Name = NewGName };
                    db.Groups.Add(group);
                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException)
            { throw new EresDataContextException("Blad polaczenia z baza danych", "Dodawanie grupy"); }

        }
Exemplo n.º 14
0
 public void deleteStudent(Student st)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Students.Find(st.StudentID);
             if (original != null)
             {
                 db.Students.Remove(original);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Tymczasowy problem z dostepem do bazy. Sprobuj ponownie za chwile.", "Usuniecie studenta");
     }
     catch (DbUpdateException)
     {
         throw new EresDataContextException("Nie mozna usunac studenta zarejestrowanego w realizacji!", "Usuniecie studenta") ;
     }
     catch (DbEntityValidationException) 
     {
         throw new EresDataContextException("Nie mozna usunac studenta, problem z baza danych", "Usuniecie studenta");
     }
 }
Exemplo n.º 15
0
 public void updateGrade(int id, string gradeName, string maxValue, int realId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Grades.Include("Realisation").Where(orig => orig.GradeID == id).FirstOrDefault();
             if (original != null)
             {
                 if (realId != original.Realisation.RealisationID)
                 {
                     var real = db.Realisations.Find(realId);
                     original.Realisation = real;
                 }
                 if (!string.IsNullOrEmpty(maxValue))
                 {
                     string Stud = string.Empty;
                     List<GradeValue> gv = db.GradeValues.Include("Grade").Include("Registration").Include("Registration.Student").Where(o => o.Grade.GradeID == id).ToList();
                     if (gv != null)
                     {
                         foreach(GradeValue v in gv)
                         {
                             if (!Validation(maxValue, v.Value))
                             {
                                 Stud = string.Concat(Stud, "\n", v.Registration.Student.LastName);
                                 Console.WriteLine(v.Registration.Student.LastName);
                             }
                         }
                         if (!string.IsNullOrEmpty(Stud))
                         {
                             throw new EresDataContextException("Musisz podac ocene", "Modyfikacja oceny");
                         }
                     }
                     original.MaxValue = maxValue.ToUpper();
                 }
                 if (!string.IsNullOrEmpty(gradeName))
                 {
                     if (db.Grades.Include("Realisation").Where(o => o.Realisation.RealisationID == realId).Where(o => o.Name == gradeName).FirstOrDefault() != null)
                     {
                         throw new EresDataContextException("Nazwa oceny musi byc unikalna", "Modyfikacja oceny");
                     }
                     original.Name = gradeName;
                 }
                 original.TimeStamp = timestamp;
                 db.Grades.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Modyfikacja oceny");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Modyfikacja oceny");
     }
     catch (EresDataContextException e)
     {
         throw e;
     }
 }
Exemplo n.º 16
0
 public void deleteSemester(Semester sem)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.Semesters.Find(sem.SemesterID);
             if (original != null)
             {
                 db.Semesters.Remove(original);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Usuwanie semestru");
     }
     catch (DbUpdateException)
     {
         throw new EresDataContextException("Nie mozna usunac semestru z realizacja!", "Usuwanie semestru");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Usuwanie semestru");
     }
 }
Exemplo n.º 17
0
 public void deleteGV(GradeValue gv)
 {
     try
     {
         using (var db = new DataContext())
         {
             var orig = db.GradeValues.Find(gv.GradeValueID);
             if (orig != null)
             {
                 db.GradeValues.Remove(orig);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Usuwanie wartosci oceny");
     }
     catch (DbUpdateException)
     {
         throw new EresDataContextException("Nie usunac tej wartosci oceny!", "Usuwanie wartosci oceny");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Usuwanie wartosci oceny");
     }
 }
Exemplo n.º 18
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");
     }
 }
Exemplo n.º 19
0
 public void updateGV(int id, string value, string date, int regId, int gradeId, byte[] timestamp)
 {
     try
     {
         using (var db = new DataContext())
         {
             var original = db.GradeValues.Include("Registration").Include("Grade").Where(orig => orig.GradeValueID == id).FirstOrDefault();
             if (original != null)
             {
                 if (regId != original.Registration.RegistrationID || gradeId != original.Grade.GradeID)
                 {
                     if (isGrade(gradeId, regId))
                     {
                         throw new EresDataContextException("Student ma juz ta ocene", "Modyfikacja wartosci oceny");
                     }
                     var reg = db.Registrations.Find(regId);
                     original.Registration = reg;
                     var g = db.Grades.Find(gradeId);
                     original.Grade = g;
                 }
                 if (!string.IsNullOrEmpty(value))
                 {
                     original.Value = value.ToUpper();
                 }
                 if (!string.IsNullOrEmpty(date))
                 {
                     original.Date = date;
                 }
                 original.TimeStamp = timestamp;
                 db.GradeValues.Attach(original);
                 db.Entry(original).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych. Sprobuj jeszcze raz.", "Modyfikacja wartosci oceny");
     }
     catch (DbEntityValidationException)
     {
         throw new EresDataContextException("Blad polaczania z baza danych.", "Modyfikacja wartosci oceny");
     }
     catch (EresDataContextException e)
     {
         throw e;
     }
 }
Exemplo n.º 20
0
 public void createStudent(string firstName, string lastName, string index, int groupId)
 {
     try
     {
         using (var db = new DataContext())
         {
             var group = db.Groups.Find(groupId);
             var student = new Student { FirstName = firstName, LastName = lastName, IndexNo = index, Group = group };
             db.Students.Add(student);
             db.SaveChanges();
         }
     }
     catch (DbEntityValidationException)
     { throw new EresDataContextException("Nie mozna dodac studenta. Blad polaczenia z baza danych.", "Dodawanie studenta"); }
     catch (DbUpdateException)
     {
         throw new EresDataContextException("Dany student jest juz w bazie", "Dodawanie studenta");
     }
 }