Exemple #1
0
        public IActionResult PromoteStudent(PromoteStudentRequest preq)
        {
            PromoteStudentResponse pres = new PromoteStudentResponse();

            pres = iDB.PromoteStudent(preq);
            return(Created("promote", pres));
        }
        public IActionResult PromoteStudents(PromoteStudentsRequest request)
        {
            if (!ModelState.IsValid)
            {
                var d = ModelState;
                return(BadRequest("!!!"));
            }

            // using (var con = new SqlConnection(ConString))
            // {
            //     using (var com = new SqlCommand())
            //     {
            //         com.Connection = con;
            //         con.Open();
            //
            //         var transaction = con.BeginTransaction();
            //         com.Transaction = transaction;
            //
            //         //1. Sprawdzam czy w tabeli enrollment istnieje wpis o podanej wartości Studies i Semester, W przeciwnym razie zwracam kod 404 Not Found
            //
            //         com.CommandText = "SELECT * FROM Enrollment" +
            //                           " INNER JOIN Studies" +
            //                           " ON Studies.IdStudy = Enrollment.IdStudy" +
            //                           " WHERE Enrollment.Semester = @semester" +
            //                           " AND Studies.Name = @studies";
            //         com.Parameters.AddWithValue("semester", request.Semester);
            //         com.Parameters.AddWithValue("studies", request.Studies);
            //
            //         var dr = com.ExecuteReader();
            //
            //         if (!dr.Read())
            //         {
            //             dr.Close();
            //
            //             return new NotFoundResult();
            //         }
            //         dr.Close();
            //
            //         // Jeżeli wszystko poszło dobrze uruchamiam procedurę składową
            //
            //         com.CommandText = "promoteStudents";
            //         com.CommandType = CommandType.StoredProcedure;
            //         dr = com.ExecuteReader();
            //         if (dr.Read())
            //         {
            //             enrollment.IdEnrollment = (int) dr["IdEnrollment"];
            //             enrollment.Semester = (int) dr["Semester"];
            //             enrollment.IdStudy = (int) dr["IdStudy"];
            //             enrollment.StartDate = (DateTime) dr["StartDate"];
            //             dr.Close();
            //         }
            //
            //
            //     }
            // }

            var response = _service.PromoteStudent(request);

            if (response.Status == 404)
            {
                return(NotFound());
            }



            return(CreatedAtAction(response.Message, response.enrollment));
        }