public IActionResult PromoteStudents(PromotionStudentRequest promotionStudentRequest)
 {
     using (var con = new SqlConnection("Data Source=db-mssql.pjwstk.edu.pl;Initial Catalog=2019SBD;Integrated Security=True"))
         using (var com = new SqlCommand())
         {
             con.Open();
             SqlTransaction tran = con.BeginTransaction();
             com.Transaction = tran;
             com.Connection  = con;
             com.Parameters.AddWithValue("Semester", promotionStudentRequest.Semester);
             com.Parameters.AddWithValue("idStudy", promotionStudentRequest.Studies);
             com.CommandText = "select count() 'cnt' from Enrollment where semester = @Semester " +
                               "and idStudy = (select idstudy from Studies where idstudy = @idStudy )";
             var dr = com.ExecuteReader();
             dr.Read();
             if ((int)dr["cnt"] > 0)
             {
                 dr.Close();
                 com.CommandText = "P_PromoteStudent";
                 com.CommandType = System.Data.CommandType.StoredProcedure;
             }
             else
             {
                 return(NotFound("Not Found"));
             }
         }
     return(Ok());
 }
示例#2
0
 public IActionResult PromoteStudents(PromotionStudentRequest request, string promotions)
 {
     if (promotions.Equals("promotions"))
     {
         try
         {
             return(Ok(_service.PromoteStudents(request.Semester, request.Studies)));
         }
         catch (Exception ex)
         {
             return(BadRequest(ex.Message));
         }
     }
     else
     {
         return(BadRequest("Bad request!"));
     }
 }
示例#3
0
        //[Authorize(Roles = "employee")]
        public IActionResult PromoteStudent(PromotionStudentRequest request)
        {
            var st = _service.GetStudyName(request.Studies);

            if (st == null)
            {
                return(NotFound("Nie znaleziono"));
            }
            var enrollment    = _service.GetEnrollment(st.IdStudy, request.Semester);
            var setEnrollment = _service.Promote(st.IdStudy, request.Semester);

            return(CreatedAtAction(nameof(GetEnrollment),
                                   new { idEnrollment = setEnrollment.IdEnrollment },
                                   new EnrollStudentResponse
            {
                IdEnrollment = setEnrollment.IdEnrollment,
                IdStudy = setEnrollment.IdStudy,
                Semester = setEnrollment.Semester,
                StartDate = setEnrollment.StartDate
            }));
        }
 public IActionResult PromotionStudent(PromotionStudentRequest promotion)
 {
     return(_service.PromoteStudents(promotion));
 }
示例#5
0
        public IActionResult PromoteStudents(PromotionStudentRequest request, string promotions)
        {
            if (promotions.Equals("promotions"))
            {
                int idStud;

                using (var con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s16503;Integrated Security=True;"))
                    using (var com = new SqlCommand())
                    {
                        com.Connection  = con;
                        com.CommandText = "SELECT Studies.IdStudy FROm Studies WHERE Studies.Name = '" + request.Studies + "';";


                        con.Open();
                        var dr = com.ExecuteReader();


                        if (dr.Read())
                        {
                            idStud = (int)dr["IdStudy"];
                        }
                        else
                        {
                            return(NotFound("Not found >> studia"));
                        }



                        //  var tran = con.BeginTransaction("SampleTransaction");
                        //  com.Transaction = tran;

                        com.CommandText = "select IdEnrollment from Enrollment where IdStudy=" + idStud + " AND Semester= " + request.Semester + ";";
                        // con.Open();
                        //  dr = com.ExecuteReader();
                        dr.Close();
                        dr = com.ExecuteReader();
                        if (!dr.Read())
                        {
                            return(NotFound("Not found >> enrollment"));
                        }



                        con.Close();
                        dr.Close();
                    }


                using (var con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s16503;Integrated Security=True;"))
                    using (var com = new SqlCommand("Promotions", con))
                    {
                        com.Connection = con;
                        con.Open();

                        try
                        {
                            com.CommandType = System.Data.CommandType.StoredProcedure;
                            com.Parameters.Add("@Studies", SqlDbType.VarChar).Value = request.Studies;
                            com.Parameters.Add("@Semester", SqlDbType.Int).Value    = request.Semester;
                            com.ExecuteNonQuery();

                            // NIECH PROCEDURA ZWRACA ENROLLMENT (selectem ) << reultSet
                            con.Close();
                        }
                        catch (SqlException ex)
                        {
                            return(BadRequest("sql error > " + ex.Message));
                        }
                    }



                using (var con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s16503;Integrated Security=True;"))
                    using (var com = new SqlCommand())
                    {
                        com.Connection  = con;
                        com.CommandText = "SELECT * FROM Enrollment WHERE Semester = " + (request.Semester + 1) + " AND IdStudy = " + idStud + " ORDER BY IdEnrollment;";


                        con.Open();
                        var dr = com.ExecuteReader();

                        var enrollment = new Enrollment();

                        if (dr.Read())
                        {
                            enrollment.IdEnrollment = (int)dr["IdEnrollment"];
                            enrollment.Semester     = (int)dr["Semester"];
                            enrollment.Study        = request.Studies;
                            enrollment.StartDate    = dr["StartDate"].ToString();
                        }
                        else
                        {
                            return(NotFound("not found new enrollment!"));
                        }



                        return(Ok(enrollment));
                    }
            }
            else
            {
                return(BadRequest("Bad request!"));
            }
        }