Beispiel #1
0
        public async Task <ActionResult <ComedianDto> > Put(int comedianId, ComedianDto dto)
        {
            try
            {
                var oldComedian = await _eventRepository.GetComedian(comedianId);

                if (oldComedian == null)
                {
                    return(NotFound($"Could not find comedian with id {comedianId}"));
                }

                var newComedian = _mapper.Map(dto, oldComedian);
                _eventRepository.Update(newComedian);
                if (await _eventRepository.Save())
                {
                    return(NoContent());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
Beispiel #2
0
        public async Task <ActionResult <ComedianDto> > Post(ComedianDto dto)
        {
            try
            {
                var mappedEntity = _mapper.Map <Comedian>(dto);
                _eventRepository.Add(mappedEntity);

                if (await _eventRepository.Save())
                {
                    var location = _linkGenerator.GetPathByAction("Get", "Comedians", new { mappedEntity.ComedianId });
                    return(Created(location, _mapper.Map <ComedianDto>(mappedEntity)));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }
Beispiel #3
0
        public async Task <ActionResult <ComedianDto> > Post([FromBody] ComedianDto dto)
        {
            try
            {
                var mappedEntity = _mapper.Map <Comedian>(dto);
                _eventRepository.Add(mappedEntity);

                if (await _eventRepository.Save())
                {
                    var location = Url.Action(action: "GetComedian", new { comedianId = mappedEntity.ComedianId });
                    return(Created(location, _mapper.Map <ComedianDto>(mappedEntity)));
                }
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }

            return(BadRequest());
        }