Beispiel #1
0
        public async Task <IActionResult> Get([FromRoute] Guid id, [FromQuery] CollectionRequestModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var query = teamsRepository.GetAll()
                            .Where(x => x.Id.Equals(id));

                bool withRelations = !model.NoRelations;

                if (withRelations)
                {
                    query = this.teamsRepository.GetRelations(query) as IQueryable <Team>;
                }

                var viewQuery = query.Select(x => ViewModelHelper.BuildTeamViewModel(x, withRelations));

                TeamViewModel team = await viewQuery.FirstOrDefaultAsync();

                if (team == null)
                {
                    return(NotFound());
                }

                return(Ok(team));
            }
            catch (Exception ex)
            {
                return(BadRequest(new JsonResult(ex.Message)));
            }
        }
Beispiel #2
0
        public IActionResult Get([FromQuery] CollectionRequestModel model)
        {
            try
            {
                var query = teamsRepository.GetAll();

                if (!string.IsNullOrEmpty(model.Name))
                {
                    query = query.Where(x => x.Name.Contains(model.Name));
                }

                bool withRelations = !model.NoRelations;

                if (withRelations)
                {
                    query = this.teamsRepository.GetRelations(query) as IQueryable <Team>;
                }

                //var response = mapper.Map<Collection<TeamViewModel>>(query);

                var viewModel = query.Select(x => ViewModelHelper.BuildTeamViewModel(x, withRelations));

                return(Ok(viewModel.ToList()));
            }
            catch (Exception ex)
            {
                return(BadRequest(new JsonResult(ex.Message)));
            }
        }