// POST: api/MonHoc public MonHoc Post([FromBody] MonHoc monhoc) { MonHoc mh = new MonHoc(); SqlConnection conn = DataProvider.Connect(); conn.Open(); string mamonhoc = MonHoc.layMaMH(); if (mh.kiemtra(monhoc.tenMonhoc)) { String sQuery = "INSERT INTO [dbo].[MonHoc]([MaMonHoc],[TenMonHoc],[SoTinChi],[SoTiet],[TrangThai])VALUES(@manh,@tenmh,@sotinchi,@sotiet,@trangthai)"; SqlCommand insertcommand = new SqlCommand(sQuery, conn); insertcommand.Parameters.AddWithValue("@manh", mamonhoc); insertcommand.Parameters.AddWithValue("@tenmh", monhoc.tenMonhoc); insertcommand.Parameters.AddWithValue("@sotinchi", monhoc.soTinchi); insertcommand.Parameters.AddWithValue("@sotiet", monhoc.soTiet); insertcommand.Parameters.AddWithValue("@trangthai", monhoc.trangThai); int result = insertcommand.ExecuteNonQuery(); conn.Close(); mh = mh.mh(mamonhoc); if (result > 0) { return(mh); } } else { return(mh); } return(mh); }