示例#1
0
        public void TestGetStatus()
        {
            var emailOne = new EmailDO { EmailID = 1, From = _fixture.TestEmail1() };
            var emailTwo = new EmailDO { EmailID = 2, From = _fixture.TestEmail1() };

            _emailRepo.Add(emailOne);
            _emailRepo.Add(emailTwo);

            _trackingStatusRepository.Add(new TrackingStatusDO
            {
                ForeignTableID = emailOne.EmailID,
                ForeignTableName = "EmailDO",
                Type = TrackingType.BOOKING_STATE,
                Status = TrackingStatus.UNPROCESSED
            });

            _trackingStatusRepository.Add(new TrackingStatusDO
            {
                ForeignTableID = emailTwo.EmailID,
                ForeignTableName = "EmailDO",
                Type = TrackingType.TEST_STATE,
                Status = TrackingStatus.UNPROCESSED
            });
            _uow.SaveChanges();

            TrackingStatusDO firstStatus = _trackingStatus.GetStatus(TrackingType.BOOKING_STATE, emailOne);
            Assert.NotNull(firstStatus);
            Assert.AreEqual(TrackingStatus.UNPROCESSED, firstStatus.Status);

            TrackingStatusDO secondStatus = _trackingStatus.GetStatus(TrackingType.BOOKING_STATE, emailTwo);
            Assert.Null(secondStatus);
        }
示例#2
0
        public void TestDeleteStatus()
        {
            var emailOne = new EmailDO { EmailID = 1, From = _fixture.TestEmail1() };

            _emailRepo.Add(emailOne);

            _trackingStatusRepository.Add(new TrackingStatusDO
            {
                ForeignTableID = emailOne.EmailID,
                ForeignTableName = "EmailDO",
                Type = TrackingType.BOOKING_STATE,
                Status = TrackingStatus.UNPROCESSED
            });
            _uow.SaveChanges();

            Assert.AreEqual(1, _trackingStatusRepository.GetAll().Count());

            _trackingStatus.DeleteStatus(TrackingType.TEST_STATE, emailOne);
            _uow.SaveChanges();
            Assert.AreEqual(1, _trackingStatusRepository.GetAll().Count());

            _trackingStatus.DeleteStatus(TrackingType.BOOKING_STATE, emailOne);
            _uow.SaveChanges();
            Assert.AreEqual(0, _trackingStatusRepository.GetAll().Count());

            _trackingStatus.DeleteStatus(TrackingType.BOOKING_STATE, emailOne);
            _uow.SaveChanges();
            Assert.AreEqual(0, _trackingStatusRepository.GetAll().Count());
        }
示例#3
0
 private void LoadEmailRow(int emailID)
 {
     var uow = ObjectFactory.GetInstance<IUnitOfWork>();
     m_EmailRow = uow.EmailRepository.GetQuery().FirstOrDefault(e => e.Id == emailID);
     string bookerId = uow.BookingRequestRepository.GetByKey(emailID).BookerID;
     if (bookerId != null)
     {
         booker = uow.UserRepository.GetByKey(bookerId).EmailAddress.Address;
     }
     else { booker = "none"; }
 }
示例#4
0
        public EmailDO TestEmail1()
        {

            EmailDO curEmailDO = new EmailDO();
            curEmailDO.Id = 1;
            curEmailDO.From = TestEmailAddress1();
            curEmailDO.AddEmailRecipient(EmailParticipantType.To, TestEmailAddress2());
            curEmailDO.Subject = "Main Subject";
            curEmailDO.HTMLText = "This is the Body Text";
            return curEmailDO;

        }
示例#5
0
        public EmailDO TestEmail3()
        {

            EmailDO curEmailDO = new EmailDO();
            curEmailDO.Id = 3;
            curEmailDO.From = TestEmailAddress3();
            curEmailDO.AddEmailRecipient(EmailParticipantType.To, TestEmailAddress3());
            curEmailDO.Subject = "Main Subject";
            curEmailDO.HTMLText = "This Email is intended to be used with KwasantIntegration account ";
            return curEmailDO;

        }
