public void CanCommunicationModeDirectOrDelegetOrNull()
        {
            CommunicationMode cruCommunicationMode;

            _fr8Account.GetMode(null);

            cruCommunicationMode = _fr8Account.GetMode(_dockyardAccountDO);
            Assert.AreEqual(cruCommunicationMode, CommunicationMode.Direct);

            _dockyardAccountDO.PasswordHash = string.Empty;
            cruCommunicationMode            = _fr8Account.GetMode(_dockyardAccountDO);
            Assert.AreEqual(cruCommunicationMode, CommunicationMode.Delegate);
        }
        //public void DispatchNegotiationRequests(IUnitOfWork uow, EmailDO generatedEmailDO, int negotiationID)
        //{
        //    DispatchNegotiationRequests(uow, generatedEmailDO, uow.NegotiationsRepository.GetByKey(negotiationID));
        //}

        //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);
        //    }
        //}

        //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);
        //        }
        //    }
        //}

        public string GetCRTemplate(Fr8AccountDO curDockyardAccountDO)
        {
            string templateName;

            // Max Kostyrkin: currently DockYardAccount#GetMode returns Direct if user has a booking request or has a password, otherwise Delegate.
            switch (_dockyardAccount.GetMode(curDockyardAccountDO))
            {
            case CommunicationMode.Direct:
                templateName = _configRepository.Get("CR_template_for_creator");

                break;

            case CommunicationMode.Delegate:
                templateName = _configRepository.Get("CR_template_for_precustomer");

                break;

            case CommunicationMode.Precustomer:
                templateName = _configRepository.Get("CR_template_for_precustomer");

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(templateName);
        }
 private Traits GetProperties(Fr8AccountDO fr8AccountDO)
 {
     return(new Traits
     {
         { "First Name", fr8AccountDO.FirstName },
         { "Last Name", fr8AccountDO.LastName },
         { "Username", fr8AccountDO.UserName },
         { "Email", fr8AccountDO.EmailAddress.Address },
         { "Delegate Account", _fr8Account.GetMode(fr8AccountDO) == CommunicationMode.Delegate },
         { "Class", fr8AccountDO.Class }
     });
 }