public int Add(T t) { //Set<T>()等于Students RemoveHoldingEntityInContext(t); db.Set <T>().Add(t); return(db.SaveChanges()); }
public int Add(T t) { //Set<T>()等于Students db.Set <T>().Add(t); return(db.SaveChanges()); }
public IActionResult CreateNew(LoaiModel model) { try { var loai = new Loai { TenLoai = model.TenLoai }; _context.Add(loai); _context.SaveChanges(); return(Ok(loai)); }catch { return(BadRequest()); } }
public void AddTeacher(string FirstName, string SecondName, string LastName, int Phone, string Email) { if (!(string.IsNullOrEmpty(FirstName) && string.IsNullOrWhiteSpace(FirstName)) && !(string.IsNullOrEmpty(SecondName) && string.IsNullOrWhiteSpace(SecondName)) && !(string.IsNullOrEmpty(LastName) && string.IsNullOrWhiteSpace(LastName)) && !(string.IsNullOrEmpty(Email) && string.IsNullOrWhiteSpace(Email))) { Teacher teacher = new Teacher() { FirstName = FirstName, SecondName = SecondName, LastName = LastName, Phone = Phone, Email = Email }; using (var db = new MyDbcontext()) { db.Teachers.Add(teacher); db.SaveChanges(); } } else { throw new System.InvalidOperationException("Fields are empty"); } }
static void Main(string[] args) { var context = new MyDbcontext(); context.SubSubClasses.Add(new SubSubClass()); context.SaveChanges(); }
public void AddTeacher(Teacher ctz) { if (ctz != null) { _Teachers.Add(ctz); using (var db = new MyDbcontext()) { db.Teachers.Add(ctz); db.SaveChanges(); } } }
public void AddChair(string name, string shortname, Teacher teacher) { Chair chair = new Chair() { NameChair = name, ShortNameChair = shortname, }; using (var db = new MyDbcontext()) { db.Chairs.Add(chair); db.SaveChanges(); } }
public void AddFaculty(string NameF, string ShortNameF, Teacher tch) { Faculty fcl = new Faculty() { NameFaculty = NameF, ShortNameFaculty = ShortNameF }; using (var db = new MyDbcontext()) { db.Faculties.Add(fcl); db.SaveChanges(); } }
public void EditCitizen(string name, string secondname, string lastname, int phone, string email) { using (var db = new MyDbcontext()) { Teacher tch = new Teacher() { FirstName = name, LastName = lastname, SecondName = secondname, Phone = phone, Email = email }; var teacher = (from i in db.Teachers where i.Id == tch.Id select i).First(); teacher.FirstName = tch.FirstName; teacher.LastName = tch.LastName; teacher.SecondName = tch.SecondName; teacher.Phone = tch.Phone; teacher.Email = tch.Email; db.SaveChanges(); Debug.WriteLine("Изменение завершено"); } }
public bool Save() { return(_infocontext.SaveChanges() >= 0); }
public MainWindowVM() { _model.PropertyChanged += (sender, args) => { RaisePropertyChanged(args.PropertyName); }; FindComplexSearch = new DelegateCommand(() => { Search cs = new Search(); cs.Show(); }); RefreshTeacherTable = new DelegateCommand(() => { _model.RefreshTables(); }); AddTeacher = new DelegateCommand(() => { AddTeacherWindow atw = new AddTeacherWindow(); atw.ShowDialog(); _model.RefreshTables(); }); EditTeacher = new DelegateCommand(() => { EditTeacherWindow ecw = new EditTeacherWindow(); ecw.DataContext = SelectedTeacher; Teacher tch = SelectedTeacher; if (ecw.ShowDialog() == true) { using (var db = new MyDbcontext()) { var Teacher = (from i in db.Teachers where i.Id == tch.Id select i).First(); Teacher.FirstName = tch.FirstName; Teacher.LastName = tch.LastName; Teacher.SecondName = tch.SecondName; db.SaveChanges(); } _model.RefreshTables(); } }); DeleteTeacher = new DelegateCommand(() => { using (var db = new MyDbcontext()) { var Teacher = (from i in db.Teachers where i.Id == SelectedTeacher.Id select i).First(); db.Teachers.Remove(Teacher); db.SaveChanges(); } _model.RefreshTables(); }); AddChair = new DelegateCommand(() => { AddChairWindow apw = new AddChairWindow(); apw.DataContext = new AddChairVM(); apw.ShowDialog(); _model.RefreshTables(); }); EditChair = new DelegateCommand(() => { EditChairWindow epw = new EditChairWindow(); Chair chr = SelectedChair; epw.DataContext = chr; if (epw.ShowDialog() == true) { using (var db = new MyDbcontext()) { var Chair = (from i in db.Chairs where i.Id == chr.Id select i).First(); Chair.NameChair = chr.NameChair; Chair.ShortNameChair = chr.ShortNameChair; db.SaveChanges(); } _model.RefreshTables(); } }); DeleteChair = new DelegateCommand(() => { using (var db = new MyDbcontext()) { var Chair = (from i in db.Chairs where i.Id == SelectedChair.Id select i).First(); db.Chairs.Remove(Chair); db.SaveChanges(); } _model.RefreshTables(); }); AddFaculty = new DelegateCommand(() => { AddFacultyWindow adw = new AddFacultyWindow(); adw.DataContext = new AddFacultyVM(); adw.ShowDialog(); _model.RefreshTables(); }); EditFaculty = new DelegateCommand(() => { EditFacultyWindow edw = new EditFacultyWindow(); Faculty fcl = SelectedFaculty; edw.DataContext = fcl; if (edw.ShowDialog() == true) { using (var db = new MyDbcontext()) { var Faculty = (from i in db.Faculties where i.Id == fcl.Id select i).First(); Faculty.NameFaculty = fcl.NameFaculty; Faculty.ShortNameFaculty = fcl.ShortNameFaculty; db.SaveChanges(); } _model.RefreshTables(); } }); DeleteFaculty = new DelegateCommand(() => { using (var db = new MyDbcontext()) { var Faculty = (from i in db.Faculties where i.Id == SelectedFaculty.Id select i).First(); db.Faculties.Remove(Faculty); db.SaveChanges(); } _model.RefreshTables(); }); FindByCypher = new DelegateCommand(() => { FindByCypherWindow fbc = new FindByCypherWindow(); fbc.Show(); }); SaveToJSON = new DelegateCommand(() => { _model.SaveToJSON(Teachers, Chairs, Faculties); MessageBox.Show("Все сохранено"); }); }