Exemplo n.º 1
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new NotFoundViewResult("DoctorNotFound"));
            }

            var doctor = await _doctorRepository.GetByIdAsync(id.Value);

            if (doctor == null)
            {
                return(new NotFoundViewResult("DoctorNotFound"));
            }

            try
            {
                await _doctorRepository.DeleteAsync(doctor);
            }
            catch (Exception exception)
            {
                ModelState.AddModelError(string.Empty, exception.Message);
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
0
        public async Task DoctorRepository_AddDoctorEntity_AddsDoctorEntityAsyncAndDeletesIt()
        {
            var newDoc = new Doctor()
            {
                FirstName   = "Karol",
                LastName    = "Wielki",
                Professions = { "Chirurg", "Internista" }
            };
            var returnedDoc = await _doctorsRepo.InsertAsync(newDoc);

            Assert.False(String.IsNullOrWhiteSpace(returnedDoc._id));
            var docFromDb = await _doctorsRepo.GetByIdAsync(returnedDoc._id);

            Assert.True(returnedDoc._rev == docFromDb._rev && returnedDoc.FirstName == docFromDb.FirstName);
            await _doctorsRepo.DeleteAsync(returnedDoc);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Delete(string id)
        {
            var user = await _userRepository.GetUserByIdAsync(id);

            if (user == null)
            {
                return(StatusCode(404, "User Not Found"));
            }

            var role = await _userRepository.GetUserRoleAsync(user);

            if (role == null)
            {
                return(StatusCode(404, "User Not Found"));
            }

            switch (role)
            {
            case "Admin":
                await _userRepository.DeleteUserAsync(user);

                break;

            case "Doctor":
                var doctor = await _doctorRepository.GetDoctorByUserEmail(user.Email);

                if (doctor == null)
                {
                    return(StatusCode(404, "User Not Found"));
                }

                //Checks if the doctor still has at least 1 appointment
                var appointment = _appointmentRepository.GetAll().FirstOrDefault(a => a.DoctorId == doctor.Id);
                if (appointment != null)
                {
                    return(StatusCode(400, "The Doctor you're trying to delete still has pending appointments"));
                }

                await _doctorRepository.DeleteAsync(doctor);

                await _userRepository.DeleteUserAsync(user);

                break;

            case "Client":
                var client = await _clientRepository.GetClientByUserEmail(user.Email);

                if (client == null)
                {
                    return(StatusCode(404, "User Not Found"));
                }
                //Checks if the client still has at least 1 animal
                if (client.NumberOfAnimals > 0)
                {
                    return(StatusCode(400, "The Client you're trying to delete still has registered animals"));
                }

                await _clientRepository.DeleteAsync(client);

                await _userRepository.DeleteUserAsync(user);

                break;

            default:
                return(StatusCode(404, "User Not Found"));
            }

            return(StatusCode(200, "Success"));
        }
Exemplo n.º 4
0
        public async Task<IActionResult> DeleteConfirmed( string userName )
        {
            await _doctorRepository.DeleteAsync( userName );
            return RedirectToAction( nameof( List ) );

        } // DeleteConfirmed
Exemplo n.º 5
0
 public async Task DeleteDoctor(Doctor doc)
 {
     await _doctorRepository.DeleteAsync(doc);
 }
        public async Task <int> Delete(Guid id)
        {
            var doctor = await _doctorRepository.GetAsync(id);

            return(await _doctorRepository.DeleteAsync(doctor));
        }