示例#6
0
        public void GenerateWelcomeEmail(string curUserId)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var curUser = uow.UserRepository.GetByKey(curUserId);
                EmailDO curEmail = new EmailDO();
                curEmail.From = uow.EmailAddressRepository.GetOrCreateEmailAddress(_configRepository.Get("EmailFromAddress_DirectMode"), _configRepository.Get("EmailFromName_DirectMode"));
                curEmail.AddEmailRecipient(EmailParticipantType.To, curUser.EmailAddress);
                curEmail.Subject = "Welcome to Kwasant";

                uow.EnvelopeRepository.ConfigureTemplatedEmail(curEmail, _configRepository.Get("welcome_to_kwasant_template"), null); //welcome to kwasant v2 template
                uow.SaveChanges();
            }
        }
示例#7
0
        public async Task SendAsync(IdentityMessage message)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                String senderMailAddress = ObjectFactory.GetInstance<IConfigRepository>().Get("EmailFromAddress_DirectMode");

                EmailDO emailDO = new EmailDO();
                emailDO.AddEmailRecipient(EmailParticipantType.To, Email.GenerateEmailAddress(uow, new MailAddress(message.Destination)));
                emailDO.From = Email.GenerateEmailAddress(uow, new MailAddress(senderMailAddress));

                emailDO.Subject = message.Subject;
                emailDO.HTMLText = message.Body;

                uow.EnvelopeRepository.ConfigurePlainEmail(emailDO);
                uow.SaveChanges();
            }
        }
示例#8
0
 public void DispatchNegotiationRequests(IUnitOfWork uow, EmailDO generatedEmailDO, int negotiationID)
 {
     DispatchNegotiationRequests(uow, generatedEmailDO, uow.NegotiationsRepository.GetByKey(negotiationID));
 }
示例#9
0
        private void SendBREmails(String toAddress, IEnumerable<BookingRequestDO> bookingRequests, IUnitOfWork uow)
        {
            EmailRepository emailRepo = uow.EmailRepository;
            const string message = "A new booking request has been created. From '{0}'.";
            foreach (BookingRequestDO bookingRequest in bookingRequests)
            {
                EmailDO outboundEmail = new EmailDO
                {
                    Subject = "New booking request!",
                    HTMLText = String.Format(message, bookingRequest.From.Address),
                    EmailStatus = EmailState.Queued
                };

                var toEmailAddress = uow.EmailAddressRepository.GetOrCreateEmailAddress(toAddress);
                outboundEmail.AddEmailRecipient(EmailParticipantType.To, toEmailAddress);
                outboundEmail.From = _emailAddress.GetFromEmailAddress(uow, toEmailAddress, bookingRequest.Customer);

                uow.EnvelopeRepository.ConfigurePlainEmail(outboundEmail);
                emailRepo.Add(outboundEmail);
            }
        }
