示例#1
0
        public async Task <IActionResult> Add(SpectacleDto dto)
        {
            var spectacle = _mapper.Map <SpectacleDto, Spectacle>(dto);

            var createdSpectacle = await _spectacleService.CreateAsync(spectacle);

            var createdDto = _mapper.Map <Spectacle, SpectacleDto>(createdSpectacle);

            return(Ok(createdDto));
        }
示例#2
0
        public IActionResult CreatePerformance([FromBody] SpectacleDto spectacleDto)
        {
            var newId = spectacles.Count + 1;

            var spectacle = new Spectacle()
            {
                Id               = newId,
                Name             = spectacleDto.Name,
                AvailableTickets = spectacleDto.AvailableTickets,
                StartDateTime    = spectacleDto.StartDateTime,
                Duration         = TimeSpan.Parse(spectacleDto.Duration)
            };

            spectacles.Add(spectacle);

            return(CreatedAtAction(nameof(GetPerformance), new { id = newId }, spectacle));
        }
示例#3
0
        public IActionResult UpdatePerformance(int id, [FromBody] SpectacleDto spectacleDto)
        {
            Spectacle spectacle = null;

            try
            {
                spectacle = spectacles.Single(s => s.Id == id);
            }
            catch
            {
                return(NotFound());
            }

            spectacle.Name             = spectacleDto.Name;
            spectacle.AvailableTickets = spectacleDto.AvailableTickets;
            spectacle.StartDateTime    = spectacleDto.StartDateTime;
            spectacle.Duration         = TimeSpan.Parse(spectacleDto.Duration);

            return(NoContent());
        }