/// <summary> /// Author: Phạm Huy Hùng /// Todo: tìm kiếm đối tượng theo khóa chính /// </summary> /// <param name="obj"></param> /// <returns></returns> public TblGroupRole FindById(TblGroupRole obj) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { return(db.TblGroupRoles.SingleOrDefault(x => x.Id == obj.Id)); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupRoleDao::FindById::" + ex.Message); } else { throw new Exception("TblGroupRoleDao::FindById::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: tạo đối tượng mới /// </summary> /// <param name=""></param> /// <returns></returns> public void Create(TblGroupRole o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { db.TblGroupRoles.Add(o); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupRoleDao::Create::" + ex.Message); } else { throw new Exception("TblGroupRoleDao::Create::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: xóa đối tượng /// </summary> /// <param name="o"></param> /// <returns></returns> public void Delete(TblGroupRole o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblGroupRoles.Where(x => x.Id == o.Id).SingleOrDefault(); db.TblGroupRoles.Remove(o); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupRoleDao::Delete::" + ex.Message); } else { throw new Exception("TblGroupRoleDao::Delete::" + ex.InnerException.Message); } } }