public override User Create(ImportRow row) { // use either employee id or login, and add digits after login to create a unique id string id = null; if (row.Has(UserColumnMappingTargets.EmployeeId)) { id = Document.For <User>((string)row[UserColumnMappingTargets.EmployeeId]); var dupe = Users.TryGet(id); if (null != dupe) { row.Problems.Add("There is already an employee with this EmployeeId, '" + id + "'."); return(null); } } else if (row.Has(UserColumnMappingTargets.Login)) { id = Document.For <User>((string)row[UserColumnMappingTargets.EmployeeId]); var dupe = Users.TryGet(id); while (null != dupe) { if (id.Length > 2 && char.IsDigit(id[id.Length - 1]) && '-' == id[id.Length - 2]) { id = id.Substring(id.Length - 1) + (int.Parse(id[id.Length - 1].ToString()) + 1); } else { id += "-1"; } dupe = Users.TryGet(id); } } else { row.Problems.Add("Row has neither EmployeeId nor Login."); } return(new User { Document = new Document { Id = id }, EmployeeId = (string)row[UserColumnMappingTargets.EmployeeId], Login = (string)row[UserColumnMappingTargets.Login], State = UserState.Registered, }); }
public override void ValidateRow(ImportRow row) { // employee id is required if its on the sheet. if (row.Has(UserColumnMappingTargets.EmployeeId) && String.IsNullOrEmpty((string)row[UserColumnMappingTargets.EmployeeId])) { row.AddProblem("Row has an empty EmployeeId column. EmployeeId is an optional column, but if part of the upload sheet, it must be filled."); } // login is also required if on the sheet if (row.Has(UserColumnMappingTargets.Login) && String.IsNullOrEmpty((string)row[UserColumnMappingTargets.Login])) { row.AddProblem("Row has an empty Login value. Login is a required field."); } }
public override User Find(ImportRow row) { // search by employee id first if (row.Has(UserColumnMappingTargets.EmployeeId)) { return(Users.FindUserByEmployeeId((string)row[UserColumnMappingTargets.EmployeeId])); } // search by login next if (row.Has(UserColumnMappingTargets.Login)) { return(Users.FindUserByLogin((string)row[UserColumnMappingTargets.Login])); } row.AddProblem("Import contains neither EmployeeId nor Login."); return(null); }
public override Product Find(ImportRow row) { // search by employee id first if (row.Has(ProductColumnMappingTargets.ProductId)) { return(Products.FindByProductId((string)row[ProductColumnMappingTargets.ProductId])); } row.AddProblem("Import contains no ProductId."); return(null); }