public void Xoa(ChuyenMonEntity tk) { KetNoiCSDL.MoKetNoi(); string sql = @"DELETE tblChuyenMon WHERE MaChuyenMon=@MaNN"; SqlCommand cdm = new SqlCommand(sql, KetNoiCSDL.connect); cdm.Parameters.AddWithValue("@MaNN", tk.MaChuyenMon); cdm.ExecuteNonQuery(); KetNoiCSDL.DongKetNoi(); }
public bool Delete(ChuyenMonEntity _ChuyenMon) { try { this.m_UnitOfWork.ChuyenMonRepository.Delete(_ChuyenMon); return true; } catch (Exception e) { System.Console.WriteLine(e.ToString()); return false; } }
public void Sua(ChuyenMonEntity tk) { KetNoiCSDL.MoKetNoi(); string themhd = @"UPDATE tblChuyenMon SET TenChuyenMon=@TenNN Where MaChuyenMon=@MaNN"; SqlCommand cdm = new SqlCommand(themhd, KetNoiCSDL.connect); // cdm.CommandType = CommandType.StoredProcedure; cdm.Parameters.AddWithValue("@MaNN", tk.MaChuyenMon); cdm.Parameters.AddWithValue("@TenNN", tk.TenChuyenMon); cdm.ExecuteNonQuery(); KetNoiCSDL.DongKetNoi(); }
public void Them(ChuyenMonEntity tk) { KetNoiCSDL.MoKetNoi(); string themhd = @"INSERT INTO tblChuyenMon(MaChuyenMon,TenChuyenMon) VALUES(@MaNN,@TenNN)"; SqlCommand cdm = new SqlCommand(themhd, KetNoiCSDL.connect); // cdm.CommandType = CommandType.StoredProcedure; cdm.Parameters.AddWithValue("@MaNN", tk.MaChuyenMon); cdm.Parameters.AddWithValue("@TenNN", tk.TenChuyenMon); cdm.ExecuteNonQuery(); KetNoiCSDL.DongKetNoi(); }
/// only return json to client public ActionResult Create(ChuyenMonEntity chuyenmon) { ChuyenMonService service = new ChuyenMonService(); if (chuyenmon == null) { RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"); return Json(JsonConvert.SerializeObject(ViewData)); } if (service.Create(chuyenmon)) { return Json(RenderResult.RequestCompleted(ViewData, "Thêm chuyên môn thành công")); } else { return Json(RenderResult.RequestCompleted(ViewData, "Lỗi khi thêm chuyên môn")); } }
public bool Update(ChuyenMonEntity _ChuyenMon) { try { var ChuyenMon = m_UnitOfWork.ChuyenMonRepository.GetByID(_ChuyenMon.Id); if (ChuyenMon != null) { ChuyenMon.MaQuyDinh = _ChuyenMon.MaQuyDinh; ChuyenMon.TenChuyenMon = _ChuyenMon.TenChuyenMon; m_UnitOfWork.Save(); } return true; } catch(Exception e) { System.Console.WriteLine(e.ToString()); return false; } }
public bool Create(ChuyenMonEntity _ChuyenMon) { try { var ChuyenMon = new ChuyenMons { Id = _ChuyenMon.Id, MaQuyDinh = _ChuyenMon.MaQuyDinh, TenChuyenMon = _ChuyenMon.TenChuyenMon }; m_UnitOfWork.ChuyenMonRepository.Insert(ChuyenMon); m_UnitOfWork.Save(); return true; } catch(Exception e) { System.Console.WriteLine(e.ToString()); return false; } }
public ActionResult Edit(ChuyenMonEntity chuyenmon) { ChuyenMonService service = new ChuyenMonService(); if (chuyenmon == null) { return Json(RenderResult.RequestError(ViewData, "Lỗi đối số không hợp lệ"), JsonRequestBehavior.AllowGet); } try { if (service.Update(chuyenmon)) return Json(RenderResult.RequestCompleted(ViewData, "Chỉnh sửa thành công")); return Json(RenderResult.RequestCompleted(ViewData, "Chỉnh sửa không thành công")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(RenderResult.RequestError(ViewData, "Lỗi xảy ra")); } }
public List<ChuyenMonEntity> GetAll() { IEnumerable<ChuyenMons> model = this.m_UnitOfWork.ChuyenMonRepository.GetAll(); List<ChuyenMonEntity> result = new List<ChuyenMonEntity>(); foreach (var item in model) { ChuyenMonEntity chuyenmon = new ChuyenMonEntity { Id = item.Id, MaQuyDinh = item.MaQuyDinh, TenChuyenMon = item.TenChuyenMon }; result.Add(chuyenmon); } return result; }
public ActionResult Delete(ChuyenMonEntity chuyenmon) { ChuyenMonService service = new ChuyenMonService(); try { if (service.Delete(chuyenmon)) return Json(RenderResult.RequestCompleted(ViewData, "Xóa thành công")); return Json(RenderResult.RequestCompleted(ViewData, "Xóa không thành công")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); return Json(RenderResult.RequestError(ViewData, "Lỗi xảy ra")); } }