Exemplo n.º 1
0
        public PersonController()
        {
            var permissionRepository = new PermissionRepository();
            var churchRepository = new ChurchRepository();
            _personRepository = new PersonRepository(permissionRepository, churchRepository);
            var emailSender = new EmailSender(new MessageRepository(), new MessageRecepientRepository(), new MessageAttachmentRepository(), _personRepository);
            var churchEmailTemplateRepository = new ChurchEmailTemplatesRepository();
            var emailService = new EmailService(new UsernamePasswordRepository(permissionRepository), _personRepository, new GroupRepository(), emailSender, new EmailContentService(new EmailContentRepository()), churchEmailTemplateRepository, permissionRepository);
            var uploadPhotoRepository = new PhotoRepository();

            _personService = new PersonService(
                _personRepository,
                new PersonGroupRepository(_personRepository),
                permissionRepository,
                new PersonRoleRepository(),
                new PersonOptionalFieldRepository(),
                new RelationshipRepository(_personRepository),
                new ChurchMatcherRepository(),
                new GroupRepository(),
                new FamilyRepository(uploadPhotoRepository),
                emailService,
                new AddressRepository(),
                uploadPhotoRepository
                );
        }
Exemplo n.º 2
0
        public AjaxController()
        {
            var messageRepository = new MessageRepository();
            var permissionRepository = new PermissionRepository();
            var churchRepository = new ChurchRepository();
            var personRepository = new PersonRepository(permissionRepository, churchRepository);
            var uploadPhotoRepository = new PhotoRepository();
            _familyRepository = new FamilyRepository(uploadPhotoRepository);
            _usernamePasswordRepository = new UsernamePasswordRepository(permissionRepository);
            var personGroupRepository = new PersonGroupRepository(personRepository);
            _personGroupRepository = personGroupRepository;
            var groupRepository = new GroupRepository();
            var emailSender = new EmailSender(messageRepository, new MessageRecepientRepository(), new MessageAttachmentRepository(), personRepository);
            var emailContentService = new EmailContentService(new EmailContentRepository());
            var churchEmailTemplateRepository = new ChurchEmailTemplatesRepository();
            _emailService = new EmailService(
                _usernamePasswordRepository,
                personRepository,
                groupRepository,
                emailSender,
                emailContentService,
                churchEmailTemplateRepository,
                permissionRepository
                );

            _passwordService = new PasswordService(personRepository, churchRepository, _usernamePasswordRepository, _emailService);

            _personService = new PersonService(
                personRepository,
                _personGroupRepository,
                permissionRepository,
                new PersonRoleRepository(),
                new PersonOptionalFieldRepository(),
                new RelationshipRepository(personRepository),
                new ChurchMatcherRepository(),
                groupRepository,
                _familyRepository,
                _emailService,
                new AddressRepository(),
                uploadPhotoRepository
                );

            _groupEventRepository = new GroupEventRepository(personRepository);
            _systemAdministratorService  = new SystemAdministratorService(churchRepository, permissionRepository);
            _personGroupService = new PersonGroupService(_personGroupRepository);
            _messageRecepientRepository = new MessageRecepientRepository();
            var httpPostService = new HttpPostService();
            _smsSender = new SmsSender(messageRepository, new MessageRecepientRepository(), personRepository, httpPostService);
            _churchEventsReporitory = new ChurchEventsRepository();
            _messageService = new MessageService(_messageRecepientRepository);
            var birthdayRepository = new BirthdayAndAniversaryRepository();
            var usernamePasswordRepository = new UsernamePasswordRepository(permissionRepository);
            var churchEmailTemplatesRepository = new ChurchEmailTemplatesRepository();
            var emailService = new EmailService(usernamePasswordRepository, personRepository, groupRepository, emailSender, emailContentService, churchEmailTemplatesRepository, permissionRepository);
            var eventRepository = new EventRepository(birthdayRepository);
            _eventService = new EventService(eventRepository, emailService, birthdayRepository);
            _childReportsService = new ChildReportsService(new ChildrenReportsRepository(), _emailService);
            _reminderService = new ReminderService(new ReminderRepository());
        }
