public async Task <IActionResult> Post([FromBody] KhoiDTO model) { using (var context = new UserProfileDbContext()) { context.Khois.Add(new Khoi { Id = model.Id, TenKhoi = model.TenKhoi }); //context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[UserProfiles] ON"); return(Ok(await context.SaveChangesAsync())); } }
public static bool SuaKhoi(KhoiDTO khoiDTO) { string sQuery = string.Format(@"UPDATE Khoi SET TenKhoi=N'{0}', GhiChu=N'{1}' WHERE MaKhoi={2}", khoiDTO.STenKhoi, khoiDTO.SGhiChu, khoiDTO.IMaKhoi); con = DataProvider.Connect(); DataTable dt = DataProvider.LayDataTable(sQuery, con); try { DataProvider.ExecuteQueriesNonQuery(sQuery, con); DataProvider.CloseConnect(con); return(true); } catch (Exception ex) { DataProvider.CloseConnect(con); return(false); } }
public static bool XoaKhoi(KhoiDTO khoiDTO) { string sQuery = string.Format(@"DELETE Khoi WHERE MaKhoi={0}", khoiDTO.IMaKhoi); con = DataProvider.Connect(); DataTable dt = DataProvider.LayDataTable(sQuery, con); try { DataProvider.ExecuteQueriesNonQuery(sQuery, con); DataProvider.CloseConnect(con); return(true); } catch (Exception ex) { DataProvider.CloseConnect(con); return(false); } }
public static bool ThemKhoi(KhoiDTO khoiDTO) { string sQuery = string.Format(@"INSERT INTO Khoi VALUES (N'{0}', N'{1}')", khoiDTO.STenKhoi, khoiDTO.SGhiChu); con = DataProvider.Connect(); DataTable dt = DataProvider.LayDataTable(sQuery, con); try { DataProvider.ExecuteQueriesNonQuery(sQuery, con); DataProvider.CloseConnect(con); return(true); } catch (Exception ex) { DataProvider.CloseConnect(con); return(false); } }
public async Task <IActionResult> Put(int id, [FromBody] KhoiDTO model) { using (var context = new UserProfileDbContext()) { var user = await context.Khois.FirstOrDefaultAsync(x => x.Id.Equals(id)); if (user == null) { return(NotFound()); } user.Id = model.Id; user.TenKhoi = model.TenKhoi; return(Ok(await context.SaveChangesAsync())); } }
public static List <KhoiDTO> LoadcbKhoi() { string sQuery = string.Format("SELECT * FROM Khoi"); con = DataProvider.Connect(); DataTable dt = DataProvider.LayDataTable(sQuery, con); List <KhoiDTO> lstk = new List <KhoiDTO>(); for (int i = 0; i < dt.Rows.Count; i++) { KhoiDTO khoiDTO = new KhoiDTO(); khoiDTO.IMaKhoi = int.Parse(dt.Rows[i]["MaKhoi"].ToString()); khoiDTO.STenKhoi = dt.Rows[i]["TenKhoi"].ToString(); //khoiDTO.SGhiChu = dt.Rows[i]["GhiChu"].ToString(); lstk.Add(khoiDTO); } DataProvider.CloseConnect(con); return(lstk); }
private void btnXoa_Click(object sender, EventArgs e) { if (txtMakhoi.Text == "") { MessageBox.Show("Bạn phải chọn khối cần xóa."); return; } KhoiDTO khoiDTO = new KhoiDTO(); khoiDTO.IMaKhoi = int.Parse(txtMakhoi.Text); if (KhoiBLL.XoaKhoi(khoiDTO)) { MessageBox.Show("Xóa thành công."); LoadKhoi(); return; } else { MessageBox.Show("Xóa thất bại."); } }
private void btnThem_Click(object sender, EventArgs e) { if (txtTenkhoi.Text == "") { MessageBox.Show("Bạn phải nhập vào khối học"); return; } KhoiDTO khoiDTO = new KhoiDTO(); khoiDTO.STenKhoi = txtTenkhoi.Text; khoiDTO.SGhiChu = txtGhichu.Text; if (KhoiBLL.ThemKhoi(khoiDTO)) { MessageBox.Show("Thêm thành công."); LoadKhoi(); return; } else { MessageBox.Show("Thêm thất bại."); } }
private void btnSua_Click(object sender, EventArgs e) { if (txtMakhoi.Text == "") { MessageBox.Show("Bạn phải chọn khối cần Sửa."); return; } KhoiDTO khoiDTO = new KhoiDTO(); khoiDTO.IMaKhoi = int.Parse(txtMakhoi.Text); khoiDTO.STenKhoi = txtTenkhoi.Text; khoiDTO.SGhiChu = txtGhichu.Text; if (KhoiBLL.SuaKhoi(khoiDTO)) { MessageBox.Show("Sửa thành công."); LoadKhoi(); return; } else { MessageBox.Show("Sửa thất bại."); } }
public static List <KhoiDTO> LoadKhoi() { string sQuery = @"SELECT * FROM Khoi "; con = DataProvider.Connect(); DataTable dt = DataProvider.LayDataTable(sQuery, con); if (dt.Rows.Count == 0) { return(null); } List <KhoiDTO> lstk = new List <KhoiDTO>(); for (int i = 0; i < dt.Rows.Count; i++) { KhoiDTO k = new KhoiDTO(); k.IMaKhoi = int.Parse(dt.Rows[i]["MaKhoi"].ToString()); k.STenKhoi = dt.Rows[i]["TenKhoi"].ToString(); k.SGhiChu = dt.Rows[i]["GhiChu"].ToString(); lstk.Add(k); } DataProvider.CloseConnect(con); return(lstk); }
public static bool SuaKhoi(KhoiDTO khoiDTO) { return(KhoiProvider.SuaKhoi(khoiDTO)); }
public static bool ThemKhoi(KhoiDTO khoiDTO) { return(KhoiProvider.ThemKhoi(khoiDTO)); }