Esempio n. 1
0
 private Studies GetStudies(string name)
 {
     using (var db = new s18838Context())
     {
         return(db.Studies.Where(s => s.Name == name).SingleOrDefault());
     }
 }
Esempio n. 2
0
 public void removeStudent(string indexNumber)
 {
     using (var db = new s18838Context())
     {
         var student = db.Student.Where(s => s.IndexNumber == indexNumber).SingleOrDefault();
         db.Student.Remove(student);
         db.SaveChanges();
     }
 }
Esempio n. 3
0
 public IEnumerable <Enrollment> GetEnrollments(string indexNumber)
 {
     using (var db = new s18838Context())
     {
         return(db.Student
                .Where(s => s.IndexNumber == indexNumber)
                .Select(e => e.IdEnrollmentNavigation));
     }
 }
Esempio n. 4
0
 private Enrollment GetLastEnrollmentForStudy(int id)
 {
     using (var db = new s18838Context())
     {
         return(db.Enrollment
                .Where(e => e.IdStudy == id && e.Semester == 1)
                .FirstOrDefault());
     }
 }
Esempio n. 5
0
 public string CheckRefreshToken(string refreshToken)
 {
     using (var db = new s18838Context())
     {
         return(db.Token
                .Where(t => t.RefreshToken == refreshToken)
                .Select(e => e.IndexNumber)
                .FirstOrDefault());
     }
 }
Esempio n. 6
0
 public string GetSalt(string indexNumber)
 {
     using (var db = new s18838Context())
     {
         return(db.Student
                .Where(s => s.IndexNumber == indexNumber)
                .Select(e => e.Salt)
                .SingleOrDefault());
     }
 }
Esempio n. 7
0
 public bool CheckIfStudentExists(string indexNumber)
 {
     using (var db = new s18838Context())
     {
         return(db.Student
                .Where(s => s.IndexNumber == indexNumber)
                .Select(e => true)
                .FirstOrDefault());
     }
 }
Esempio n. 8
0
 public void DeleteRefreshToken(string refreshToken)
 {
     using (var db = new s18838Context())
     {
         var token = db.Token
                     .Where(t => t.RefreshToken == refreshToken)
                     .SingleOrDefault();
         db.Token.Remove(token);
         db.SaveChanges();
     }
 }
Esempio n. 9
0
 public void SaveRefreshToken(string refreshToken, string indexNumber)
 {
     using (var db = new s18838Context())
     {
         var token = new Token
         {
             IndexNumber  = indexNumber,
             RefreshToken = refreshToken
         };
         db.Token.Add(token);
         db.SaveChanges();
     }
 }
Esempio n. 10
0
 private Enrollment GetEnrollment(string name, int semester)
 {
     using (var db = new s18838Context())
     {
         return(db.Enrollment
                .Where(e => e.Semester == semester)
                .Join(
                    db.Studies.Where(s => s.Name == name),
                    e => e.IdStudy, s => s.IdStudy,
                    (e, _) => e
                    ).SingleOrDefault());
     }
 }
Esempio n. 11
0
 public void modifyStudent(string indexNumber, Student student)
 {
     using (var db = new s18838Context())
     {
         var s = db.Student.Where(s => s.IndexNumber == indexNumber).SingleOrDefault();
         s.IndexNumber  = student.IndexNumber;
         s.FirstName    = student.FirstName;
         s.BirthDate    = student.BirthDate;
         s.IdEnrollment = student.IdEnrollment;
         s.Salt         = student.Salt;
         s.Password     = student.Password;
         db.SaveChanges();
     }
 }
Esempio n. 12
0
        public Enrollment EnrollStudent(EnrollStudentRequest request)
        {
            using (var db = new s18838Context()) {
                if (request.Studies == null ||
                    request.BirthDate == null ||
                    request.FirstName == null ||
                    request.IndexNumber == null ||
                    request.LastName == null)
                {
                    throw new Exception();
                }
                using (var transaction = db.Database.BeginTransaction())
                {
                    var study = GetStudies(request.Studies);
                    if (study == null)
                    {
                        transaction.Rollback();
                        throw new Exception();
                    }
                    Enrollment enrollment = GetLastEnrollmentForStudy(study.IdStudy);
                    if (enrollment == null)
                    {
                        enrollment = new Enrollment()
                        {
                            Semester  = 1,
                            IdStudy   = study.IdStudy,
                            StartDate = DateType.FromString(DateTime.Now.ToString("MM.dd.yyyy"))
                        };

                        SaveEnrollment(db, enrollment);
                    }
                    if (CheckIfStudentExists(request.IndexNumber))
                    {
                        transaction.Rollback();
                        throw new Exception();
                    }
                    var student = new Student()
                    {
                        IndexNumber  = request.IndexNumber,
                        FirstName    = request.FirstName,
                        LastName     = request.LastName,
                        BirthDate    = DateType.FromString(request.BirthDate),
                        IdEnrollment = IntegerType.FromObject(enrollment.IdEnrollment)
                    };
                    SaveStudent(db, student);
                    transaction.Commit();
                    return(enrollment);
                }
            }
        }
Esempio n. 13
0
 public Enrollment PromoteStudents(PromoteStudentsRequest request)
 {
     using (var db = new s18838Context())
     {
         var enrollment = GetEnrollment(request.Studies, request.Semester);
         if (enrollment == null)
         {
             throw new Exception();
         }
         db.Database.ExecuteSqlRaw("exec PromoteStudents @Studies @Semester", request.Studies, request.Semester);
         enrollment.Semester++;
         return(enrollment);
     }
 }
Esempio n. 14
0
        public bool LogIn(LoginCredentials loginCredentials)
        {
            using (var db = new s18838Context())
            {
                var salt       = GetSalt(loginCredentials.Login);
                var valueBytes =
                    KeyDerivation.Pbkdf2(
                        loginCredentials.Password,
                        Encoding.UTF8.GetBytes(salt),
                        KeyDerivationPrf.HMACSHA512,
                        1000,
                        256 / 8
                        );

                var password = Convert.ToBase64String(valueBytes);
                return(db.Student
                       .Where(s => s.IndexNumber == loginCredentials.Login && s.Password == password)
                       .Select(e => true)
                       .SingleOrDefault());
            }
        }
Esempio n. 15
0
 public IEnumerable <Student> GetStudents()
 {
     using (var db = new s18838Context()) {
         return(db.Student.ToList());
     }
 }
Esempio n. 16
0
 private void SaveStudent(s18838Context db, Student student)
 {
     db.Student.Add(student);
     db.SaveChanges();
 }
Esempio n. 17
0
 private void SaveEnrollment(s18838Context db, Enrollment enrollment)
 {
     db.Enrollment.Add(enrollment);
     db.SaveChanges();
 }