示例#1
0
        public async Task <IActionResult> Update(int id, [FromBody] EventCollectionDto dto)
        {
            try
            {
                var collection = await _eventCollectionRetrievalService
                                 .GetCollectionByIdAsync(id, new EventCollectionRetrievalOptions
                {
                    ForUpdate = true
                });

                dto.CopyTo(collection);

                await _eventCollectionManagementService.UpdateCollectionAsync(collection);

                return(Ok(new EventCollectionDto(collection)));
            }
            catch (NotFoundException e)
            {
                return(NotFound(e.Message));
            }
            catch (NotAccessibleException e)
            {
                return(NotFound(e.Message)); // FIXME: can't return FORBIDDEN, it will redirect to login page!
            }
        }
        public async Task <IActionResult> Create([FromBody] EventCollectionDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.FormatErrors()));
            }

            try
            {
                var collection = new EventCollection();
                dto.CopyTo(collection);
                await _service.CreateCollectionAsync(collection);

                return(Ok());
            }
            catch (NotAccessibleException e)
            {
                return(NotFound(e.Message)); // FIXME: can't return FORBIDDEN, it will redirect to login page!
            }
        }