示例#10
0
        public void DispatchBatchedNegotiationRequests(IUnitOfWork uow, String templateName, String htmlText, IList<RecipientDO> recipients, NegotiationDO negotiationDO)
        {
            if (!recipients.Any())
                return;

            var emailDO = new EmailDO();
            //This means, when the customer replies, their client will include the bookingrequest id
            emailDO.TagEmailToBookingRequest(negotiationDO.BookingRequest);

            var customer = negotiationDO.BookingRequest.Customer;
            var mode = _user.GetMode(customer);
            if (mode == CommunicationMode.Direct)
            {
                var directEmailAddress = _configRepository.Get("EmailFromAddress_DirectMode");
                var directEmailName = _configRepository.Get("EmailFromName_DirectMode");
                emailDO.From = uow.EmailAddressRepository.GetOrCreateEmailAddress(directEmailAddress);
                emailDO.FromName = directEmailName;
            }
            else
            {
                var delegateEmailAddress = _configRepository.Get("EmailFromAddress_DelegateMode");
                var delegateEmailName = _configRepository.Get("EmailFromName_DelegateMode");
                emailDO.From = uow.EmailAddressRepository.GetOrCreateEmailAddress(delegateEmailAddress);
                emailDO.FromName = String.Format(delegateEmailName, customer.DisplayName);
            }

            emailDO.Subject = string.Format("Need Your Response on {0} {1} event: {2}",
                negotiationDO.BookingRequest.Customer.FirstName,
                (negotiationDO.BookingRequest.Customer.LastName ?? ""),
                "RE: " + negotiationDO.Name);

            var responseUrl = String.Format("NegotiationResponse/View?negotiationID={0}", negotiationDO.Id);

            var tokenUrls = new List<String>();
            foreach (var attendee in recipients)
            {
                emailDO.AddEmailRecipient(EmailParticipantType.To, attendee.EmailAddress);
                var curUserDO = uow.UserRepository.GetOrCreateUser(attendee.EmailAddress);
                var tokenURL = uow.AuthorizationTokenRepository.GetAuthorizationTokenURL(responseUrl, curUserDO);
                tokenUrls.Add(tokenURL);
            }

            uow.EmailRepository.Add(emailDO);
            var summaryQandAText = _negotiation.GetSummaryText(negotiationDO);

            string currBookerAddress = negotiationDO.BookingRequest.Booker.EmailAddress.Address;

            var conversationThread = _br.GetConversationThread(negotiationDO.BookingRequest);

            // Fix an issue when coverting to UTF-8
            conversationThread = conversationThread.Replace((char)160, (char)32);

            uow.EnvelopeRepository.ConfigureTemplatedEmail(emailDO, templateName,
                new Dictionary<string, object>
                {
                    {"RESP_URL", tokenUrls},
                    {"bodytext", htmlText},
                    {"questions", String.Join("<br/>", summaryQandAText)},
                    {"conversationthread", conversationThread},
                    {"bookername", currBookerAddress.Replace("@kwasant.com","")}
                });

            negotiationDO.NegotiationState = NegotiationState.AwaitingClient;

            //Everyone who gets an email is now an attendee.
            var currentAttendeeIDs = negotiationDO.Attendees.Select(a => a.EmailAddressID).ToList();
            foreach (var recipient in recipients)
            {
                if (!currentAttendeeIDs.Contains(recipient.EmailAddressID))
                {
                    var newAttendee = new AttendeeDO
                    {
                        EmailAddressID = recipient.EmailAddressID,
                        Name = recipient.EmailAddress.Name,
                        NegotiationID = negotiationDO.Id
                    };
                    uow.AttendeeRepository.Add(newAttendee);
                }
            }
        }
示例#11
0
        public void DispatchNegotiationRequests(IUnitOfWork uow, EmailDO generatedEmailDO, NegotiationDO negotiationDO)
        {
            var batches = generatedEmailDO.Recipients.GroupBy(r =>
            {
                var curUserDO = uow.UserRepository.GetOrCreateUser(r.EmailAddress);
                return GetCRTemplate(curUserDO);
            });

            foreach (var batch in batches)
            {
                DispatchBatchedNegotiationRequests(uow, batch.Key, generatedEmailDO.HTMLText, batch.ToList(), negotiationDO);
            }
        }
