Пример #1
0
        private void ProcessRowCell(UploadWizardCompleteModel model, CustomDataOrigin origin, Dictionary <int, CustomField> customFieldsDicitonary, int rowNum, DataRow row, Student student, ref bool successfulRow, ref int nonIdColumns, List <CustomFieldValue> rowCustomFieldValues, int i)
        {
            string fieldValue = row[i].ToString();

            if (!string.IsNullOrWhiteSpace(fieldValue))
            {
                nonIdColumns++;
                int integerTest;
                if (customFieldsDicitonary[i].CustomFieldType.Name.Equals("Integer") && !int.TryParse(fieldValue, out integerTest))
                {
                    successfulRow = false;
                    ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Custom field {0} on row {1} is malformed", i + 1, rowNum + 2), model);
                }
                else
                {
                    DateTime dateTest;
                    if (customFieldsDicitonary[i].CustomFieldType.Name.Equals("Date") && !DateTime.TryParse(fieldValue, out dateTest))
                    {
                        successfulRow = false;
                        ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Custom field {0} on row {1} is malformed", i + 1, rowNum + 2), model);
                    }
                    else
                    {
                        var value = new CustomFieldValue
                        {
                            CustomDataOriginId = origin.Id,
                            StudentId          = student.Id,
                            CustomFieldId      = customFieldsDicitonary[i].Id,
                            Value = fieldValue
                        };
                        rowCustomFieldValues.Add(value);
                    }
                }
            }
        }
Пример #2
0
        private void AttemptRowReadOfUploadWizardFile(int studentIdColumn, UploadWizardCompleteModel model, CustomDataOrigin origin, Dictionary <int, CustomField> customFieldsDicitonary, int numColumns, int rowNum, DataRow row, Student student)
        {
            var successfulRow = true;
            int nonIdColumns  = 0;
            List <CustomFieldValue> rowCustomFieldValues = new List <CustomFieldValue>();

            for (int i = 0; i < numColumns; i++)
            {
                if (i != studentIdColumn)
                {
                    ProcessRowCell(model, origin, customFieldsDicitonary, rowNum, row, student, ref successfulRow, ref nonIdColumns, rowCustomFieldValues, i);
                }
            }
            if (nonIdColumns == 0)
            {
                successfulRow = false;
                ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Row {0} requires an additional field to Id", rowNum + 2), model);
            }
            if (successfulRow)
            {
                model.SuccessfulRowsCount++;
                foreach (var value in rowCustomFieldValues)
                {
                    CustomFieldValueRepository.Add(value);
                }
            }
        }
Пример #3
0
        private UploadWizardCompleteModel CheckUploadErrors(EducationSecurityPrincipal user, UploadWizardModel model, DataTable dataTable)
        {
            UploadWizardCompleteModel completeModel = new UploadWizardCompleteModel();

            if (dataTable.Columns.Count != model.CustomFields.Count())
            {
                completeModel.RowErrors.Add("There is a different amount of columns in the file than listed. Please re-submit the file and try again.");
                completeModel.ProcessedRowCount = completeModel.SuccessfulRowsCount = 0;
                return(completeModel);
            }
            foreach (var field in model.CustomFields)
            {
                if (field.SelectedCustomFieldId != 0)
                {
                    IPermission customFieldPermission = PermissionFactory.Current.Create("UploadCustomFieldData", CustomFieldRepository.Items.Single(c => c.Id == field.SelectedCustomFieldId));
                    if (!customFieldPermission.TryGrantAccess(user))
                    {
                        completeModel.RowErrors.Add("You don't have access to one or more of the selected custom fields. Re-submit and try again.");
                        completeModel.ProcessedRowCount = completeModel.SuccessfulRowsCount = 0;
                        return(completeModel);
                    }
                }
            }
            return(completeModel);
        }
Пример #4
0
        private void CreateErrorDownloadFile(EducationSecurityPrincipal user, UploadWizardCompleteModel model)
        {
            var writer = new DataFileWriter();

            model.ErrorDownloadFile = new DownloadFileModel
            {
                BlobAddress = string.Format("DataFileWizardUploadErrors-{0}-{1}.txt", user.Identity.User.DisplayName, DateTime.Now.Ticks),
                FileName    = string.Format("{0}-ErrorRows-{1}.txt", user.Identity.User.DisplayName, DateTime.Now.Ticks),
            };
            writer.BuildTemplate(model.RowErrorValues);
            writer.Write(DataFileBlobContainer, model.ErrorDownloadFile.BlobAddress);
        }
Пример #5
0
        private void ProcessError(DataRow row, string rowError, UploadWizardCompleteModel model)
        {
            var rowValue = string.Empty;

            for (int i = 0; i < row.ItemArray.Count(); i++)
            {
                rowValue += row[i].ToString() + '\t';
            }
            if (rowValue.Length > 0)
            {
                rowValue = rowValue.Remove(rowValue.Length - 1);
            }
            model.RowErrorValues.Add(rowValue);
            model.RowErrors.Add(rowError);
        }
Пример #6
0
 private void HandleRowErrors(EducationSecurityPrincipal user, UploadWizardCompleteModel model, Dictionary <int, CustomField> customFieldsDicitonary)
 {
     if (model.RowErrors.Count > 0)
     {
         var headers = string.Empty;
         foreach (var field in customFieldsDicitonary)
         {
             headers += (field.Value != null) ? field.Value.Name + '\t' : "Student Id\t";
         }
         if (headers.Length > 0)
         {
             headers = headers.Remove(headers.Length - 1);
         }
         model.RowErrorValues.Insert(0, headers);
         CreateErrorDownloadFile(user, model);
     }
 }
Пример #7
0
        private void ProcessRows(EducationSecurityPrincipal user, int studentIdColumn, DataTable dataTable, UploadWizardCompleteModel completeModel, CustomDataOrigin origin, Dictionary <int, CustomField> customFieldsDicitonary)
        {
            int numColumns = dataTable.Columns.Count;

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                var row = dataTable.Rows[i];
                if (row.HasErrors)
                {
                    ProcessError(row, string.Format(CultureInfo.CurrentCulture, "Row {0} failed to process.  {1}", i + 2, row.RowError), completeModel);
                }
                else
                {
                    var studentId = row[studentIdColumn].ToString();
                    var student   = StudentRepository.Items.Include("StudentAssignedOfferings.ServiceOffering.Provider").
                                    SingleOrDefault(s => s.StudentSISId == studentId);
                    if (student == null || !PermissionFactory.Current.Create("ProcessDataFile", student).TryGrantAccess(user))
                    {
                        ProcessError(row, string.Format(CultureInfo.CurrentCulture, "You do not have permission to interact with the referenced student on row {0}", i + 2), completeModel);
                    }
                    else
                    {
                        AttemptRowReadOfUploadWizardFile(studentIdColumn, completeModel, origin, customFieldsDicitonary, numColumns, i, row, student);
                    }
                }
                completeModel.ProcessedRowCount++;
            }
        }