public bool Save(object dataBoundItem) { if (dataBoundItem is ThietBi acc) { var db = new dbQLTSEntities(); if (acc.IDThietBi == 0) { acc.Status = false; acc.Bad = 0; acc.CanUse = acc.Total ?? 0; db.ThietBis.Add(acc); } else { if (db.ThietBis.ToList().FirstOrDefault(q => q.IDThietBi == acc.IDThietBi) is ThietBi x) { db.Entry(x).CurrentValues.SetValues(acc); } else { return(false); } } return(db.SaveChanges() > 0); } return(false); }
public bool Save(object dataBoundItem) { if (dataBoundItem is Account acc) { var db = new dbQLTSEntities(); if (acc.IDAccount == 0) { acc.Status = false; acc.Password = "******"; db.Accounts.Add(acc); } else { if (db.Accounts.ToList().FirstOrDefault(q => q.IDAccount == acc.IDAccount) is Account x) { db.Entry(x).CurrentValues.SetValues(acc); } else { return(false); } } return(db.SaveChanges() > 0); } return(false); }
public bool Save(object dataBoundItem) { if (dataBoundItem is Position acc) { var db = new dbQLTSEntities(); if (acc.IDPosition == 0) { acc.IsDelete = false; db.Positions.Add(acc); } else { if (db.Positions.ToList().FirstOrDefault(q => q.IDPosition == acc.IDPosition) is Position x) { db.Entry(x).CurrentValues.SetValues(acc); } else { throw new Exception("Đối tượng không tồn tại"); } } return(db.SaveChanges() > 0); } return(false); }
public bool Delete(object dataBoundItem) { if (dataBoundItem is ThietBi acc) { var db = new dbQLTSEntities(); acc.Status = true; if (db.ThietBis.ToList().FirstOrDefault(q => q.IDThietBi == acc.IDThietBi) is ThietBi x) { db.Entry(x).CurrentValues.SetValues(acc); } else { return(false); } return(db.SaveChanges() > 0); } return(false); }
public bool Delete(object dataBoundItem) { if (dataBoundItem is Position acc) { var db = new dbQLTSEntities(); acc.IsDelete = true; if (db.Positions.ToList().FirstOrDefault(q => q.IDPosition == acc.IDPosition) is Position x) { db.Entry(x).CurrentValues.SetValues(acc); } else { return(false); } return(db.SaveChanges() > 0); } return(false); }
public bool Save(object dataBoundItem) { if (dataBoundItem is CTMuonTB ct) { var db = new dbQLTSEntities(); if (ct.IDCTMuon == 0) { if (muonTB.Status == false) { ct.Bad = 0; ct.IDMuonTB = muonTB.IDMuonTB; db.CTMuonTBs.Add(ct); } else { throw new Exception("Không thể thêm thiết bị cho phiếu mượn đẵ trả."); } } else { if (db.CTMuonTBs.ToList().FirstOrDefault(q => q.IDCTMuon == ct.IDCTMuon) is CTMuonTB obj) { if (db.ThietBis.ToList().FirstOrDefault(q => q.IDThietBi == ct.IDThietBi) is ThietBi tb) { var bad = ct.Bad - obj.Bad; tb.Bad += bad; tb.CanUse -= bad; } else { throw new Exception("Phiếu mượn không tồn tại, vui lòng reload"); } db.Entry(obj).CurrentValues.SetValues(ct); } else { throw new Exception("Chi tiết không tồn tại, vui lòng reload"); } } return(db.SaveChanges() > 0); } return(false); }