예제 #1
0
        public async Task <IActionResult> AddDoctorAbsence(AddDoctorAbsenceViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var doctor = await _doctorsRepository.GetDoctorByName(User.Identity.Name);

            var alreadyHasAbsence = await _absenceRepository.GetDoctorsAbscenceByDate(doctor.Name, model.AbsenceDate);

            if (alreadyHasAbsence != null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var absence = new DoctorAbsence
            {
                AbsenceDate        = model.AbsenceDate,
                DoctorId           = doctor.DoctorId,
                AbsenceDescription = model.AbsenceDescription
            };

            await _absenceRepository.AddAbsence(absence);

            return(RedirectToAction("Index", "Home"));
        }
예제 #2
0
        public async Task <DoctorAbsence> AddAbsence(DoctorAbsence doctorAbsence)
        {
            await _dbContext.DoctorsAbsences.AddAsync(doctorAbsence);

            await _dbContext.SaveChangesAsync();

            return(doctorAbsence);
        }
        public void Setup()
        {
            IFixture fixture = new Fixture();

            fixture.Behaviors.OfType <ThrowingRecursionBehavior>().ToList()
            .ForEach(b => fixture.Behaviors.Remove(b));
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());

            var databaseName = fixture.Create <string>();

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName).Options;

            mockSet = new Mock <DbSet <DoctorAbsence> >();

            mockContext = new Mock <ApplicationDbContext>(options);
            mockContext.Setup(m => m.DoctorsAbsences).Returns(mockSet.Object);
            absenceRepository = new AbsenceRepository(mockContext.Object);

            testDoctorAbsence = fixture.Create <DoctorAbsence>();
        }
예제 #4
0
        public async Task AddDoctorsAbsence(string name, DateTime modelAbsenceDate, string modelAbsenceDescription,
                                            CancellationToken cancellationToken)
        {
            var doctor = await _doctorsRepository.GetAsync(name, cancellationToken).ConfigureAwait(false);

            var doctorsAbsences = await _absenceRepository.ListAsync(cancellationToken).ConfigureAwait(false);

            var doctorsAppointments = await _appointmentsRepository.ListAsync(cancellationToken).ConfigureAwait(false);

            if (doctorsAbsences.Any(a => a.AbsenceDate == modelAbsenceDate) ||
                doctorsAppointments.Any(a => a.Doctor.Name == name && a.StartDateTime.ToString("d") == modelAbsenceDate.ToString("d")))
            {
                return;
            }

            var absenceToAdd = new DoctorAbsence
            {
                Doctor             = doctor,
                AbsenceDate        = modelAbsenceDate,
                AbsenceDescription = modelAbsenceDescription
            };

            await _absenceRepository.CreateAsync(absenceToAdd, cancellationToken).ConfigureAwait(false);
        }