Beispiel #1
0
        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);
        }
Beispiel #2
0
        public int RemoveDoctor(int id)
        {
            var doctor = GetDoctor(id);

            if (doctor == null)
            {
                return(0);
            }
            _context.Remove(doctor);
            return(_context.SaveChanges());
        }
Beispiel #3
0
        public void DeleteDoctor(int id)
        {
            var doctor = new Doctor
            {
                IdDoctor = id
            };

            db.Attach(doctor);
            db.Remove(doctor);
            db.SaveChanges();
        }
Beispiel #4
0
        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"));
        }
Beispiel #5
0
        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
            });
        }
Beispiel #6
0
        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);
        }