예제 #1
0
      public IActionResult CreateStudent([FromServices] IStudentsDb service, Student newStudent)
      {
          using (SqlConnection con = new SqlConnection())
              using (SqlCommand com = new SqlCommand())
              {
                  com.Connection  = con;
                  com.CommandText = "insert into students(IndexNumber,FirstName,LastName) values (@par1,@par2,@par3)";

                  com.Parameters.AddWithValue("@par1", newStudent.IndexNumber);
                  com.Parameters.AddWithValue("@par2", newStudent.FirstName);
                  com.Parameters.AddWithValue("@par3", newStudent.LastName);

                  con.Open();
                  int affectedRows = com.ExecuteNonQuery();
              }

          return(Ok());
      }
예제 #2
0
        public IActionResult CreateStudent([FromServices] IStudentsDb service, Student newStudent)
        {
            using (SqlConnection con = new SqlConnection(ConnString))
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = con;
                    command.CommandText = "insert into student(IndexNumber, FirstName, LastName,BirthDate, IdEnrollment) values (@par1, @par2, @par3,@par4,@par5)";

                    command.Parameters.AddWithValue("s789", newStudent.IndexNumber);
                    command.Parameters.AddWithValue("Snoopy", newStudent.FirstName);
                    command.Parameters.AddWithValue("Dogg", newStudent.LastName);
                    command.Parameters.AddWithValue("1980-10-09", newStudent.BirthDate);
                    command.Parameters.AddWithValue("3", newStudent.IdEnrollment);

                    con.Open();
                    int affectedRows = command.ExecuteNonQuery();
                }

            return(Ok(newStudent));
        }
예제 #3
0
 public StudentsController(IStudentsDb db)
 {
     _dbService = db;
 }
예제 #4
0
 public EnrollmentsController(IStudentsDb dbService, IConfiguration configuration)
 {
     Configuration = configuration;
     _dbService    = dbService;
 }
예제 #5
0
        //[3.1]


        public StudentController(IStudentsDb database)
        {
            this._dbService = database;
        }
예제 #6
0
 public StudentsController(IStudentsDb service)
 {
     _dbService = service;
 }