コード例 #1
0
        public IActionResult updateDoctor(int id, CreateDoctorDtoRequest doctor)
        {
            if (!_db.Doctors.Any(d => d.IdDoctor == id))
            {
                return(NotFound("Doktor o podanym numerze id nie istnieje."));
            }

            if (string.IsNullOrEmpty(doctor.FirstName) || string.IsNullOrEmpty(doctor.LastName) || string.IsNullOrEmpty(doctor.Email))
            {
                return(BadRequest("Jedna z przekazanych wartości jest pusta."));
            }

            Doctor d = new Doctor
            {
                IdDoctor  = id,
                FirstName = doctor.FirstName,
                LastName  = doctor.LastName,
                Email     = doctor.Email
            };

            _db.Attach(d);
            _db.Entry(d).Property("FirstName").IsModified = true;
            _db.Entry(d).Property("LastName").IsModified  = true;
            _db.Entry(d).Property("Email").IsModified     = true;
            _db.SaveChanges();

            return(Ok());
        }
コード例 #2
0
        public IActionResult addDoctor(CreateDoctorDtoRequest doctor)
        {
            if (string.IsNullOrEmpty(doctor.FirstName) || string.IsNullOrEmpty(doctor.LastName) || string.IsNullOrEmpty(doctor.Email))
            {
                return(BadRequest("Jedna z przekazanych wartości jest pusta."));
            }

            Doctor d = new Doctor
            {
                FirstName = doctor.FirstName,
                LastName  = doctor.LastName,
                Email     = doctor.Email
            };

            _db.Add(d);
            _db.SaveChanges();

            return(Ok(d));
        }