public async Task <IActionResult> Create(AppViewModel model)
        {
            var appointment = _converterHelper.ToAppointment(model, true);

            if (ModelState.IsValid)
            {
                appointment.User = await _userHelper.GetUserByEmailAsync(this.User.Identity.Name);

                var customer = await _customerRepository.GetCustomerAsync(model.CustomerId);

                _mailHelper.SendMail(customer.User.Email, "YourVet App - Appointment", $"<h1>YourVet - Appointment scheduled successfully</h1>" +
                                     $"<br/>" +
                                     $"<h4>Hello {appointment.Customer.User.FullName}, welcome to YourVet.</4>" +
                                     $"<h5>Your appointment was scheduled successfully.</h5>" +
                                     $"<br/>" +
                                     $"<p>Schedule details:</p>" +
                                     $"<p>Date and time: {appointment.AppDate}</p>" +
                                     $"<p>Doctor: {appointment.Doctor.FullName}</p>" +
                                     $"<p>Date and time: {appointment.Pet.Name}</p>" +
                                     $"<br/>" +
                                     $"<p>Please arrive 10 minutes before the scheduled time.</p>");

                await _appRepository.CreateAsync(appointment);

                return(RedirectToAction(nameof(Index)));
            }

            model.Doctors      = _combosHelper.GetComboDoctors();
            model.Customers    = _combosHelper.GetComboCustomers();
            model.Pets         = _combosHelper.GetComboPets(model.CustomerId);
            model.ServiceTypes = _combosHelper.GetComboServiceTypes();


            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> Schedule(AppointmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.Doctor = await _doctorRepository.GetDoctorByIdAsync(model.DoctorId);

                    model.Owner = await _ownerRepository.GetOwnerWithUserByIdAsync(model.OwnerId);

                    model.Pet = await _petRepository.GetByIdWithIncludesAsync(model.PetId);

                    var appointment = _converterHelper.ToAppointment(model, true);

                    appointment.CreatedBy = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                    await _appointmentRepository.CreateAsync(appointment);

                    return(RedirectToAction(nameof(MyAppointments)));
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }

            model.Doctors = _doctorRepository.GetComboDoctors();
            model.Pets    = _petRepository.GetComboPets(model.OwnerId);

            return(View(model));
        }
        public async Task <IActionResult> Edit(AppointmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.Doctor = await _doctorRepository.GetDoctorByIdAsync(model.DoctorId);

                    model.Owner = await _ownerRepository.GetOwnerWithUserByIdAsync(model.OwnerId);

                    model.Pet = await _petRepository.GetByIdWithIncludesAsync(model.PetId);

                    var appointment = _converterHelper.ToAppointment(model, false);

                    if (appointment == null)
                    {
                        return(new NotFoundViewResult("AppointmentNotFound"));
                    }

                    appointment.ModifiedBy = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                    await _appointmentRepository.UpdateAsync(appointment);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }

            return(View(model));
        }