public Response RegisterSquad(SquadRequest request) { var errors = Validate(request); if (errors.Count() > 0) { return(Response.CreateResponse(errors)); } var club = clubQuery.GetClub(request.ClubId); if (club == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist"))); } try { squadRepository.AddSquad(new Squad(club.Guid) { Name = request.SquadName, YearBorn = request.YearBorn }); } catch (Exception ex) { return(Response.CreateResponse(ex)); } return(Response.CreateSuccessResponse()); }
private IEnumerable <string> Validate(SquadRequest request, bool mustHaveSquadId = false) { List <string> errors = new List <string>(); if (request.ClubId.IsEmpty()) { errors.Add("ClubId must be provided"); } if (request.SquadName.IsEmpty()) { errors.Add("Name must be provided"); } if (mustHaveSquadId && request.SquadId.IsEmpty()) { errors.Add("SquadId must be provided"); } return(errors); }
public Response UpdateSquadProfile(SquadRequest request) { var errors = Validate(request, true); if (errors.Count() > 0) { return(Response.CreateResponse(errors)); } var club = clubQuery.GetClub(request.ClubId); if (club == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist"))); } var squad = squadQuery.GetSquad(request.SquadId.Value); if (squad == null || squad.ClubId != request.ClubId) { return(Response.CreateResponse(new EntityNotFoundException("The specified squad does not exist"))); } var squads = squadQuery.GetSquads(request.ClubId); try { squadRepository.UpdateSquad(new Squad(club.Guid, request.SquadId) { Name = request.SquadName }); } catch (Exception ex) { return(Response.CreateResponse(ex)); } return(Response.CreateSuccessResponse()); }