示例#1
0
        public IActionResult StudentPromotion(StudentPromotionRequest request)
        {
            var response = _service.StudentPromotion(request);

            if (response.answer == "OK")
            {
                return(Created(response.answer, response));
            }
            else
            {
                return(NotFound(response));
            }
        }
示例#2
0
        public StudentPromotionResponse StudentPromotion(StudentPromotionRequest request)
        {
            StudentPromotionResponse response = new StudentPromotionResponse();
            Enrollment enrollment             = new Enrollment();

            using (SqlConnection connectionSql = new SqlConnection(ConString))
                using (SqlCommand commandSql = new SqlCommand("PromoteStudents", connectionSql))
                {
                    commandSql.CommandType = CommandType.StoredProcedure;
                    commandSql.Parameters.AddWithValue("@name", request.Name);
                    commandSql.Parameters.AddWithValue("@semester", request.Semester);

                    response.answer = "OK";

                    SqlCommand command = new SqlCommand();

                    command.Connection = connectionSql;
                    connectionSql.Open();


                    command.CommandText = "select IdStudy from Studies where Name=@name";
                    command.Parameters.AddWithValue("name", request.Name);

                    var readStudiesName = command.ExecuteReader();
                    if (!readStudiesName.Read())
                    {
                        response.answer = "Brak studiów w bazie";
                        return(response);
                    }
                    int idstudies = (int)readStudiesName["IdStudy"];
                    readStudiesName.Close();

                    command.CommandText = "select idEnrollment,semester,idstudy,StartDate from Enrollment where idStudy=@idStudy and Semester=@Semester";
                    command.Parameters.AddWithValue("idStudy", idstudies);
                    command.Parameters.AddWithValue("Semester", request.Semester + 1);

                    var readEnrollment = command.ExecuteReader();
                    if (readEnrollment.Read())
                    {
                        enrollment.IdEnrollment = (int)readEnrollment["IdEnrollment"];
                        enrollment.Semester     = (int)readEnrollment["Semester"];
                        enrollment.IdStudy      = (int)readEnrollment["IdStudy"];
                        enrollment.StartDate    = (DateTime)readEnrollment["StartDate"];
                    }
                    readEnrollment.Close();
                    response.enrollment = enrollment;

                    return(response);
                }
        }