コード例 #1
0
ファイル: StudentController.cs プロジェクト: s16600/CW10
        public IActionResult Student(Student student)
        {
            var s = new Student();

            s.IndexNumber  = student.IndexNumber;
            s.FirstName    = student.FirstName;
            s.LastName     = student.LastName;
            s.BirthDate    = student.BirthDate;
            s.IdEnrollment = student.IdEnrollment;

            var db = new s16600Context();

            db.Student.Add(s);
            db.SaveChanges();

            return(Ok(s));

            /*
             * {
             *  "IndexNumber": "S166100",
             *  "FirstName": "Jan",
             * "LastName": "Winnicki",
             * "BirthDate": "2001-01-25",
             * "IdEnrollment": 1
             * }
             */
        }
コード例 #2
0
ファイル: StudentController.cs プロジェクト: s16600/CW10
        public IActionResult Student()
        {
            var db = new s16600Context();
            var s  = db.Student.ToList();

            return(Ok(s));
        }
コード例 #3
0
ファイル: StudentController.cs プロジェクト: s16600/CW10
        public IActionResult Student(string Index)
        {
            var db = new s16600Context();
            var s  = db.Student.Where(s => s.IndexNumber.Equals(Index)).First();

            db.Student.Remove(s);
            db.SaveChanges();

            return(Ok("Usunięto studenta"));
        }
コード例 #4
0
        public IActionResult EnrollStudent(EnrollmentDTO enrolment)
        {
            var db = new s16600Context();

            //if (db.Studies.Count(s => s.Name == e.Studies) == 0)
            if (!db.Studies.Any(s => s.Name == enrolment.Studies))

            {
                return(BadRequest("Brak takiego kierunku studiów"));
            }

            if (db.Student.Any(s => s.IndexNumber == enrolment.IndexNumber))
            {
                return(BadRequest("Student o takim numerze indeksu już istnieje"));
            }

            var ids = db.Studies.Where(s => s.Name == enrolment.Studies).First().IdStudy;

            if (!db.Enrollment.Any(e => (e.Semester == 1) && (e.IdStudy == ids)))
            {
                var e = new Enrollment();
                e.IdEnrollment = db.Enrollment.Max(e => e.IdEnrollment) + 1;
                e.Semester     = 1;
                e.IdStudy      = ids;
                e.StartDate    = DateTime.Now;

                db.Enrollment.Add(e);
                db.SaveChanges();

                //return Ok("Dodano rekrutację");
            }

            var s = new Student();

            s.IndexNumber  = enrolment.IndexNumber;
            s.FirstName    = enrolment.FirstName;
            s.LastName     = enrolment.LastName;
            s.BirthDate    = Convert.ToDateTime(enrolment.BirthDate);
            s.IdEnrollment = db.Enrollment.Where(e => (e.Semester == 1) && (e.IdStudy == ids)).First().IdEnrollment;

            db.Student.Add(s);
            db.SaveChanges();

            return(Ok("Dodano studenta"));

            /*
             * {
             *  "IndexNumber": "s12345",
             *  "FirstName": "Andrzej",
             *  "LastName": "Malewski",
             *  "BirthDate": "30.03.1993",
             *  "Studies": "IT"
             * }*/
        }
コード例 #5
0
ファイル: StudentController.cs プロジェクト: s16600/CW10
        public IActionResult Student(string Index, string FirstName)
        {
            var db      = new s16600Context();
            var student = (from s in db.Student
                           where s.IndexNumber == Index
                           select s).First();

            student.FirstName = FirstName;
            db.SaveChanges();

            return(Ok("Zmieniono imię studenta"));
        }