public ValidationResult InputFileValidate(InputFile input)
        {
            if (input == null) throw new ArgumentNullException("input");
            var result = new ValidationResult();

            //validate header
            if (input.Header == null || !input.Header.Any())
            {
                result.ValidationErrors.Add(new ValidationError("Header",
                    "Header is missing. Please use approved template!"));
                return result;
            }

            IRow descritpionRow = input.Header.Last();
            foreach (var headerValue in _headerValues)
            {
                ICell cell = descritpionRow.GetCell(headerValue.Value == CellPosition.First ? descritpionRow.FirstCellNum : (descritpionRow.LastCellNum - 1), MissingCellPolicy.CREATE_NULL_AS_BLANK);
                cell.SetCellType(CellType.String);
                if (!headerValue.Key.InvariantEquals(cell.StringCellValue.Trim()))
                {
                    result.ValidationErrors.Add(new ValidationError("Header",
                        "Invalid file structure. Please use approved template!"));
                    return result;
                }
            }

            // validate min allowed
            if (input.Data == null || !input.Data.Any())
            {
                result.ValidationErrors.Add(new ValidationError("Data",
                    "No records provided. At least one Product required to initiate upload!"));
                return result;
            }

            //Validate max allowed
            int maxWarehouseRows = _maxBatchSize;
            int actualWarehouseRows = input.Data.Count;
            if (actualWarehouseRows > maxWarehouseRows)
            {
                result.ValidationErrors.Add(new ValidationError("MaxRows",
                    string.Format(
                        "Batch size has been exceeded. Maximum allowed size is {0} rows, file provided has: {1} rows",
                        maxWarehouseRows, actualWarehouseRows)));
                return result;
            }

            return result;
        }
 public ValidationResult FileFormatValidate(string input)
 {
     if (input == null) throw new ArgumentNullException("input");
     var result = new ValidationResult();
     if (!input.Contains("vnd.openxmlformats-officedocument.spreadsheetml.sheet") &&
         !input.Contains("application/octet-stream"))
     {
         result.ValidationErrors.Add(new ValidationError("Format", input + " format is not supported!"));
     }
     return result;
 }
Beispiel #3
0
 public ResultBase(UserContext userContext)
 {
     if (userContext == null) throw new ArgumentNullException("userContext");
     ValidationResult = new ValidationResult();
     UserContext = userContext;
 }