public void TestGetUploadDataModel()
        {
            var model = new UploadSimpleRowParser(GetValidRow()).GetUploadDataModel(GetSimpleUpload());

            AssertSimpleUploadPropertiesCopiedOk(model);
            AssertRowValuesParsedOk(model, count, lowerCI, upperCI, denominator);
        }
 public void TestAreaCode()
 {
     var rows = Rows(UploadColumnNames.AreaCode, typeof(string));
     rows.Add(areaCode);
     var parser = new UploadSimpleRowParser(rows[0]);
     Assert.AreEqual(areaCode, parser.AreaCode);
 }
        public static void UpdateNumberOfRowsInFile(UploadJob job, DataTable dataTable, UploadJobRepository repository,
            bool isSimpleUpload)
        {
            var rowCount = 0;

            if (isSimpleUpload)
            {
                for (var i = 0; i < dataTable.Rows.Count; i++)
                {
                    var row = dataTable.Rows[i];
                    var rowParser = new UploadSimpleRowParser(row);

                    if (rowParser.DoesRowContainData == false)
                    {
                        break;
                    }

                    rowCount++;
                }
            }
            else
            {
                rowCount = dataTable.Rows.Count;
            }

            job.TotalRows = rowCount;
            repository.UpdateJob(job);


        }
        public DataTable RemoveDuplicatesInSimple(DataTable pholioData)
        {
            var simpleUpload = new SimpleUpload();
            var dataToBeUploaded = new List<UploadDataModel>();

            for (var i = 0; i < pholioData.Rows.Count; i++)
            {
                var row = pholioData.Rows[i];
                var rowParser = new UploadSimpleRowParser(row);

                if (rowParser.DoesRowContainData == false)
                {
                    //There isn't an area code or value so assume the end of the data 
                    break;
                }

                var uploadDataModel = rowParser.GetUploadDataModelWithUnparsedValuesSetToDefaults(simpleUpload);
                dataToBeUploaded.Add(uploadDataModel);
            }

            // Remove the duplicate
            var noDupData =
                        dataToBeUploaded.GroupBy(
                            x =>
                                new
                                {
                                    x.AreaCode
                                })
                            .Select(y => y.First())
                            .ToList();

            // Create new table without duplicats            
            var table = new DataTable();
            table.Columns.Add("AreaCode", typeof(string));
            table.Columns.Add("Count", typeof(double));
            table.Columns.Add("Value", typeof(double));
            table.Columns.Add("LowerCI", typeof(double));
            table.Columns.Add("UpperCI", typeof(double));
            table.Columns.Add("Denominator", typeof(double));
            table.Columns.Add("ValueNoteId", typeof(double));

            foreach (var data in noDupData)
            {
                table.Rows.Add(data.AreaCode, data.Count, data.Value, data.LowerCi, data.UpperCi, data.Denominator,
                    data.ValueNoteId);
            }
            return table;
        }
        public SimpleUpload UploadData(DataTable indicatorDetails, DataTable pholioData, UploadJob job)
        {
            var simpleUpload = new SimpleUpload();
            var rowCount = 0;

            var allowedData = new AllowedData(_profilesReader);

            // TODO: find out why were are calling it again here as its caled in Validate()
            ValidateIndicatorDetails(indicatorDetails, simpleUpload, allowedData);

            var dataToUpload = new List<UploadDataModel>();

            for (int i = 0; i < pholioData.Rows.Count; i++)
            {
                DataRow row = pholioData.Rows[i];
                var rowParser = new UploadSimpleRowParser(row);

                if (rowParser.DoesRowContainData == false)
                {
                    //There isn't an area code or value so assume the end of the data  
                    break;
                }

                rowCount++;

                var upload = rowParser.GetUploadDataModelWithUnparsedValuesSetToDefaults(simpleUpload);
                _coreDataRepository.InsertCoreData(upload.ToCoreDataSet(), job.Guid);
                dataToUpload.Add(upload);
            }

            simpleUpload.DataToUpload = dataToUpload;

            int uploadId = _loggingRepository.InsertUploadAudit(job.Guid, job.Username,
                rowCount, job.Filename, WorksheetNames.SimplePholio);

            simpleUpload.ShortFileName = Path.GetFileName(job.Filename);
            simpleUpload.TotalDataRows = rowCount;
            simpleUpload.UploadBatchId = job.Guid;
            simpleUpload.Id = uploadId;

            return simpleUpload;
        }
        private void ValidateSpreadsheetRows(DataTable excelData, SimpleUpload simpleUpload, AllowedData allowedData)
        {
            simpleUpload.ColumnsCount = excelData.Columns.Count;
            simpleUpload.TotalDataRows = excelData.Rows.Count - 1;

            List<string> allAreaCodes = allowedData.AreaCodes;

            for (int i = 0; i < excelData.Rows.Count; i++)
            {
                DataRow row = excelData.Rows[i];
                var rowParser = new UploadSimpleRowParser(row);

                if (rowParser.DoesRowContainData == false)
                {
                    //There isn't an area code or value so assume the end of the data and stop validating now...   
                    break;
                }

                List<UploadValidationFailure> rowErrors = ValidateUploadedRow(row, i + 2, allAreaCodes);
                if (rowErrors.Count == 0)
                {
                    UploadDataModel upload = rowParser.GetUploadDataModel(simpleUpload);
                    upload.RowNumber = i + 1;
                    simpleUpload.DataToUpload.Add(upload);
                }
                else
                {
                    foreach (UploadValidationFailure error in rowErrors)
                        simpleUpload.UploadValidationFailures.Add(error);
                }

                simpleUpload.TotalDataRows = i + 1;
            }
        }