public DoctorResponse AddDoctor(AddDoctorRequest request) { var response = new DoctorResponse(); var doctor = _dbContext.Doctors.Add(new Doctor() { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }) .Entity; if (doctor != null) { _dbContext.SaveChanges(); response.IdDoctor = doctor.IdDoctor; response.FirstName = doctor.FirstName; response.LastName = doctor.LastName; response.Email = doctor.Email; } else { _dbContext.Remove(doctor); } return(response); }
public void DeleteDoctor(int dr) { var rem = _dbc.Doctors.Where(e => e.IdDoctor == dr).First(); _dbc.Remove(rem); _dbc.SaveChanges(); }
public IActionResult DeleteDoctor(int idDoctor) { var doctor = new Doctor { IdDoctor = idDoctor }; _context.Attach(doctor); _context.Remove(doctor); _context.SaveChanges(); return(Ok()); }
public async Task <IActionResult> DeleteDoctor(int id) { var doctor = _context.Doctor.FirstOrDefault(s => s.IdDoctor == id); if (doctor == null) { return(new BadRequestResult()); } _context.Attach(doctor); _context.Remove(doctor); await _context.SaveChangesAsync(); return(new OkObjectResult(doctor)); }
public bool DeleteDoctor(DeleteDoctorRequest request) { _context = new DoctorsDbContext(); Doctor doctor; try { doctor = _context.Doctors.First(d => d.IdDoctor == Convert.ToInt32(request.IdDoctor)); } catch { return(false); } _context.Remove(doctor); _context.SaveChanges(); return(true); }
public IActionResult removeDoctor(int id) { if (!_db.Doctors.Any(d => d.IdDoctor == id)) { return(NotFound("Doktor o podanym numerze id nie istnieje.")); } var doctor = new Doctor { IdDoctor = id }; _db.Attach(doctor); _db.Remove(doctor); _db.SaveChanges(); return(Ok()); }