public IActionResult Update(TeacherUpdate teacherUpdate) { if (teacherUpdate == null) { return(RedirectToActionPermanent("Index")); } if (!ModelState.IsValid) { return(View("Update", teacherUpdate)); } using (var db = new SchoolContext()) { var teacher = db.Teachers.SingleOrDefault(t => t.Id == teacherUpdate.Id); if (teacher == null) { return(RedirectToActionPermanent("Index")); } teacher.Firstname = teacherUpdate.Firstname; teacher.Lastname = teacherUpdate.Lastname; db.Teachers.Update(teacher); db.SaveChanges(); return(RedirectToActionPermanent("Index")); } }
public EditTeacherSubject(TeacherUpdate parent, bool create) { InitializeComponent(); db = parent.db; this.parent = parent; this.create = create; comboBox1.Items.Add("Выберите предмет"); if (create) { foreach (var subject in db.Subjects.ToList()) { if (!parent.teacherSubjects.Contains(subject.Name)) { comboBox1.Items.Add(subject.Name); } } } else { foreach (var subject in db.Subjects.ToList()) { if (parent.teacherSubjects.Contains(subject.Name)) { comboBox1.Items.Add(subject.Name); } } } comboBox1.SelectedIndex = 0; button1.Enabled = false; }
public async Task <IActionResult> TeacherUpdate(TeacherUpdate teacher) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (var item in teacher.phones) { if (item == null || String.IsNullOrEmpty(item.phone)) { return(BadRequest(new { errorText = "Empty phone field!" })); } } await _context.Database.ExecuteSqlInterpolatedAsync($"UPDATE Teachers SET name = {teacher.name}, surname={teacher.surname}, lastname={teacher.lastname} WHERE Teachers.id_teacher = {teacher.id_teacher}"); await _context.Database.ExecuteSqlInterpolatedAsync($"DELETE FROM Teacher_phones WHERE Teacher_phones.id_teacher = {teacher.id_teacher}"); foreach (Models.IO_Objects.Teacher.PhonesIn phone in teacher.phones) { await _context.Database.ExecuteSqlInterpolatedAsync($"INSERT INTO Teacher_phones VALUES ({phone.phone}, {teacher.id_teacher});"); } //await _context.Database.ExecuteSqlInterpolatedAsync($"INSERT INTO Teachers VALUES ({null}, {teacher.name}, {teacher.surname}, {teacher.lastname}, {teacher.email}, {DateTime.Now}, {0}, {PasswordManager.PasswordSaveHashing(teacher.Password_temp, salt)} , {saltStr});"); return(Ok()); }
public IHttpActionResult UpdateTeacher([FromBody] TeacherUpdate teacher) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_teacherService.UpdateTeacher(teacher) is null) { return(BadRequest($"ID #{teacher.TeacherId} does not exist in the database.")); } return(Ok($"Teacher #{teacher.TeacherId} was successfully updated")); }
public Teacher UpdateTeacher(TeacherUpdate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Teachers .SingleOrDefault(e => e.TeacherId == model.TeacherId); if (entity != null) { entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.CourseId = model.CourseId; ctx.SaveChanges(); return(entity); } return(null); } }