public async Task GetEmployeeSearch() { //Arrange var input = new EmployeeSearchDatabaseInput() { SearchedEmployeeUserName = "******" }; //Act var result = await _projectManagerRepository.GetEmployeeSearch(input); //Assert Assert.NotNull(result); }
public async Task <IActionResult> GetEmployeeSearch(EmployeeSearchInput input) { if (TempData.Peek("userName") == null) { return(UserNotAllowedAccess(isUserLoggedIn: false)); } if (TempData.Peek("userRole").ToString() == "Employee") { return(UserNotAllowedAccess(isUserLoggedIn: true)); } //return the model state if the request is invalid if (!ModelState.IsValid) { List <string> errors = ModelState.Values.SelectMany(p => p.Errors.Select(x => x.ErrorMessage)).ToList(); TempData.Add("EmployeeSearchInvalid", errors); return(RedirectTo("ProjectManager", "EmployeeSearch")); } var databaseInput = new EmployeeSearchDatabaseInput() { SearchedEmployeeUserName = input.SearchedEmployee }; //define the output outside of the try catch block EmployeeSearchOutput employeeSearchResult; try { //this is just a stub for now employeeSearchResult = await _IProjectManagerDomain.GetEmployeeSearch(databaseInput); employeeSearchResult.ChartData = employeeSearchResult.getCapacityForChart(); if (employeeSearchResult.IsOverCapacity) { TempData.Add("IsOverCapacity", "Warning: Thie employee is over capacity."); } } catch (Exception) { TempData.Add("NoEmployeeFound", $"The User Name you entered, {input.SearchedEmployee}, was either incorrect, does not exist in the system, or has no associated data in the system. Please verify the User Name is correct and and try again."); return(RedirectTo("ProjectManager", "EmployeeSearch")); } //return the View and pass in the Model return(View(employeeSearchResult)); }
public async Task <EmployeeSearchOutput> GetEmployeeSearch(EmployeeSearchDatabaseInput input) { //create the DyanmicParamter object to hold our input for the sproc var p = new DynamicParameters(); //Add the sproc input params to p p.Add("@p_UserName", input.SearchedEmployeeUserName); //define your result outside of the using block EmployeeSearchOutput result; using (IDbConnection connection = new SqlConnection(_connectionString)) { //using Dapper execute the "sp_EmployeeSearch" sproc result = await connection.QueryFirstAsync <EmployeeSearchOutput>("sp_EmployeeSearch", p, commandType : CommandType.StoredProcedure); } //return the sproc result return(result); }
public async Task <EmployeeSearchOutput> GetEmployeeSearch(EmployeeSearchDatabaseInput input) { return(await _IProjectManagerRepository.GetEmployeeSearch(input)); }