public async Task <Object> GetVehicleForReservation(int id)
        {
            var vehicleReservation = await _context.VehicleReservation.FindAsync(id);

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

            var vehicle = await _context.Vehicles
                          .Include(vehicle => vehicle.RentACar)
                          .Where(vehicle => vehicle.VehicleId == vehicleReservation.VehicleId)
                          .FirstOrDefaultAsync();

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

            VehicleForEmail vehicleForEmail = new VehicleForEmail()
            {
                Brand        = vehicle.Brand,
                RentACarName = vehicle.RentACar.Name
            };

            return(System.Text.Json.JsonSerializer.Serialize(vehicleForEmail));
        }
Пример #2
0
        public static void SendEMailReceipt(AppUser user, TOFlightReservation flightReservation, VehicleForEmail vehicle)
        {
            MailAddress to   = new MailAddress(user.Email, user.Name);
            MailAddress from = new MailAddress("*****@*****.**", "Careoplane");

            MailMessage message = new MailMessage(from, to);

            message.Subject = "Careoplane - Receipt";

            string text = string.Format("Hello {0},\n\n\tRecently you have made a reservation on our website. Below are your reservation details:\n\t", user.Name);

            foreach (TOFlightReservationDetail tOFlightReservationDetail in flightReservation.FlightReservationDetails)
            {
                text += string.Format("\tFlight ({4}): from {0} ({1}) to {2} ({3})\n\t", tOFlightReservationDetail.Flight.Origin, tOFlightReservationDetail.Flight.Departure.ToString(), tOFlightReservationDetail.Flight.Destination, tOFlightReservationDetail.Flight.Arrival.ToString(), tOFlightReservationDetail.Flight.AirlineName);
            }

            if (vehicle != null)
            {
                text += string.Format("\tVehicle ({1}): {0}\n\n", vehicle.Brand, vehicle.RentACarName);
            }

            text += string.Format("Final price: €{0}\n\n\t", flightReservation.FinalPrice);
            text += "Hope you have an enjoyable trip.\n\tAll the best,\n\tCareoplane";

            message.Body = text;

            SmtpClient client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential("*****@*****.**", "Careoplane!1"),
                EnableSsl   = true
            };

            try
            {
                client.Send(message);
            }
            catch (SmtpException ex)
            {
                Console.WriteLine(ex.ToString());
                throw ex;
            }
        }
Пример #3
0
        public static void SendEMailInvite(AppUser inviter, AppUser user, TOFlightReservation flightReservation, VehicleForEmail vehicle, int id)
        {
            MailAddress to   = new MailAddress(user.Email, user.Name);
            MailAddress from = new MailAddress("*****@*****.**", "Careoplane");

            MailMessage message = new MailMessage(from, to);

            message.Subject = "Careoplane - Invitation";

            var link = string.Format("http://*****:*****@gmail.com", "Careoplane!1"),
                EnableSsl   = true
            };

            try
            {
                client.Send(message);
            }
            catch (SmtpException ex)
            {
                Console.WriteLine(ex.ToString());
                throw ex;
            }
        }