Ejemplo n.º 1
0
        public ModifyDoctorResponse ModifyDoctor(int id, ModifyDoctorRequest request)
        {
            var d = _context.Doctor.Where(x => x.IdDoctor == id).FirstOrDefault();

            if (d == null)
            {
                return(null);
            }
            else
            {
                d.FirstName = request.FirstName;
                d.LastName  = request.LastName;
                d.Email     = request.Email;
                _context.SaveChanges();

                ModifyDoctorResponse response = new ModifyDoctorResponse
                {
                    IdDoctor  = d.IdDoctor,
                    FirstName = d.FirstName,
                    LastName  = d.LastName,
                    Email     = d.Email
                };

                return(response);
            }
        }
Ejemplo n.º 2
0
        public ModifyDoctorResponse ModifyDoctor(ModifyDoctorRequest doctorRequest)
        {
            var doctor = _context.Doctor
                         .FirstOrDefault(d => d.IdDoctor == Int32.Parse(doctorRequest.IdDoctor));

            var response = new ModifyDoctorResponse();

            response.IdDoctor = doctorRequest.IdDoctor;

            if (!string.IsNullOrEmpty(doctorRequest.FirstName))
            {
                doctor.FirstName = doctorRequest.FirstName;
                _context.SaveChanges();
                response.FirstName = doctor.FirstName;
            }

            if (!string.IsNullOrEmpty(doctorRequest.LastName))
            {
                doctor.LastName = doctorRequest.LastName;
                _context.SaveChanges();
                response.LastName = doctor.LastName;
            }

            if (!string.IsNullOrEmpty(doctorRequest.Email))
            {
                doctor.Email = doctorRequest.Email;
                _context.SaveChanges();
                response.Email = doctor.Email;
            }

            return(response);
        }
Ejemplo n.º 3
0
        public ModifyDoctorResponse ModifyDoctor(ModifyDoctorRequest request)
        {
            var response = new ModifyDoctorResponse();

            using (var doctorDbContext = new DoctorDbContext())
            {
                var entity = doctorDbContext.Doctors.FirstOrDefault(item => item.IdDoctor == request.doctor.IdDoctor);
                if (entity != null)
                {
                    entity.FirstName = request.doctor.FirstName;
                    entity.LastName  = request.doctor.LastName;
                    entity.Email     = request.doctor.Email;

                    try
                    {
                        doctorDbContext.SaveChanges();
                        response.message = "UPDATE SUCCESSFULL";
                    }
                    catch (Exception)
                    {
                        response.message = "UPDATE FAILED";
                    }
                }
                else
                {
                    response.message = "There is no doctor with this index!";
                }
            }
            return(response);
        }
Ejemplo n.º 4
0
        public IActionResult ModifyDoctor(ModifyDoctorRequest doctorRequest)
        {
            var errors = ValidationHelper.ValidateModifyDoctorRequest(doctorRequest);

            if (errors.Count > 0)
            {
                return(StatusCode(400, errors));
            }

            bool exists = _doctorDbService.DoctorExists(Convert.ToInt32(doctorRequest.IdDoctor));

            if (exists)
            {
                ModifyDoctorResponse response = _doctorDbService.ModifyDoctor(doctorRequest);
                return(StatusCode(201, response));
            }
            return(StatusCode(404, "No doctor with id " + doctorRequest.IdDoctor));
        }
Ejemplo n.º 5
0
        public ModifyDoctorResponse ModifyDoctor(int index, ModifyDoctorRequest request)
        {
            var doctor = _context.Doctor.Find(index);

            if (doctor == null)
            {
                return(null);
            }
            else
            {
                doctor.FirstName = request.FirstName;
                doctor.LastName  = request.LastName;
                doctor.Email     = request.Email;
                _context.SaveChanges();

                ModifyDoctorResponse response = new ModifyDoctorResponse();
                response.IdDoctor  = doctor.IdDoctor;
                response.FirstName = doctor.FirstName;
                response.LastName  = doctor.LastName;
                response.Email     = doctor.Email;
                return(response);
            }
        }