Esempio n. 1
0
        public async Task <IActionResult> InsertAsync(CreateEventCommand data)
        {
            var operationResult = Event.Create(data);

            if (!operationResult.IsValid)
            {
                ModelState.AddFromOperationResult(operationResult);
                return(BadRequest(ModelState));
            }

            await _eventRepository.InsertAsync(operationResult.Result);

            return(Created($"/api/events/{operationResult.Result.Id}", null));
        }
Esempio n. 2
0
        public async Task <ActionResult <Event> > UpdateAsync(int id, UpdateEventCommand data)
        {
            var foundEvent = await _eventRepository.FindByIdAsync(id);

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

            var operationResult = foundEvent.UpdateEventDetails(data);

            if (!operationResult.IsValid)
            {
                ModelState.AddFromOperationResult(operationResult);
                return(BadRequest(ModelState));
            }

            await _eventRepository.UpdateAsync(foundEvent);

            return(Ok(foundEvent));
        }