示例#12
0
        public void TestGetEntitiesWithoutStatus()
        {
            var emailOne = new EmailDO { EmailID = 1, From = _fixture.TestEmail1() };
            var emailTwo = new EmailDO { EmailID = 2, From = _fixture.TestEmail1() };

            _emailRepo.Add(emailOne);
            _emailRepo.Add(emailTwo);

            _trackingStatusRepository.Add(new TrackingStatusDO
            {
                ForeignTableID = emailOne.EmailID,
                ForeignTableName = "EmailDO",
                Type = TrackingType.BOOKING_STATE,
                Status = TrackingStatus.UNPROCESSED
            });

            _trackingStatusRepository.Add(new TrackingStatusDO
            {
                ForeignTableID = emailTwo.EmailID,
                ForeignTableName = "EmailDO",
                Type = TrackingType.TEST_STATE,
                Status = TrackingStatus.UNPROCESSED
            });

            _uow.SaveChanges();

            List<EmailDO> t = _trackingStatus.GetEntitiesWithoutStatus(TrackingType.BOOKING_STATE).ToList();
            Assert.AreEqual(2, _emailRepo.GetAll().Count());
            Assert.AreEqual(1, t.Count);
            Assert.AreEqual(emailTwo.EmailID, t.First().EmailID);
        }
示例#13
0
        private static void OnPostResolutionNegotiationResponseReceived(int negotiationId)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var negotiationDO = uow.NegotiationsRepository.GetByKey(negotiationId);

                IConfigRepository configRepository = ObjectFactory.GetInstance<IConfigRepository>();
                string fromAddress = configRepository.Get("EmailAddress_GeneralInfo");

                const string subject = "New response to resolved negotiation request";
                const string messageTemplate = "A customer has submitted a new response to an already-resolved negotiation request ({0}). Click {1} to view the booking request.";

                var bookingRequestURL = String.Format("{0}/BookingRequest/Details/{1}", Server.ServerUrl, negotiationDO.BookingRequestID);
                var message = String.Format(messageTemplate, negotiationDO.Name, "<a href='" + bookingRequestURL + "'>here</a>");

                var toRecipient = negotiationDO.BookingRequest.Booker.EmailAddress;

                EmailDO curEmail = new EmailDO
                    {
                        Subject = subject,
                        PlainText = message,
                        HTMLText = message,
                        From = uow.EmailAddressRepository.GetOrCreateEmailAddress(fromAddress),
                        Recipients = new List<RecipientDO>
                            {
                                new RecipientDO
                                    {
                                        EmailAddress = toRecipient,
                                        EmailParticipantType = EmailParticipantType.To
                                    }
                            }
                    };

                uow.EnvelopeRepository.ConfigurePlainEmail(curEmail);
                uow.SaveChanges();
            }
        }
示例#14
0
 public string PackResponseGetEmail(EmailDO curEmailDO)
 {
   return jsonSerializer.Serialize(curEmailDO);
    
 }
示例#15
0
文件: Account.cs 项目: alexed1/dtrack
        public async Task ForgotPasswordAsync(string userEmail)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var userManager = new KwasantUserManager(uow);
                var user = await userManager.FindByEmailAsync(userEmail);
                if (user == null/* || !(await userManager.IsEmailConfirmedAsync(user.Id))*/)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return;
                }

                var code = await userManager.GeneratePasswordResetTokenAsync(user.Id);
                var callbackUrl = string.Format("{0}Account/ResetPassword?UserId={1}&code={2}", Server.ServerUrl, user.Id, code);

                var emailDO = new EmailDO();
                IConfigRepository configRepository = ObjectFactory.GetInstance<IConfigRepository>();
                string fromAddress = configRepository.Get("EmailAddress_GeneralInfo");
                var emailAddressDO = uow.EmailAddressRepository.GetOrCreateEmailAddress(fromAddress);
                emailDO.From = emailAddressDO;
                emailDO.FromID = emailAddressDO.Id;
                emailDO.AddEmailRecipient(EmailParticipantType.To, uow.EmailAddressRepository.GetOrCreateEmailAddress(userEmail));
                emailDO.Subject = "Password Recovery Request";

                uow.EnvelopeRepository.ConfigureTemplatedEmail(emailDO, configRepository.Get("ForgotPassword_template"),
                                                               new Dictionary<string, object>()
                                                                   {{"-callback_url-", callbackUrl}});
                uow.SaveChanges();
            }
        }
