public Result <bool> insert_mon(Mon_ett mon) { Result <bool> rs = new Result <bool>(); try { // create new tbl_khoa to insert to datacontext tbl_mon temp = new tbl_mon(); temp.mamon = mon.mamon; temp.tenmon = mon.tenmon; // remember : linq insert data db.tbl_mons.InsertOnSubmit(temp); // remember : all manipulations such as insert, update, delete have to use this command db.SubmitChanges(); rs.data = true; rs.errorCode = ErrorCode.Sucess; return(rs); } catch (Exception e) { rs.data = false; rs.errorCode = ErrorCode.False; rs.errorInfor = e.ToString(); return(rs); } }
public Result <List <Mon_ett> > select_by_fields(string nameInput, string how_to_search) { Result <List <Mon_ett> > rs = new Result <List <Mon_ett> >(); try { IQueryable <tbl_mon> dt = null; List <Mon_ett> lst = new List <Mon_ett>(); switch (how_to_search) { case "mamon": dt = db.tbl_mons.Where(o => o.mamon.Contains(nameInput)); break; case "tenmon": dt = db.tbl_mons.Where(o => o.tenmon.Contains(nameInput)); break; default: break; } if (dt.Count() > 0) { foreach (tbl_mon item in dt) { Mon_ett temp = new Mon_ett(item); lst.Add(temp); } rs.errorCode = ErrorCode.Sucess; rs.data = lst; } else { rs.errorCode = ErrorCode.NaN; rs.data = null; } return(rs); } catch (Exception e) { rs.data = null; rs.errorCode = ErrorCode.False; rs.errorInfor = e.ToString(); return(rs); } }
// handle manipulations public Result <List <Mon_ett> > select_all_mon() { Result <List <Mon_ett> > rs = new Result <List <Mon_ett> >(); try { List <Mon_ett> lst = new List <Mon_ett>(); // remember : linq select all table "tbl_mon" var dt = db.tbl_mons; if (dt.Count() > 0) { foreach (tbl_mon item in dt) { Mon_ett temp = new Mon_ett(item); lst.Add(temp); } rs.data = lst; rs.errorCode = ErrorCode.Sucess; } else { rs.data = null; rs.errorCode = ErrorCode.NaN; rs.errorInfor = Constants.empty_data; } return(rs); } catch (Exception ex) { rs.data = null; rs.errorInfor = ex.ToString(); rs.errorCode = ErrorCode.False; return(rs); } }