Пример #1
0
        public async Task SendPenaltyInvoice(Penalty penalty)
        {
            Parking parking = await context.Parking.FindAsync(penalty.ParkingId);

            DateTime penaltyTime = DateTime.Now;
            DateTime startTime   = DateTime.Parse(Convert.ToString(parking.CreatedAt));
            DateTime expectedEnd = startTime.AddHours(Convert.ToDouble(parking.ParkedHours));

            //This key is for authentication in SendGrid API
            var sendGridAPIKey = Environment.GetEnvironmentVariable("SENDGRID_KEY");

            //Initializing new instance of the API client
            var mailClient = new SendGridClient(sendGridAPIKey);

            //Initializing new message
            var message = new SendGridMessage()
            {
                From = new EmailAddress("*****@*****.**", "ParkKL"),
            };

            message.SetTemplateId("a1049d0f-08ed-4a78-8b3e-d1e890b41ec0");
            message.AddSubstitution("-PLATE-", parking.CarPlateNumber);
            message.AddSubstitution("-LOCATION-", parking.LocationName);
            message.AddSubstitution("-ISSUETIME-", penaltyTime.ToString("g"));
            message.AddSubstitution("-ENDTIME-", expectedEnd.ToString("g"));
            message.AddSubstitution("-EXCEED-", penalty.ExceededHours);

            message.AddTo(new EmailAddress(penalty.Email, "User"));

            //Sending the E-mail message
            var response = await mailClient.SendEmailAsync(message);
        }
Пример #2
0
        public async Task SendPenaltyReceipt(Wallet wallet, string parkingId, string Id, string penaltyId)
        {
            User user = await context.Users.FindAsync(Id);

            Parking parking = await context.Parking.FindAsync(parkingId);

            Penalty penalty = await context.Penalty.FindAsync(penaltyId);

            DateTime paymentTime = DateTime.Now;
            DateTime startTime   = DateTime.Parse(Convert.ToString(parking.CreatedAt));
            DateTime expectedEnd = startTime.AddHours(Convert.ToDouble(parking.ParkedHours));

            //This key is for authentication in SendGrid API
            var sendGridAPIKey = Environment.GetEnvironmentVariable("SENDGRID_KEY");

            //Initializing new instance of the API client
            var mailClient = new SendGridClient(sendGridAPIKey);

            //Initializing new message
            var message = new SendGridMessage()
            {
                From = new EmailAddress("*****@*****.**", "ParkKL"),
            };

            //Configuring the E-mail message to fit a saved template
            message.SetTemplateId("a18f4e89-4212-4820-b7bd-7ad5ee52d410");
            message.AddSubstitution("-FIRST-", user.FirstName);
            message.AddSubstitution("-DATE-", paymentTime.ToString("g"));
            message.AddSubstitution("-LOCATION-", parking.LocationName);
            message.AddSubstitution("-PLATE-", parking.CarPlateNumber);
            message.AddSubstitution("-DURATION-", expectedEnd.ToString("g"));
            message.AddSubstitution("-EXCESS-", penalty.ExceededHours);
            message.AddSubstitution("-BALANCE-", wallet.Balance.ToString());
            message.AddTo(new EmailAddress(wallet.Email, "User"));

            //Sending the E-mail message
            var response = await mailClient.SendEmailAsync(message);
        }