示例#16
0
        private void ReportBookingRequestReserved(int bookingRequestId, string bookerId)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var curBookingRequest = uow.BookingRequestRepository.GetByKey(bookingRequestId);
                if (curBookingRequest == null)
                    throw new EntityNotFoundException<BookingRequestDO>(bookingRequestId);
                var curBooker = uow.UserRepository.GetByKey(bookerId);
                if (curBooker == null)
                    throw new EntityNotFoundException<UserDO>(bookerId);

                if (!curBooker.Available.GetValueOrDefault())
                {
                    IConfigRepository configRepository = ObjectFactory.GetInstance<IConfigRepository>();
                    string fromAddress = configRepository.Get("EmailAddress_GeneralInfo");

                    const string subject = "A booking request has been reserved for you";
                    const string messageTemplate = "A booking request has been reserved for you ({0}). Click {1} to view the booking request.";

                    var bookingRequestURL = String.Format("{0}/BookingRequest/Details/{1}", Server.ServerUrl, curBookingRequest.Id);
                    var message = String.Format(messageTemplate, curBookingRequest.Subject, "<a href='" + bookingRequestURL + "'>here</a>");

                    var toRecipient = curBooker.EmailAddress;

                    EmailDO curEmail = new EmailDO
                    {
                        Subject = subject,
                        PlainText = message,
                        HTMLText = message,
                        From = uow.EmailAddressRepository.GetOrCreateEmailAddress(fromAddress),
                        Recipients = new List<RecipientDO>
                            {
                                new RecipientDO
                                    {
                                        EmailAddress = toRecipient,
                                        EmailParticipantType = EmailParticipantType.To
                                    }
                            }
                    };

                    uow.EnvelopeRepository.ConfigurePlainEmail(curEmail);
                    uow.SaveChanges();
                }
            }
            Logger.GetLogger().Info(string.Format("Reserved. BookingRequest ID : {0}, Booker ID: {1}", bookingRequestId, bookerId));
        }
示例#17
0
        public void TestSetStatus()
        {
            var emailOne = new EmailDO { EmailID = 1, From = _fixture.TestEmail1() };

            _emailRepo.Add(emailOne);
            _uow.SaveChanges();

            Assert.AreEqual(0, _trackingStatusRepository.GetAll().Count());

            TrackingStatusDO status = _trackingStatus.GetStatus(TrackingType.BOOKING_STATE, emailOne);
            Assert.Null(status);

            _trackingStatus.SetStatus(TrackingType.BOOKING_STATE, emailOne, TrackingStatus.UNPROCESSED);
            _uow.SaveChanges();

            status = _trackingStatus.GetStatus(TrackingType.BOOKING_STATE, emailOne);
            Assert.NotNull(status);
            Assert.AreEqual(TrackingStatus.UNPROCESSED, status.Status);
            Assert.AreEqual(1, _trackingStatusRepository.GetAll().Count());

            _trackingStatus.SetStatus(TrackingType.BOOKING_STATE, emailOne, TrackingStatus.PROCESSED);
            _uow.SaveChanges();

            status = _trackingStatus.GetStatus(TrackingType.BOOKING_STATE, emailOne);
            Assert.NotNull(status);
            Assert.AreEqual(TrackingStatus.PROCESSED, status.Status);
            Assert.AreEqual(1, _trackingStatusRepository.GetAll().Count());

            _trackingStatus.SetStatus(TrackingType.TEST_STATE, emailOne, TrackingStatus.UNPROCESSED);
            _uow.SaveChanges();

            status = _trackingStatus.GetStatus(TrackingType.BOOKING_STATE, emailOne);
            Assert.NotNull(status);
            Assert.AreEqual(TrackingStatus.PROCESSED, status.Status);
            Assert.AreEqual(2, _trackingStatusRepository.GetAll().Count());
        }