Esempio n. 1
0
        public static void InsertStudent()
        {
            var db = new s16705Context();

            var e = new Enrollment();

            e.IdEnrollment = db.Enrollment.Max(e => e.IdEnrollment) + 1;
            e.Semester     = 1;
            e.IdStudy      = 3;
            e.StartDate    = DateTime.Now;

            db.Enrollment.Add(e);

            Random index   = new Random();
            String indexnr = "s" + (index.Next(1000, 9999));
            var    s       = new Student
            {
                IndexNumber  = indexnr,
                FirstName    = "Anna",
                LastName     = "Zielińska",
                BirthDate    = DateTime.Now.AddYears(-20),
                IdEnrollment = e.IdEnrollment
            };

            db.Student.Add(s);

            db.SaveChanges();
        }
Esempio n. 2
0
        public IActionResult PromoteStudent(PromoteStudentRequest promote)
        {
            var db      = new s16705Context();
            var semestr = promote.Semester;
            var idStudy = db.Studies.Where(s => s.Name == promote.Studies).First().IdStudy;
            var tmp     = promote.Semester + 1;

            //var s = db.Enrollment.Where(s => (s.IdStudy == idStudy) && (s.Semester == promote.Semester));
            //db.Entry(e).Property(e => e.Semester).CurrentValue = promote.Semester+1;
            var query = "UPDATE Enrollment SET semester = " + tmp + " WHERE Semester = " + semestr + " AND IdStudy = " + idStudy;
            var pr    = db.Enrollment.FromSqlRaw(query).ToList();

            db.SaveChanges();

            return(Ok());
            //Old

            /*
             * var response = _dbService.PromoteStudents(promote.Semester, promote.Studies);
             * if (response.Info == "201 Semestr zmieniony")
             * {
             *  return Created(response.Info, response);
             *
             * }
             * else
             * {
             *  return BadRequest(response);
             * }
             */
        }
Esempio n. 3
0
        public static void UpdateStudent()
        {
            var db = new s16705Context();

            var s1 = db.Student.First();

            s1.FirstName = "Ewa";

            db.SaveChanges();
        }
Esempio n. 4
0
        public IActionResult EnrollStudent(EnrollStudentRequest student)
        {
            var db = new s16705Context();

            var idStudy = db.Studies.Where(s => s.Name == student.Studies).First().IdStudy;

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

                db.Enrollment.Add(e);
            }

            var s = new ModelsCw10.Student();

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

            db.Student.Add(s);
            try
            {
                db.SaveChanges();
            }catch (Exception e)
            {
                Console.WriteLine("Error when adding new student: " + e.Source);
            }

            return(Ok());

            //Old

            /*
             * var response = _dbService.EnrollStudent(student);
             * if(response.Info == "201 Student dodany")
             * {
             *  return Created(response.Info, response);
             * }
             * else
             * {
             *  return BadRequest(response);
             * }
             */
        }
Esempio n. 5
0
        public static void RemoveStudent()
        {
            var db = new s16705Context();

            //Opcja nr1
            var s = db.Student.Where(s => s.IdEnrollment == 8).First();

            db.Student.Remove(s);

            //Opcja nr2
            //var s = new Student
            //{
            //    IdEnrollment = 8
            //};
            //db.Attach(s);
            //db.Remove(s);

            db.SaveChanges();
        }
Esempio n. 6
0
        public static void GetStudents()
        {
            var db = new s16705Context();

            var res = db.Student.ToList();
        }