コード例 #1
0
        public IEnumerable <Response> PromoteStudent(PromoteStudentsRequests psrequest)
        {
            var db            = new s19461Context();
            var responsesList = new List <Response>();

            var study = db.Studies.Where(s => s.Name == psrequest.Studies).FirstOrDefault();

            var enrollment = db.Enrollment.Where(e => e.Semester == psrequest.Semester && e.IdStudy == study.IdStudy).First();

            var newEnrollment = db.Enrollment.Where(e => e.Semester == psrequest.Semester + 1 && e.IdStudy == study.IdStudy).FirstOrDefault();

            var newIdEnrollment = db.Enrollment.Max(e => e.IdEnrollment) + 1;

            if (newEnrollment == null)
            {
                db.Enrollment.Add(new Enrollment
                {
                    IdEnrollment = newIdEnrollment,
                    Semester     = psrequest.Semester + 1,
                    IdStudy      = study.IdStudy,
                    StartDate    = DateTime.Now
                });

                newEnrollment = db.Enrollment.Where(e => e.Semester == psrequest.Semester + 1 && e.IdStudy == study.IdStudy).FirstOrDefault();
            }

            var studentsList = db.Student.Where(student => student.IdEnrollment == enrollment.IdEnrollment).ToList();

            foreach (var student in studentsList)
            {
                student.IdEnrollment = newEnrollment.IdEnrollment;
            }


            var psresponse = new Response
            {
                IdEnrollment = newEnrollment.IdEnrollment,
                Semester     = psrequest.Semester + 1,
                IdStudy      = study.IdStudy,
                StartDate    = DateTime.Now
            };

            responsesList.Add(psresponse);
            return(responsesList);
        }
コード例 #2
0
        public IActionResult PromoteStudent(PromoteStudentsRequests promote)
        {
            var res = _dbService.PromoteStudent(promote);

            return(Ok(res));
        }