public IActionResult EditClinicianCredentials(string previousHCPId, string HCPId, string password) { if (!Clinician.IsValidHCPId(HCPId)) { return(PartialView("_StatusMessagePartial", new Tuple <bool, string>(false, $"Could not update Clinician, HCP ID: {HCPId} is not valid."))); } if (!Clinician.IsValidPassword(password)) { return(PartialView("_StatusMessagePartial", new Tuple <bool, string>(false, $"Could not update Clinician, Password: {password} is not valid."))); } if (ClinicianProcessor.UpdateClinician(previousHCPId, HCPId, password) == 1) { return(PartialView("_StatusMessagePartial", new Tuple <bool, string>(true, $"Successfully updated Clinician."))); } return(PartialView("_StatusMessagePartial", new Tuple <bool, string>(false, $"Could not update Clinician, a Clinician already exists with HCP ID: {HCPId}."))); }
public static List <string> GetClinicianCredentials(IFormFile formFile, out List <Clinician> clinicians) { List <string> errorMessages = new List <string>(); clinicians = new List <Clinician>(); using (StreamReader streamReader = new StreamReader(formFile.OpenReadStream())) { int lineCount = 0; while (streamReader.Peek() > 0) { // Track the line count for error messages lineCount++; var line = streamReader.ReadLine(); // TODO: Move the replacement of whitespace around var noWhiteSpaceLine = line.Replace(" ", string.Empty); // If the line was only white spaces, the string will now be of length 0 if (noWhiteSpaceLine.Length == 0) { continue; } var commaSeparatedValues = noWhiteSpaceLine.Split(','); if (commaSeparatedValues.Length == 1) { errorMessages.Add($"Error Importing Clinician at Line {lineCount}. \n" + $"No comma found"); continue; } if (commaSeparatedValues.Length > 2) { errorMessages.Add($"Error Importing Clinician at Line {lineCount}. \n" + $"Too many commas"); continue; } bool valid = true; foreach (var value in commaSeparatedValues) { if (!value.All(c => char.IsLetterOrDigit(c))) { errorMessages.Add($"Error Importing Clinician at Line {lineCount}. \n " + $"Non AlphaNumeric character found"); valid = false; break; } } if (!valid) { continue; } if (!Clinician.IsValidHCPId(commaSeparatedValues[0])) { errorMessages.Add($"Error Importing Clinician at Line {lineCount}. \n " + $"Clinician HCP ID is not valid"); continue; } if (!Clinician.IsValidPassword(commaSeparatedValues[1])) { errorMessages.Add($"Error Importing Clinician at Line {lineCount}. \n " + $"Clinician Password is not valid"); continue; } clinicians.Add( new Clinician { HCPId = commaSeparatedValues[0], ClinicianPassword = commaSeparatedValues[1] } ); } } return(errorMessages); }