Ejemplo n.º 1
0
        public AppointmentDTO MakeAppointment(AppointmentDTO appointmentDTO)
        {
            var validatedAppointmentDTO = ValidateAndSetAppointment(appointmentDTO, AppointmentStatus.CREATED);

            var appointment = AppointmentConverter.FromAppointmentDTOToAppointment(validatedAppointmentDTO);

            _iAppointmentDao.Add(appointment);

            var owner     = _iUserDao.FindUserById(appointmentDTO.AdvertismentOwnerId);
            var initiator = _iUserDao.FindUserById(appointmentDTO.InitiatorId);

            EmailModelAppointment emailModel = new EmailModelAppointment
            {
                Sender            = ConfigurationManager.AppSettings["AdminEmail"],
                SenderName        = initiator.FirstName + " " + initiator.LastName,
                Receiver          = owner.Email,
                ReceiverFirstName = owner.FirstName,
                ReceiverLastName  = owner.LastName,
                EmailSubject      = EmailSubjects.NewAppointment,
                AppointmentTitle  = appointmentDTO.AdvertismentTitle,
                AppointmentDate   = appointmentDTO.AppointmentDateTime,
                EmailTemplatePath = EmailTemplatesPath.MakeAppointmentTemplate
            };

            _iMailerService.SendMailAppointments(emailModel);

            return(CreateAppoinmentNotification(appointment, owner, initiator));
        }
        public async Task <IActionResult> Create([Bind("PatientId,AppointmentDate,FromHour,FromMinute,ToHour,ToMinute,AppointmentDuration")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                int success = await _appointmentRepository.SaveAppointmentAsync(AppointmentConverter.AppointmentForDb(appointment));

                if (success != 0)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
                    ViewBag.ListOfHours    = hours.Hours;
                    ViewBag.ListOfMinutes  = hours.Minutes;

                    ViewBag.ErrorMessage = "Something went wrong while creating appointment list entry, please try again...";
                }
            }

            ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
            ViewBag.ListOfHours    = hours.Hours;
            ViewBag.ListOfMinutes  = hours.Minutes;

            return(View(appointment));
        }
Ejemplo n.º 3
0
        public UserAppointmentsViewModel GetUserAppointmentsViewModel(string userId)
        {
            var userAppointmentsViewModel = new UserAppointmentsViewModel();

            var userAppointments = _iAppointmentDao.GetUserAppointments(userId);

            foreach (var userAppointment in userAppointments)
            {
                var horseAd        = _iHorseAdDao.GetById(userAppointment.AdvertismentId);
                var appointmentDTO = AppointmentConverter.FromAppointmentToAppointmentDTO(userAppointment, horseAd);

                if (userAppointment.InitiatorId == userId && userAppointment.IsAccepted == false)
                {
                    userAppointmentsViewModel.UserPendingWhenInitiator.Add(appointmentDTO);
                    if (!userAppointment.SeenByInitiator)
                    {
                        userAppointmentsViewModel.UnseenAppointmentIds.Add(userAppointment.Id);
                    }
                }

                if (userAppointment.InitiatorId == userId && userAppointment.IsAccepted == true)
                {
                    userAppointmentsViewModel.UserUpcomingWhenInitiator.Add(appointmentDTO);
                    if (!userAppointment.SeenByInitiator)
                    {
                        userAppointmentsViewModel.UnseenAppointmentIds.Add(userAppointment.Id);
                    }
                }

                if (userAppointment.AdvertismentOwnerId == userId && userAppointment.IsAccepted == false)
                {
                    userAppointmentsViewModel.UserPendingWhenOwner.Add(appointmentDTO);
                    if (!userAppointment.SeenByOwner)
                    {
                        userAppointmentsViewModel.UnseenAppointmentIds.Add(userAppointment.Id);
                    }
                }

                if (userAppointment.AdvertismentOwnerId == userId && userAppointment.IsAccepted == true)
                {
                    userAppointmentsViewModel.UserUpcomingWhenOwner.Add(appointmentDTO);
                    if (!userAppointment.SeenByOwner)
                    {
                        userAppointmentsViewModel.UnseenAppointmentIds.Add(userAppointment.Id);
                    }
                }
            }

            return(userAppointmentsViewModel);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,PatientId,AppointmentDate,FromHour,FromMinute,ToHour,ToMinute,AppointmentDuration")] Appointment appointment)
        {
            if (id != appointment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var app = AppointmentConverter.AppointmentForDb(appointment);

                    var succes = await _appointmentRepository.UpdateAppointmentAsync(app);

                    if (succes != 0)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
                        ViewBag.ListOfHours    = hours.Hours;
                        ViewBag.ListOfMinutes  = hours.Minutes;

                        ViewBag.ErrorMessage = "Something went wrong while updating patient list entry, please try again...";
                    }
                }
                catch (SqlException)
                {
                    var entry = await _appointmentRepository.GetAppointmentByIdAsync(appointment.Id);

                    if (entry is null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
            ViewBag.ListOfHours    = hours.Hours;
            ViewBag.ListOfMinutes  = hours.Minutes;

            return(View(appointment));
        }
Ejemplo n.º 5
0
        public ActionResult <bool> Post([FromBody] AppointmentDTO dto)
        {
            try
            {
                var converter = new AppointmentConverter(_repositoryFactory);

                var appointmentRepository = _repositoryFactory.GetAppointmentRepository();
                return(appointmentRepository.AddIfNotExist(
                           converter.Convert(dto)
                           ));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id is null)
            {
                return(NotFound());
            }

            var app = await _appointmentRepository.GetAppointmentByIdAsync(id.Value);

            if (app is null)
            {
                return(NotFound());
            }

            var appointment = await AppointmentConverter.AppointmentForFrontEnd(app, _patientRepository);

            return(View(appointment));
        }
        // GET: Appointment/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var app = await _appointmentRepository.GetAppointmentByIdAsync(id.Value);//await _dbDataAccess.GetAppointmentByIdAsync(id.Value);

            if (app == null)
            {
                return(NotFound());
            }

            ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
            ViewBag.ListOfHours    = hours.Hours;
            ViewBag.ListOfMinutes  = hours.Minutes;

            var appointment = await AppointmentConverter.AppointmentForFrontEnd(app, _patientRepository);

            return(View(appointment));
        }