public bool ValidateRecord(string record) { bool result = true; string[] recordFields = record.Split(','); result = isDepartmentNameValid(recordFields[0]); if (result) { result = isCrewCodeValid(recordFields[1]); } if (result) { result = isEmployeeNameValid(recordFields[2]); } if (result) { result = isStatusValid(recordFields[3]); } if (result) { result = isEmployeeNumberValid(recordFields[4]); } if (result) { result = isRoleTypeValid(recordFields[5]); } if (result) { result = isSeniorityDateValid(recordFields[6]); } if (result) { result = isSupervisorNameValid(recordFields[7], recordFields[5]); } if (result) { result = isSupervisorNumberValid(recordFields[4], recordFields[8], recordFields[5]); } if (result) { DataFileRecordModel dataFileModel = CreateDataFileRecordModel(record); if (isDuplicatedRecord(recordFields[4])) { DuplicatedRecords.Add(dataFileModel); } else { ValidRecords.Add(dataFileModel); } } else { InvalidRecords.Add(record); } return(result); }
public List <Employee> CreateEmployeesFromRecords(List <DataFileRecordModel> records) { List <Employee> employees = new List <Employee>(); List <Department> allDistinctDepartments = _dal.GetAllDistinctDepartments(); List <RoleType> allDistinctRoleTypes = _dal.GetAllDistinctRollTypes(); List <Crew> allDistinctCrews = _dal.GetAllDisctinctCrews(); foreach (var record in records) { try { Employee employee = new Employee() { name = record.employee_name, department_id = allDistinctDepartments.Where(d => d.department_name == record.DepartmentName).SingleOrDefault().department_id, employee_num = record.Employee_num, status = (record.Status == Statuses.Active) ? (true) : (false), seniority_date = Convert.ToDateTime(record.SeniorityDate), roletype_id = allDistinctRoleTypes.Where(r => r.roletype_name == record.Role).SingleOrDefault().roletype_id, crew_id = allDistinctCrews.Where(c => c.crew_code == record.Crew_Code).SingleOrDefault().crew_id, supervisor_id = _dal.GetEmployeeIdForEmployeeNumber(record.Supervisor_num) }; employees.Add(employee); } catch { // TODO: This needs to get fixed! InvalidRecords.Add(record.ToString()); } } return(employees); }
public void ValidateUnnassignedVariants(ConcurrentDictionary <string, List <Product> > unnassignedVariants) { if (unnassignedVariants.Count != 0) { foreach (var kvp in unnassignedVariants) { var errors = new List <string>(); foreach (var variant in kvp.Value) { errors.Add($"Item {variant.Id} was added but parent {kvp.Key} was never added"); } InvalidRecords.Add(kvp.Key, errors); } } }
public void ValidateProduct(Product product) { var errors = new List <string>(); var priceErrors = ValidatePrices(product); errors.AddRange(priceErrors); if (string.IsNullOrWhiteSpace(product.ParentId) && product.Variants.Count == 0 && product.Prices.Count == 0) { errors.Add("Product has no parent, no variants and no price. A product must have a price or must be a parent with variants."); } if (errors.Count != 0) { InvalidRecords.Add(product.Id, errors); } }