Exemplo n.º 3
0
        public HomeController()
        {
            var permissionRepository = new PermissionRepository();
            var churchRepository = new ChurchRepository();
            _personRepository = new PersonRepository(permissionRepository, churchRepository); var birthdayRepository = new BirthdayAndAniversaryRepository();
            var personRepository = new PersonRepository(permissionRepository, new ChurchRepository());
            var usernamePasswordRepository = new UsernamePasswordRepository(permissionRepository);
            var groupRepository = new GroupRepository();
            var messageRepository = new MessageRepository();
            var messageRecepientRepository = new MessageRecepientRepository();
            var messageAttachmentRepository = new MessageAttachmentRepository();
            var emailSender = new EmailSender(messageRepository, messageRecepientRepository, messageAttachmentRepository, personRepository);
            var churchEmailTemplatesRepository = new ChurchEmailTemplatesRepository();
            var emailContentRepository = new EmailContentRepository();
            var emailContentService = new EmailContentService(emailContentRepository);
            _emailService = new EmailService(usernamePasswordRepository, personRepository, groupRepository, emailSender, emailContentService, churchEmailTemplatesRepository, permissionRepository);
            var eventRepository = new EventRepository(birthdayRepository);
            _eventService = new EventService(eventRepository, _emailService, birthdayRepository);
            _personGroupRepository = new PersonGroupRepository(_personRepository);
            _usernamePasswordRepository = new UsernamePasswordRepository(permissionRepository);

            _photoRepository = new PhotoRepository();
            _photoServices = new PhotoServices();
            _personService = new PersonService(
                _personRepository,
                new PersonGroupRepository(_personRepository),
                permissionRepository,
                new PersonRoleRepository(),
                new PersonOptionalFieldRepository(),
                new RelationshipRepository(_personRepository),
                new ChurchMatcherRepository(),
                new GroupRepository(),
                new FamilyRepository(_photoRepository),
                _emailService,
                new AddressRepository(),
                _photoRepository
                );
        }
        public IEnumerable<string> Get()
        {
            var returnMessages = new List<string>();
            using (var pop3Client = new Pop3Client())
            {
                var messages = GetNewMessages(pop3Client);
                var messageCount = messages.Count();
                if (messageCount > 0)
                {
                    IMessageRepository messageRepository = new MessageRepository();
                    IMessageRecepientRepository messageRecepientRepository = new MessageRecepientRepository();
                    IMessageAttachmentRepository messageAttachmentRepository = new MessageAttachmentRepository();
                    IPermissionRepository permissionRepository = new PermissionRepository();
                    IChurchRepository churchRepository = new ChurchRepository();
                    IPersonRepository personRepository = new PersonRepository(permissionRepository, churchRepository);

                    var emailSender = new EmailSender(messageRepository, messageRecepientRepository, messageAttachmentRepository, personRepository);

                    foreach (var m in messages)
                    {
                        var mm = m.Value.ToMailMessage();
                        var regex = new Regex(@"##([0-9]*)##");
                        var matches = regex.Matches(mm.Body);
                        if (matches.Count > 0 && matches[0].Groups.Count > 1)
                        {
                            try
                            {
                                int messageId;
                                if (int.TryParse(matches[0].Groups[1].Value, out messageId))
                                {
                                    var originalSender = messageRepository.GetSender(messageId);
                                    if (originalSender != null)
                                    {
                                        var originalReceiver = personRepository.FetchPersonIdsFromEmailAddress(mm.From.Address, originalSender.ChurchId);
                                        var fromPersonId = originalSender.PersonId;

                                        if (originalReceiver.Any())
                                        {
                                            fromPersonId = originalReceiver.First();
                                        }
                                        returnMessages.Add(string.Format("Forwarding email on to {0}", originalSender.Email));
                                        emailSender.SendEmail(mm.Subject, mm.Body, Username, originalSender.Email, Username, Password, fromPersonId, originalSender.ChurchId, mm.Attachments);
                                    }
                                    if (!DeleteMessageByMessageId(pop3Client, m.Key))
                                    {
                                        var exception = new Exception("Cannot delete message " + mm.Subject + " " + mm.From);
                                        emailSender.SendExceptionEmailAsync(exception);
                                    }
                                    //pop3Client.DeleteMessage(count + 1);
                                }
                            }
                            catch (Exception errSending)
                            {
                                returnMessages.Add(errSending.Message);
                                emailSender.SendExceptionEmailAsync(errSending);
                            }
                        }
                    }
                }
            }
            return returnMessages;
        }
Exemplo n.º 5
0
        public string GetEmails()
        {
            var returnMessages = new List<string>();
            using (var pop3Client = new Pop3Client())
            {
                var messages = GetNewMessages(pop3Client);
                var messageCount = messages.Count();
                if (messageCount > 0)
                {
                    IMessageRepository messageRepository = new MessageRepository();
                    IMessageRecepientRepository messageRecepientRepository = new MessageRecepientRepository();
                    IMessageAttachmentRepository messageAttachmentRepository = new MessageAttachmentRepository();
                    IPermissionRepository permissionRepository = new PermissionRepository();
                    IChurchRepository churchRepository = new ChurchRepository();
                    IPersonRepository personRepository = new PersonRepository(permissionRepository, churchRepository);

                    IEmailSender emailSender = new EmailSender(messageRepository, messageRecepientRepository, messageAttachmentRepository, personRepository);

                    for (var count = 0; count < messageCount; count++)
                    {
                        var mm = messages[count].ToMailMessage();
                        var regex = new Regex(@"##([0-9]*)##");
                        var matches = regex.Matches(mm.Body);
                        if (matches.Count > 0 && matches[0].Groups.Count > 1)
                        {
                            try
                            {
                                int messageId;
                                if (int.TryParse(matches[0].Groups[1].Value, out messageId))
                                {
                                    var originalSender = messageRepository.GetSender(messageId);
                                    if (originalSender != null)
                                    {
                                        var originalReceiver = personRepository.FetchPersonIdsFromEmailAddress(mm.From.Address, originalSender.ChurchId);
                                        var fromPersonId = originalSender.PersonId;

                                        if (originalReceiver.Any())
                                        {
                                            fromPersonId = originalReceiver.First();
                                        }
                                        returnMessages.Add(string.Format("Forwarding reply from {0} for messageId {1} on to {2}", fromPersonId, messageId, originalSender.Email));
                                        emailSender.SendEmail(mm.Subject, mm.Body, Username, originalSender.Email, Username, Password, fromPersonId, originalSender.ChurchId, mm.Attachments);
                                    }
                                    pop3Client.DeleteMessage(count + 1);
                                }
                            }
                            catch (Exception errSending)
                            {
                                returnMessages.Add(errSending.Message);
                                emailSender.SendExceptionEmailAsync(errSending);
                            }
                        }
                    }
                }
            }
            if (!returnMessages.Any())
            {
                return "No replies found";
            }

            var returnMessage = returnMessages.Aggregate(string.Empty, (current, m) => current + (m + "<br/>"));
            _emailService.SendSystemEmail("Replies found", returnMessage);
            return returnMessage;
        }