private void TestValidationTeam() { ValidationTeam validationTeam = new ValidationTeam(); Team team = new Team(1, ""); try { validationTeam.Validate(team); }catch (ValidationException v) { Debug.Assert(v.Message.ToString() == "Name shouldn't be null!\n"); } Team teamTwo = new Team(-1, "Aba"); try { validationTeam.Validate(teamTwo); } catch (ValidationException v) { Debug.Assert(v.Message.ToString() == "ID shouldn't be less than 0!\n"); } Team teamThree = new Team(-1, ""); try { validationTeam.Validate(teamThree); } catch (ValidationException v) { Debug.Assert(v.Message.ToString() == "ID shouldn't be less than 0!\nName shouldn't be null!\n"); } }
public bool Update(TeamModel entity) { var record = Repository.Get(entity.Id); if (record == null) { return(false); } else { if (entity.LeagueId != 0) { record.LeagueId = entity.LeagueId; } if (!string.IsNullOrWhiteSpace(entity.Name)) { record.Name = entity.Name; } ValidationTeam validator = new ValidationTeam(); FluentValidation.Results.ValidationResult result = validator.Validate(record); if (result.IsValid) { record.UpdatedAt = DateTime.Now; Repository.Update(record); return(true); } else { return(false); } } }
public TeamModel Insert(TeamModel teamModel) { ValidationTeam validator = new ValidationTeam(); Team entity = Mapper.Map <Team>(teamModel); FluentValidation.Results.ValidationResult result = validator.Validate(entity); if (result.IsValid) { Repository.Insert(entity); return(teamModel); } else { return(teamModel); } }