示例#1
0
        public ApiResponse <DataConnectionModel> Get([FromRoute] Guid packageId, [FromRoute] Guid id)
        {
            // Create the response object
            ApiResponse <DataConnectionModel> response = new ApiResponse <DataConnectionModel>();

            try
            {
                // Did we find a package?
                Package package = SessionHandler.PackageRepository.Get(packageId);
                if (package != null)
                {
                    // Was an id passed in? If not just return everything
                    response.Data = mapper.Map <DataConnectionModel>(
                        package.DataConnections.Where
                            (def => (id == Guid.Empty || def.Id == id)).FirstOrDefault()
                        );

                    // Fill in the blanks
                    response.Data = ConnectionApiHelper.PopulateModel(mapper, package, response.Data);
                }

                // Success as we got here
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Data    = null;  // Clear the data as we don't want to send back partial data
                response.Success = false; // Failed due to hard failure
            }

            // Return the response object
            return(response);
        }
        public void Populate_ConnectionModel()
        {
            // Arrange
            Guid credentialsId = Guid.NewGuid(); // Set the fixed id of the credentials

            // Create a new package to pick the credentials up from in the populate routine
            Package package = new Package()
            {
                CredentialsStore = new List <Credentials>()
                {
                    new Credentials()
                    {
                        Id = credentialsId, Name = "Dummy Credentials"
                    }
                }
            };

            // Create a new connection model without the populated fields
            DataConnectionModel model = new DataConnectionModel()
            {
                Credentials =
                    new KeyValuePair <Guid, string>
                        (credentialsId, String.Empty),
                ProviderType = (Int32)DataProviderType.SQLProvider
            };

            // Set up the mapper to map any needed objects
            AutoMapperProfile.Initialise();
            IMapper mapper = new Mapper(Mapper.Configuration);

            // Act
            model = ConnectionApiHelper.PopulateModel(mapper, package, model);

            // Assert
            Assert.True(model.Credentials.Value != String.Empty);
            Assert.True(model.ProviderData != null);
        }
示例#3
0
        public ApiResponse <DataConnectionModel> Post([FromRoute] Guid packageId, [FromBody] DataConnectionModel request)
        {
            // Create the response object
            ApiResponse <DataConnectionModel> response = new ApiResponse <DataConnectionModel>();

            // Map the model to a domain object type
            DataConnection savedConnection = mapper.Map <DataConnection>(request);

            // Did the mapping work ok?
            if (savedConnection != null)
            {
                // Did we find a package?
                Package package = SessionHandler.PackageRepository.Get(packageId);
                if (package != null)
                {
                    // Get the repository to save the package for us
                    savedConnection = package.Save <DataConnection>(savedConnection);
                }

                // Saved ok?
                if (savedConnection != null)
                {
                    // Map the connection back to a model type and send it back to the user
                    response.Data = mapper.Map <DataConnectionModel>(savedConnection);

                    // Fill in the blanks
                    response.Data = ConnectionApiHelper.PopulateModel(mapper, package, response.Data);
                }

                // Nothing died .. Success
                response.Success = true;
            }

            // Send the response back
            return(response);
        }