public async Task <ActionResult <Hall> > Post([FromBody] Hall hall)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _repository.Create(hall);

                await _repository.SaveChangesAsync();

                return(Ok(hall));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #2
0
        public async Task <IActionResult> CreateHallAsync(
            [FromBody, SwaggerParameter(Description = "Hall to create", Required = true)] HallToCreateDto hallToCreate,
            [FromHeader(Name = "Accept"), SwaggerParameter(Description = "media type to request between json or json+hateoas")] string mediaType)
        {
            var hallToAdd = Mapper.Map <Hall>(hallToCreate);

            _hallRepository.AddHall(hallToAdd);

            if (!await _hallRepository.SaveChangesAsync())
            {
                _logger.LogError("Saving changes to database while creating a hall failed");
            }

            if (mediaType == "application/vnd.biob.json+hateoas")
            {
                var links = CreateLinksForHall(hallToAdd.Id);

                var linkedHall = hallToAdd.ShapeData(null) as IDictionary <string, object>;

                linkedHall.Add("links", links);

                return(CreatedAtRoute("GetHall", new { hallId = hallToAdd.Id }, linkedHall));
            }

            return(CreatedAtRoute("GetHall", new { hallId = hallToAdd.Id }, hallToAdd));
        }