//updates a doctor (doctor myaccount)
        public async Task <ActionResult> UpdateMedic(UpdateDoctorDTO doctorDTO)
        {
            //get the currently logged in user
            var useremail = User.FindFirst(ClaimTypes.Email)?.Value;
            var user      = await _context.USERS.Where(p => p.email == useremail).FirstAsync();

            //CHECK IF THE USER IS A doctor
            if (user.isMedic == 1)
            {
                //upload photo

                string uniqueFileName = UploadedFile(doctorDTO);


                user.firstName   = doctorDTO.firstName;
                user.lastName    = doctorDTO.lastName;
                user.phoneNumber = doctorDTO.phoneNumber;
                user.email       = doctorDTO.email.ToLower();
                user.description = doctorDTO.description;
                if (doctorDTO.photo != null)
                {
                    user.photo = uniqueFileName;
                }

                _context.USERS.Update(user);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(Unauthorized());
            }
        }
Example #2
0
        public UpdateDoctorDTO UpdateDoctor(int id, [FromBody] UpdateDoctorDTO doctor)
        {
            Doctor doctorEntity = _repository.GetDoctorById(id);

            doctor.Id = doctorEntity.Id;
            _mapper.Map(doctor, doctorEntity);
            _repository.UpdateDoctor(doctorEntity);
            _repository.Save();
            return(doctor);
        }
Example #3
0
        public IActionResult UpdateDoctor(UpdateDoctorDTO updateDoctor)
        {
            var response = _context.UpdateDoctor(updateDoctor);

            if (response == null)
            {
                return(NotFound("Doctor with id " + updateDoctor.IdDoctor + " not found!"));
            }

            return(Ok(response));
        }
        private string UploadedFile(UpdateDoctorDTO doctorDTO)
        {
            string uniqueFileName = null;

            if (doctorDTO.photo != null)
            {  //the path to the iamge folder (if the folder is after webroot)
                string uploadFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                //random unique random+ uploaded filename for the filename stored in the app
                uniqueFileName = Guid.NewGuid().ToString() + "_" + doctorDTO.photo.FileName;
                //filePath -the path to the folder where the photo is saved + the filename
                string filePath = Path.Combine(uploadFolder, uniqueFileName);
                //copy the content of the sent file in the filepath
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    doctorDTO.photo.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
Example #5
0
        public IActionResult UpdateDoctor(int id, [FromBody] UpdateDoctorDTO doctor)
        {
            var updatedDoctor = _doctorService.UpdateDoctor(id, doctor);

            return(Ok(updatedDoctor));
        }