Exemple #1
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                Camp camp = null;

                if (includeSpeakers)
                {
                    camp = _repo.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    camp = _repo.GetCampByMoniker(moniker);
                }

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} was not found."));
                }

                // We're mapping our camp but also map an URL helper that we'll use in our
                // AutoMapper profile resolver.
                return(Ok(_mapper.Map <CampModel>(camp)));
            }
            catch
            {
            }

            return(BadRequest());
        }
Exemple #2
0
        // MVC assumes any pass in parameter listed in the url are query string parameters
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                Camp camp = null;

                if (includeSpeakers)
                {
                    camp = _repo.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    camp = _repo.GetCampByMoniker(moniker);
                }

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} not found."));
                }

                // opt.Items passes a collection into the resolver.
                // we are passing down UrlHelper to the resolver
                return(Ok(_mapper.Map <CampModel>(camp)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"get camp exception: {ex}");
            }
            return(BadRequest());
        }
Exemple #3
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                Camp camp = null;
                if (includeSpeakers)
                {
                    camp = campRepository.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    camp = campRepository.GetCampByMoniker(moniker);
                }

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} was not found."));
                }
                return(Ok(mapper.Map <CampModel>(camp)));
            }
            catch (Exception ex)
            {
                logger.LogError($"Exception was thrown while saving Camp: {ex}");
                return(BadRequest());
            }
        }
Exemple #4
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                Camp camp = null;

                if (includeSpeakers)
                {
                    camp = _repo.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    camp = _repo.GetCampByMoniker(moniker);
                }

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} was not found"));
                }

                return(Ok(_mapper.Map <CampModel>(camp, opt => opt.Items["UrlHelper"] = this.Url)));
            }
            catch
            {
            }

            return(BadRequest());
        }
Exemple #5
0
        public IActionResult GetMoniker(string moniker, bool includeSpeakers = false)
        {
            try
            {
                Camp camp = null;

                if (includeSpeakers)
                {
                    camp = _repo.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    camp = _repo.GetCampByMoniker(moniker);
                }

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} was not found"));
                }

                return(Ok(_mapper.Map <CampModel>(camp))); //LD STEP3
            }
            catch
            {
            }

            return(BadRequest());
        }
        public async Task <ActionResult <SpeakerModel> > Post(string moniker, [FromBody] SpeakerModel model)
        {
            try
            {
                var user = await _userManager.FindByNameAsync(this.User.Identity.Name);

                if (user != null)
                {
                    var camp = _repository.GetCampByMonikerWithSpeakers(moniker);
                    if (camp != null)
                    {
                        var speaker = _mapper.Map <Speaker>(model);
                        speaker.User = user;
                        camp.Speakers.Add(speaker);
                        _repository.Add(speaker);

                        if (await _repository.SaveAllAsync())
                        {
                            var url = Url.RouteUrl("GetSpeaker", new { Moniker = moniker, id = speaker.Id });
                            return(Created(url, _mapper.Map <SpeakerModel>(speaker)));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(BadRequest());
        }
Exemple #7
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                Camp camp = null;
                if (includeSpeakers)
                {
                    camp = _repo.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    camp = _repo.GetCampByMoniker(moniker);
                }

                if (camp == null)
                {
                    return(NotFound($"Camp with moniker = '{moniker}' was not found."));
                }

                return(Ok(_mapper.Map <CampModel>(camp)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ex in Get by moniker: {moniker}: {ex}");
            }

            return(BadRequest());
        }
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {         //query string of ?includeSpeakers=true. Additional params are query string
            try
            {
                Camp camp = null;
                if (includeSpeakers)
                {
                    camp = _repo.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    camp = _repo.GetCampByMoniker(moniker);
                }

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} was not found"));
                }

                return(Ok(_mapper.Map <CampModel>(camp)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Exemple #9
0
        public ActionResult <CampModel> Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                Camp result;

                if (includeSpeakers)
                {
                    result = _repository.GetCampByMonikerWithSpeakers(moniker);
                }
                else
                {
                    result = _repository.GetCampByMoniker(moniker);
                }

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

                return(_mapper.Map <CampModel>(result));
            }
            catch (Exception)
            {
            }

            return(BadRequest());
        }
Exemple #10
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            Camp camp = null;

            if (includeSpeakers)
            {
                camp = _repo.GetCampByMonikerWithSpeakers(moniker);
            }
            else
            {
                camp = _repo.GetCampByMoniker(moniker);
            }
            if (camp == null)
            {
                return(NotFound($"camp : {moniker} was not found"));
            }
            return(Ok(_mapper.Map <CampModel>(camp)));
        }
Exemple #11
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try {
                var camp = includeSpeakers
                    ? _campRepository.GetCampByMonikerWithSpeakers(moniker)
                    : _campRepository.GetCampByMoniker(moniker);
                if (camp == null)
                {
                    return(NotFound($"Camp with moniker '{moniker}' was not found."));
                }
                // return Ok(_mapper.Map<CampViewModel>(camp, opt => opt.Items["UrlHelper"] = Url)); /* => this method was cumbersome to use, now implemented by custom resolver */
                return(Ok(_mapper.Map <CampViewModel>(camp)));
            } catch (Exception ex) {
                _logger.LogCritical($"Threw exception while getting camp with moniker='{moniker}' and includeSpeakers='{includeSpeakers}': {ex}");
            }

            return(BadRequest("Could not get camp"));
        }
Exemple #12
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                var camp = includeSpeakers ? repository.GetCampByMonikerWithSpeakers(moniker) : repository.GetCampByMoniker(moniker);

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} was not found"));
                }

                return(Ok(mapper.Map <CampModel>(camp)));
            }
            catch (Exception exception)
            {
                logger.LogError("Threw exception while getting a Camp", exception);
            }

            return(BadRequest());
        }
Exemple #13
0
        public IActionResult Get(string moniker, bool includeSpeakers = false)
        {
            try
            {
                _logger.LogInformation("Getting a Code Camp");

                var camp = includeSpeakers
                    ? _campRepository.GetCampByMonikerWithSpeakers(moniker)
                    : _campRepository.GetCampByMoniker(moniker);

                if (camp == null)
                {
                    return(NotFound($"Camp {moniker} was not found"));
                }

                return(Ok(_mapper.Map <CampModel>(camp)));
            }
            catch (Exception exception)
            {
                _logger.LogError($"Threw exception while getting Camp: {exception}");
            }

            return(BadRequest("Couldn't get Camp"));
        }