Example #1
0
        public JsonResult MarkShipped(ShippedVM vm)
        {
            string id = BifSessionData.IsInRole("ADMIN") ? vm.SenderId ?? BifSessionData.Id : BifSessionData.Id;

            var match = DAL.Context.Matches.Where(x => x.ExchangeId == BifSessionData.ExchangeId && x.SenderId == id)
                        .Select(x => new { Match = x, ExchangeName = x.Exchange.Name, SenderEmail = x.Sender.Email, SenderUsername = x.Sender.Profile.RedditUsername, RecipientEmail = x.Recipient.Email, RecipientUsername = x.Recipient.Profile.RedditUsername })
                        .FirstOrDefault();

            if (match == null)
            {
                return(Json(new { Success = false }));
            }

            match.Match.Carrier    = vm.Carrier;
            match.Match.TrackingNo = vm.TrackingNo;
            match.Match.ShipDate   = DateTime.Now;

            DAL.Context.SaveChanges();

            ShippingNoticeVM noticeVM = new ShippingNoticeVM {
                Carrier           = match.Match.Carrier,
                TrackingNo        = match.Match.TrackingNo,
                ExchangeName      = match.ExchangeName,
                SenderEmail       = match.SenderEmail,
                SenderUsername    = match.SenderUsername,
                RecipientEmail    = match.RecipientEmail,
                RecipientUsername = match.RecipientUsername
            };

            sendShippingEmails(noticeVM);

            return(Json(new { Success = true }));
        }
Example #2
0
        private void sendShippingEmails(ShippingNoticeVM vm)
        {
            EmailClient email = EmailClient.Create();

            string confirmationBody = RenderPartialToString(this, "__ShippingConfirmation", vm);
            string notificationBody = RenderPartialToString(this, "__ShippingNotification", vm);

            MailMessage confirmationMessage = new MailMessage
            {
                To         = { new MailAddress(vm.SenderEmail, vm.SenderUsername) },
                CC         = { new MailAddress("*****@*****.**") },
                Bcc        = { new MailAddress("*****@*****.**") },
                From       = new MailAddress("*****@*****.**", "BeerItForward"),
                Subject    = $"{vm.ExchangeName} Shipping Confirmation",
                Body       = confirmationBody,
                IsBodyHtml = true
            };

            MailMessage notificationMessage = new MailMessage
            {
                To         = { new MailAddress(vm.RecipientEmail, vm.RecipientUsername) },
                CC         = { new MailAddress("*****@*****.**") },
                Bcc        = { new MailAddress("*****@*****.**") },
                From       = new MailAddress("*****@*****.**", "BeerItForward"),
                Subject    = $"{vm.ExchangeName} Shipping Notification",
                Body       = notificationBody,
                IsBodyHtml = true
            };

#if (DEBUG)
#else
            email.SMTP.Send(confirmationMessage);
            email.SMTP.Send(notificationMessage);
#endif
        }