public async Task <int> ThemMoiHocSinh(HocSinh hocSinh) { using (Data.Connection()) { var insertId = 0; string Query = "INSERT INTO HocSinh VALUES (@Ten,@Tuoi,@ngaySinh,@maSoSinhVien,@lopId,@khoaId)"; var pa = new DynamicParameters(); pa.Add("@Ten", hocSinh.Ten); pa.Add("@Tuoi", hocSinh.Tuoi); pa.Add("@ngaySinh", hocSinh.ngaySinh); pa.Add("@maSoSinhVien", hocSinh.maSinhVien); pa.Add("@lopId", hocSinh.lopId); pa.Add("@khoaId", hocSinh.khoaId); CommandType c = CommandType.Text; insertId = await Data.Connection().ExecuteAsync(Query, pa, null, null, c); return(insertId); } }
public async Task <int> SuaHocSinh(HocSinh hocSinh) { using (Data.Connection()) { var updateId = 0; string Query = "UPDATE HocSinh SET Ten = @Ten, Tuoi = @Tuoi, ngaySinh = @ngaySinh, maSinhVien = @maSoSinhVien, lopId = @lopId, khoaId = @khoaId"; var pa = new DynamicParameters(); pa.Add("@Ten", hocSinh.Ten); pa.Add("@Tuoi", hocSinh.Tuoi); pa.Add("@ngaySinh", DateTime.Now); pa.Add("@maSoSinhVien", hocSinh.maSinhVien); pa.Add("@lopId", hocSinh.lopId); pa.Add("@khoaId", hocSinh.khoaId); CommandType c = CommandType.Text; updateId = await Data.Connection().ExecuteAsync(Query, pa, null, null, c); return(updateId); } }