public async Task AssignProject(AssignProjectToEmployeeDatabaseInput input) { var p = new DynamicParameters(); p.Add("@p_AssignedEmployeeUserName", input.AssignedUserName); p.Add("@p_AssignedProjectName", input.AssignedProjectName); p.Add("@p_Capacity", input.Capacity); p.Add("@p_CreateUser", input.CreateUser); var validUserNameAndProject = new DynamicParameters(); validUserNameAndProject.Add("@p_UserName", input.AssignedUserName); validUserNameAndProject.Add("@p_ProjectName", input.AssignedProjectName); using (IDbConnection connection = new SqlConnection(_connectionString)) { bool isValid = false; isValid = await connection.QueryFirstAsync <bool>("sp_IsAssignAProjectInputValid", validUserNameAndProject, commandType : CommandType.StoredProcedure); if (!isValid) { throw new AssignAProjectException("Either the UserName or ProjectName you entered is invalid. Please try again"); } await connection.ExecuteAsync("sp_AssignProjectToEmployee", p, commandType : CommandType.StoredProcedure); } }
/// <summary> /// This method will return the View where there project manager /// can save a project assignment /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <IActionResult> SaveProjectAssignment(WorkHourTracker.Web.Models.AssignProjectInput input) { if (TempData.Peek("userName") == null) { return(UserNotAllowedAccess(isUserLoggedIn: false)); } if (TempData.Peek("userRole").ToString() == "Employee") { return(UserNotAllowedAccess(isUserLoggedIn: true)); } //if the ModelState is invalid return the user to the AssignProject page and show them the validation errors if (!ModelState.IsValid) { List <string> errors = ModelState.Values.SelectMany(p => p.Errors.Select(x => x.ErrorMessage)).ToList(); TempData.Add("AssignProjectInvalid", errors); return(RedirectTo("ProjectManager", "AssignProject")); } // Create a WorkHourTrackerListResult object and initializes its properties var resultList = new WorkHourTrackerListResult() { Errors = new List <string>(), WorkHourTrackList = new List <dynamic>() }; // Since ViewModel input is valid, transform it into the DTO to transfer to other layers var databaseInput = new AssignProjectToEmployeeDatabaseInput(input.AssignedProjectName, input.AssignedUserName, input.Capacity, TempData.Peek("userName").ToString()); try { await _IProjectManagerDomain.AssignProject(databaseInput); resultList.Errors.Add("The project has been successfully assigned!"); TempData.Add("AssignedProjectSuccess", resultList.Errors); } catch (AssignAProjectException ex) { resultList.Errors.Add(ex.Message); TempData.Add("AssignedProjectError", resultList.Errors); } catch (Exception) { throw; } return(RedirectTo("ProjectManager", "AssignProject")); }
public async Task AssignProject(AssignProjectToEmployeeDatabaseInput input) { await _IProjectManagerRepository.AssignProject(input); }