public static bool DeleteLOW(int no) { try { using (var _context = new LabMangementEntities()) { var dblow = (from t in _context.ListOfWorks where t.no == no select t).SingleOrDefault(); foreach (var low in dblow.Projects) { foreach (var t in low.ListOfWorks) { if (t.no == no) { low.ListOfWorks.Remove(t); break; } } } _context.ListOfWorks.Remove(dblow); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool DeletePro(Project pro) { try { using (var _context = new LabMangementEntities()) { //Xoa danh sach cong viec var dbpro = (from u in _context.Projects where u.procode == pro.procode select u).SingleOrDefault(); foreach (var work in dbpro.Works) { foreach (var u in work.Projects) { if (u.procode == pro.procode) { work.Projects.Remove(u); break; } } } _context.Projects.Remove(dbpro); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static int getNofromDB() { using (var _context = new LabMangementEntities()) { var no = (from t in _context.ListOfWorks select t.no).ToList(); if (no.Count <= 0) { return(1); } else { int nos = 1; while (true) { if (no.Contains(nos)) { nos++; } else { return(nos); } } } } }
public static int getIDfromDB() { using (var _context = new LabMangementEntities()) { var id = (from t in _context.Works select t.ID).ToList(); if (id.Count <= 0) { return(1); } else { int ids = 1; while (true) { if (id.Contains(ids)) { ids++; } else { return(ids); } } } } }
public static bool AddWork(Work works) { using (var _context = new LabMangementEntities()) { foreach (var mem in works.Members) { var memdb = (from u in _context.Members where u.memcode == mem.memcode select u).Single(); memdb.Works.Add(works); } works.Members.Clear(); foreach (var pro in works.Projects) { var prodb = (from p in _context.Projects where p.procode == pro.procode select p).Single(); prodb.Works.Add(works); } works.Projects.Clear(); _context.Works.AddOrUpdate(works); _context.SaveChanges(); return(true); } }
public static bool DeleteWork(int id) { try { using (var _context = new LabMangementEntities()) { var dbwork = (from t in _context.Works where t.ID == id select t).SingleOrDefault(); foreach (var mem in dbwork.Members) { foreach (var t in mem.Works) { if (t.ID == id) { mem.Works.Remove(t); break; } } } _context.Works.Remove(dbwork); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool DeleteMem(Member mem) { try { using (var _context = new LabMangementEntities()) { //Xoa danh sach cong viec var dbmem = (from u in _context.Members where u.memcode == mem.memcode select u).SingleOrDefault(); foreach (var work in dbmem.Works) { foreach (var u in work.Members) { if (u.memcode == mem.memcode) { work.Members.Remove(u); break; } } } _context.Members.Remove(dbmem); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool UpdatePro(Project pro) { try { using (var _context = new LabMangementEntities()) { _context.Projects.AddOrUpdate(pro); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool UpdateMem(Member mem) { try { using (var _context = new LabMangementEntities()) { _context.Members.AddOrUpdate(mem); _context.SaveChanges(); return(true); } } catch { return(false); } }
public static bool AddLOW(ListOfWork lows) { using (var _context = new LabMangementEntities()) { foreach (var pro in lows.Projects) { var prodb = (from u in _context.Projects where u.procode == pro.procode select u).Single(); prodb.ListOfWorks.Add(lows); } lows.Projects.Clear(); _context.ListOfWorks.AddOrUpdate(lows); _context.SaveChanges(); return(true); } }
public static List <Project> getlistPros() { using (var _context = new LabMangementEntities()) { var pro = (from u in _context.Projects.AsEnumerable() select u).Select(x => new Project { procode = x.procode, proname = x.proname, description = x.description, fromdate = x.fromdate, todate = x.todate, }).ToList(); return(pro); } }
public static Project getPro(string procode) { using (var _context = new LabMangementEntities()) { var pro = (from u in _context.Projects where u.procode == procode select u).ToList(); if (pro.Count == 1) { return(pro[0]); } else { return(null); } } }
public static Member getMem(string memcode) { using (var _context = new LabMangementEntities()) { var mem = (from u in _context.Members where u.memcode == memcode select u).ToList(); if (mem.Count == 1) { return(mem[0]); } else { return(null); } } }
public static List <Member> getlistMems() { using (var _context = new LabMangementEntities()) { var mem = (from u in _context.Members.AsEnumerable() select u).Select(x => new Member { memcode = x.memcode, memname = x.memname, gender = x.gender, birthday = x.birthday, address = x.address, phonenum = x.phonenum, email = x.email }).ToList(); return(mem); } }
public static List <ListOfWork> getAllLOWs() { using (var _context = new LabMangementEntities()) { var lows = (from t in _context.ListOfWorks.AsEnumerable() select new { no = t.no, job = t.job, status = t.status, Projects = t.Projects }) .Select(x => new ListOfWork { no = x.no, job = x.job, status = x.status, Projects = x.Projects, }); return(lows.ToList()); } }
public static List <Work> getAllWorks() { using (var _context = new LabMangementEntities()) { var works = (from t in _context.Works.AsEnumerable() select new { ID = t.ID, workingtime = t.workingtime, salary = t.salary, Members = t.Members, Projects = t.Projects }) .Select(x => new Work { ID = x.ID, workingtime = x.workingtime, salary = x.salary, Members = x.Members, Projects = x.Projects, }); return(works.ToList()); } }