예제 #1
0
        public IHttpActionResult GetProfileImage(Int32 contactId)
        {
            var token = _apiUserService.GetToken();
            var files = _mpService.GetFileDescriptions("Contacts", contactId, token);
            var file  = files.FirstOrDefault(f => f.IsDefaultImage);

            return(file != null?
                   GetImage(file.FileId, file.FileName, token) :
                       (RestHttpActionResult <ApiErrorDto> .WithStatus(HttpStatusCode.NotFound, new ApiErrorDto("No matching image found"))));
        }
        public Organization GetOrganizationByName(string name)
        {
            var apiUserToken = _mpApiUserService.GetToken();
            var org          = new Organization();
            var mpOrg        = _mpOrganizationService.GetOrganization(name, apiUserToken);

            if (mpOrg != null)
            {
                return(org.FromMpOrganization(mpOrg));
            }
            return(null);
        }
예제 #3
0
        public BulkEmailSyncService(
            MPInterfaces.IBulkEmailRepository bulkEmailRepository,
            MPInterfaces.IApiUserRepository apiUserService,
            IConfigurationWrapper configWrapper)
        {
            _bulkEmailRepository = bulkEmailRepository;
            _apiUserService      = apiUserService;
            _configWrapper       = configWrapper;

            _token = _apiUserService.GetToken();

            ConfigureRefreshTokenTimer();
        }
예제 #4
0
        public Person GetPerson(int contactId)
        {
            var contact = _contactService.GetContactById(contactId);
            var person  = Mapper.Map <Person>(contact);

            var family = _contactService.GetHouseholdFamilyMembers(person.HouseholdId);

            person.HouseholdMembers = family;

            // TODO: Should this move to _contactService or should update move it's call out to this service?
            var apiUser         = _apiUserService.GetToken();
            var configuration   = MpObjectAttributeConfigurationFactory.Contact();
            var attributesTypes = _objectAttributeService.GetObjectAttributes(apiUser, contactId, configuration);

            person.AttributeTypes   = attributesTypes.MultiSelect;
            person.SingleAttributes = attributesTypes.SingleSelect;

            return(person);
        }
예제 #5
0
        public void AutoCompleteTasks()
        {
            try
            {
                var apiUserToken    = _apiUserService.GetToken();
                var tasksToComplete = _taskRepository.GetTasksToAutostart();

                _logger.InfoFormat("Number of tasks to autocomplete: {0} ", tasksToComplete.Count);

                foreach (var task in tasksToComplete)
                {
                    _logger.InfoFormat("Inside of tasks to complete Loop");

                    var user = _userService.GetUserByRecordId(task.Assigned_User_ID);

                    _logger.InfoFormat("User Record ID for task to complete: {0}", user.UserRecordId);
                    _logger.InfoFormat("Task ID for task to complete: {0}", task.Task_ID);

                    try
                    {
                        _impersonationService.WithImpersonation(apiUserToken,
                                                                user.UserEmail,
                                                                () =>
                        {
                            _taskRepository.CompleteTask(apiUserToken, task.Task_ID, task.Rejected, "Auto Completed");
                            return(true);
                        });
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorFormat("Auto complete task failed for Task {0} Detail: {1}", task.Task_ID, ex);
                    }
                }
            }
            catch (Exception outerException)
            {
                _logger.ErrorFormat("Could not process tasks for autocomplete, Detail: {0}", outerException);
            }
        }
예제 #6
0
        public void SaveObjectAttributes(int objectId,
                                         Dictionary <int, ObjectAttributeTypeDTO> objectAttributes,
                                         Dictionary <int, ObjectSingleAttributeDTO> objectSingleAttributes, MpObjectAttributeConfiguration configuration)
        {
            var currentAttributes = TranslateMultiToMPAttributes(objectAttributes);

            currentAttributes.AddRange(TranslateSingleToMPAttribute(objectSingleAttributes));

            if (objectAttributes == null)
            {
                return;
            }

            var apiUserToken = _apiUserService.GetToken();

            var persistedAttributes = _mpObjectAttributeService.GetCurrentObjectAttributes(apiUserToken, objectId, configuration);
            var attributesToSave    = GetDataToSave(currentAttributes, persistedAttributes);

            foreach (var attribute in attributesToSave)
            {
                SaveAttribute(objectId, attribute, apiUserToken, configuration);
            }
        }
예제 #7
0
 private void RefreshTokenTimerElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
 {
     _logger.Info("Refreshing token");
     _token = _apiUserService.GetToken();
 }
예제 #8
0
        public OptInResponse AddListSubscriber(string emailAddress, string listName)
        {
            var token = _apiUserService.GetToken();

            return(_emailListHandler.AddListSubscriber(emailAddress, listName, token));
        }
예제 #9
0
        public List <MpAttribute> CreateMissingAttributes(List <MpAttribute> attributes, int attributeType)
        {
            var attributesToSearch = attributes.Select(a => $"(Attribute_Name='{a.Name.Replace("'", "''")}' AND Attribute_Category_Id={a.CategoryId})");

            string searchFilter = $"Attribute_Type_ID={attributeType} AND (" + String.Join(" OR ", attributesToSearch) + ")";

            var foundNames = _ministryPlatformRestRepository.UsingAuthenticationToken(_apiUserRepository.GetToken()).Search <MpRestAttribute>(searchFilter, "Attribute_ID, Attribute_Name, ATTRIBUTE_CATEGORY_ID");

            foreach (var attribute in attributes)
            {
                if (foundNames.Count(a => String.Equals(a.Name, attribute.Name, StringComparison.CurrentCultureIgnoreCase) && a.CategoryId == attribute.CategoryId) > 0)
                {
                    attribute.AttributeId = foundNames.First(foundAttribute => String.Equals(foundAttribute.Name, attribute.Name, StringComparison.CurrentCultureIgnoreCase) &&
                                                             foundAttribute.CategoryId == attribute.CategoryId).AttributeId;
                }
                else
                {
                    attributes.First(a => a.Name == attribute.Name && a.CategoryId == attribute.CategoryId)
                    .AttributeId = _attributeRepository.CreateAttribute(attribute);
                }
            }

            return(attributes);
        }