Exemple #1
0
        public void AddServiceToUserOffice(UserOffice userOffice, string serviceTypeName)
        {
            var serviceProvider = _serviceProviderRepository.GetByType(serviceTypeName);

            if (serviceProvider != null)
            {
                var service = _userServiceRepository.GetSingle(
                    x => x.UserOfficeId.Equals(userOffice.Id) && x.ServiceProvider.Id.Equals(serviceProvider.Id)) ??
                              _userServiceRepository.Create(new UserService
                {
                    ServiceProviderId = serviceProvider.Id,
                    UserOfficeId      = userOffice.Id
                });

                var serviceProviderSettings = (ServiceProviderSettings)_appSettings.Value.ServiceProviderTypeSettings.GetType()
                                              .GetProperty(serviceTypeName)
                                              .GetValue(_appSettings.Value.ServiceProviderTypeSettings);

                if (serviceProviderSettings.UserData != null)
                {
                    foreach (var pair in serviceProviderSettings.UserData)
                    {
                        var userServiceData =
                            _userServiceDataRepository.GetSingle(
                                x => x.UserServiceId.Equals(service.Id) && x.Key.Equals(pair.Key));
                        if (userServiceData == null)
                        {
                            _userServiceDataRepository.Create(new UserServiceData
                            {
                                Key           = pair.Key,
                                Value         = string.IsNullOrEmpty(pair.Value) ? null : pair.Value,
                                UserServiceId = service.Id
                            });
                        }
                        else if (userServiceData.Value != pair.Value && string.IsNullOrEmpty(userServiceData.Value))
                        {
                            userServiceData.Value = pair.Value;
                            _userServiceDataRepository.Update(userServiceData);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public IActionResult GetServiceData(string userId, string serviceTypeName, string dataKey)
        {
            var response = new ApiResponseModel();

            var userOffice = _userOfficeRepository.GetSingle(x => x.UserId.Equals(userId));

            if (userOffice == null)
            {
                return(NotFound(response));
            }

            var service = _userOfficeManager.GetUserService(userOffice, serviceTypeName);
            var data    =
                _userServcieDataRepository.GetSingle(x => x.UserServiceId.Equals(service.Id) && x.Key == dataKey);

            if (data == null)
            {
                return(NotFound(response));
            }

            response.Data.Add("Data", data.Value);
            return(Ok(response));
        }