Example #1
0
        public IActionResult Create()
        {
            var viewModel = new CreateUpdateAppointmentViewModel
            {
                Doctors     = _context.Doctors.ToList(),
                Pets        = _context.Pets.Include(p => p.Owner).ToList(),
                Appointment = new Appointment()
            };


            return(View(viewModel));
        }
Example #2
0
        public IActionResult Create(CreateUpdateAppointmentViewModel viewModel, bool sendEmail)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            _context.Appointments.Add(viewModel.Appointment);
            _context.SaveChanges();

            if (!sendEmail)
            {
                return(View("Created", viewModel.Appointment));
            }

            var appointment = _context.Appointments
                              .Include(a => a.Pet)
                              .ThenInclude(p => p.Owner)
                              .Include(a => a.Doctor).ToList()
                              .Find(a => a.Id == viewModel.Appointment.Id);

            var ownerEmail  = appointment.Pet.Owner.Email;
            var doctorEmail = appointment.Doctor.Email;


            var message = new MailMessage();

            message.To.Add(new MailAddress(ownerEmail));
            message.From = new MailAddress("*****@*****.**", "VetApp");
            message.Bcc.Add(new MailAddress(doctorEmail));
            message.Subject = "VeApp - Appointment to " + appointment.Pet.Name;
            message.Body    =
                "<p>An appointment was booked to " + appointment.Pet.Name + " to " +
                appointment.Date.Day + "/" + appointment.Date.Month + "/" + appointment.Date.Year + " " +
                appointment.Date.Hour + ":" + appointment.Date.Minute +
                " with Doctor " + appointment.Doctor.Name + ".</p>" +
                "<p>For more details or to change this appointment, contact us.</p>" +
                "<br/>" +
                "<p>This is an automatic email, please do not reply.</p>";
            message.IsBodyHtml = true;


            var client = new SmtpClient("smtp.gmail.com")
            {
                Port        = 587,
                Credentials = new NetworkCredential("[email protected] ", "vetapppw"),
                EnableSsl   = true
            };

            client.Send(message);

            return(View("Created", viewModel.Appointment));
        }
Example #3
0
        public IActionResult Update(int?id)
        {
            var viewModel = new CreateUpdateAppointmentViewModel()
            {
                Appointment = _context.Appointments.Find(id),
                Doctors     = _context.Doctors.ToList(),
                Pets        = _context.Pets.ToList()
            };


            return(View(viewModel));
        }