private void CreateTeamButton_Click(object sender, EventArgs e) { TeamModel T = new TeamModel(); T.TeamName = TeameNameTextBox.Text; T.TeamMembers = selectedTeamMembers; TeamValidator TeamValidator = new TeamValidator(); var result = TeamValidator.Validate(T); string message = ""; if (!result.IsValid) { foreach (ValidationFailure res in result.Errors) { message += $"{res}\n"; } MessageBox.Show(message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } GlobalConfig.Connaction.CreateTeam(T); callingForm.TeamComplete(T); this.Close(); }
public static void ValidateTeam(Team team) { var validator = new TeamValidator(); var result = validator.Validate(team); if (result.IsValid) { return; } throw new ValidationException(result.Errors); }
public Response <TeamDTO> Update(TeamDTO teamDTO) { try { TeamValidator validator = new TeamValidator(); ValidationResult results = validator.Validate(teamDTO); if (results.IsValid) { var team = TeamMapper.MapTeamDTOToTeamModel(teamDTO); var teamEntity = _repository.Update(team); _repository.SaveChanges(); var teamEntityDTO = TeamMapper.MapTeamModelToTeamDTO(teamEntity); var response = new Response <TeamDTO> { DTO = teamEntityDTO }; return(response); } else { return(new Response <TeamDTO> { Errors = results.Errors.Select(x => new Error { Type = ErrorType.ValidationError, Message = x.ErrorMessage }).ToList() }); } } catch (Exception ex) { return(new Response <TeamDTO> { Errors = new List <Error>() { new Error { Type = ErrorType.Exception, Message = ex.Message } } }); } }
public Team Add(Team t) { validator.Validate(t); return(repository.Save(t)); }