Example #1
0
        public void Execute(int serviceDeskId, IReadOnlyCollection <TemplateDomainListItem> selectedDomains)
        {
            using (var dbConnection = _unitOfWork.CreateConnection())
            {
                try
                {
                    // Open the connection and begin a transaction
                    dbConnection.Open();
                    _repositoryTransaction = _unitOfWork.BeginTransaction();

                    foreach (var selectedDomain in selectedDomains)
                    {
                        var templateRows = _templateRowRepository.All().Where(x => x.TemplateId == selectedDomain.TemplateId && x.ServiceDomain == selectedDomain.DomainName).ToList();
                        _transformTemplateToDesign.Transform(serviceDeskId, templateRows);
                    }

                    Save();
                }
                catch (Exception)
                {
                    // If we have a transaction then roll it back
                    Rollback();

                    // Throw the exception
                    throw;
                }
            }
        }
        public void Execute(string serviceDecompositionFilePath, string filename, int serviceDeskId)
        {
            if (serviceDecompositionFilePath == null)
            {
                throw new ArgumentNullException(nameof(serviceDecompositionFilePath));
            }

            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }

            if (!File.Exists(serviceDecompositionFilePath))
            {
                throw new FileNotFoundException(serviceDecompositionFilePath);
            }

            // Read the contents of Service Decomposition spreadsheet (This will have been uploaded via the Web UI)
            var importResults = _serviceDecompositionTemplateImporter.ImportSpreadsheet(serviceDecompositionFilePath);


            if (importResults.ValidationResults.Count > 0)
            {
                throw new DataImportException(
                          $"Error reading Service Decomposition Template spreadsheet ({filename}) - ", importResults.ValidationResults);
            }

            if (importResults.Results.Count == 0)
            {
                throw new DataImportException(
                          $"Error reading Service Decomposition Template spreadsheet ({filename}) - Spreadsheet does not contain any valid data.");
            }

            using (var dbConnection = _unitOfWork.CreateConnection())
            {
                try
                {
                    // Open the connection and begin a transaction
                    dbConnection.Open();
                    _repositoryTransaction = _unitOfWork.BeginTransaction();

                    _serviceDeskService.Clear(serviceDeskId);

                    _transformTemplateToDesign.Transform(serviceDeskId, importResults.AsTemplateRows());

                    Save();
                }
                catch (Exception)
                {
                    // If we have a transaction then roll it back
                    Rollback();

                    // Throw the exception
                    throw;
                }
            }
        }