public HelperRequest DeleteDoctor(DeleteDoctorRequest request) { var helper = new HelperRequest(); var countDoctor = _context.Doctors.Count(doc => doc.LastName == request.LastName && doc.FirstName == request.FirstName); if (countDoctor == 0) { helper.Number = 0; return(helper); } var selectDoctorId = _context.Doctors.Where(doc => doc.LastName == request.LastName && doc.FirstName == request.FirstName).Select(x => x.IdDoctor).ToArray(); var doctor = new Doctor { IdDoctor = selectDoctorId[0] }; _context.Attach(doctor); _context.Remove(doctor); _context.SaveChangesAsync(); helper.Number = 1; return(helper); }
public int RemoveDoctor(int id) { var doctor = GetDoctor(id); if (doctor == null) { return(0); } _context.Remove(doctor); return(_context.SaveChanges()); }
public void DeleteDoctor(int id) { var doctor = new Doctor { IdDoctor = id }; db.Attach(doctor); db.Remove(doctor); db.SaveChanges(); }
public IActionResult DeleteDoctor(int id) { var d = new Doctor { IdDoctor = id }; context.Attach(d); context.Remove(d); context.SaveChanges(); return(Ok($"Doctor {id} usunięty pomyślnie")); }
public RemoveDoctorResponse RemoveDoctor(RemoveDoctorRequest request) { var doctor = _context.Doctors.FirstOrDefault(x => x.IdDoctor == request.IdDoctor); _context.Remove(doctor); _context.SaveChanges(); return(new RemoveDoctorResponse { IdDoctor = doctor.IdDoctor, FirstName = doctor.FirstName, LastName = doctor.LastName }); }
public Doctor DeleteDoctor(int id) { var doctor = _context.Doctor.FirstOrDefault(e => e.IdDoctor == id); if (doctor == null) { throw new Exception("Nie ma takiego doktora"); } _context.Remove(doctor); _context.SaveChanges(); return(doctor); }