public GetStadiumsResponse Get()
        {
            try
            {
                var response = new GetStadiumsResponse
                {
                    Code    = _responseSettings.Value.SuccessfulResponseCode,
                    Message = _responseSettings.Value.SuccessfulResponseMessage,
                };

                response.Stadiums = _stadiumDataManager.Get().Select(x => new Stadium
                {
                    Id       = x.Id,
                    Name     = x.Name,
                    Suburb   = x.Suburb,
                    City     = x.City,
                    Province = x.Province,
                    TeamName = x.Team?.Name
                }).ToArray();

                return(response);
            }
            catch (Exception exception)
            {
                //TODO Log error
                return(new GetStadiumsResponse
                {
                    Code = _responseSettings.Value.ErrorOccuredCode,
                    Message = _responseSettings.Value.ErrorOccuredMessage
                });
            }
        }
Beispiel #2
0
        public CreateTeamResponse Create(CreateTeamRequest request)
        {
            try
            {
                if (request.StadiumId != null)
                {
                    var stadium = _stadiumDataManager.Get(request.StadiumId.GetValueOrDefault());
                    if (!stadium.Any())
                    {
                        return new CreateTeamResponse
                               {
                                   Code    = _responseSettings.Value.InvalidStadiumResponseCode,
                                   Message = string.Format(_responseSettings.Value.InvalidStadiumResponseMessage, request.StadiumId)
                               }
                    }
                    ;

                    if (stadium.First().Team != null)
                    {
                        return new CreateTeamResponse
                               {
                                   Code    = _responseSettings.Value.StadiumAlreadyHasLinkedTeamCode,
                                   Message = _responseSettings.Value.StadiumAlreadyHasLinkedTeamMessage
                               }
                    }
                    ;
                }

                if (_teamDataManager.Get(name: request.Name).Any())
                {
                    return new CreateTeamResponse
                           {
                               Code    = _responseSettings.Value.TeamAlreadyExistsCode,
                               Message = _responseSettings.Value.TeamAlreadyExistsMessage
                           }
                }
                ;

                _teamDataManager.Create(new DataAccess.Models.Team
                {
                    Name      = request.Name,
                    Suburb    = request.Suburb,
                    City      = request.City,
                    Province  = request.Province,
                    StadiumId = request.StadiumId
                });

                return(new CreateTeamResponse
                {
                    Code = _responseSettings.Value.SuccessfulResponseCode,
                    Message = _responseSettings.Value.SuccessfulResponseMessage,
                });
            }
            catch (Exception exception)
            {
                //TODO Add logging
                return(new CreateTeamResponse
                {
                    Code = _responseSettings.Value.ErrorOccuredCode,
                    Message = _responseSettings.Value.ErrorOccuredMessage,
                });
            }
        }