Beispiel #1
0
        public async Task <ActionResult> CreateItemAsync([FromBody] SchedulerConfigurationDTO schedulerCronInterval, CancellationToken cancellationToken)
        {
            var newItem = _mapper.Map <SchedulerConfiguration>(schedulerCronInterval);

            newItem = await _schedulerConfigurationService.AddAsync(newItem, cancellationToken);

            if (newItem == null)
            {
                AssignToModelState(_schedulerConfigurationService.Errors);
                return(ValidationProblem());
            }

            return(CreatedAtAction(nameof(ItemByIdAsync), new { id = newItem.Id }, null));
        }
Beispiel #2
0
        public async Task <ActionResult> UpdateItemAsync([FromBody] SchedulerConfigurationDTO schedulerCronInterval, CancellationToken cancellationToken)
        {
            var specFilter = new SchedulerConfigurationFilterSpecification(schedulerCronInterval.Id);
            var rowCount   = await _schedulerConfigurationService.CountAsync(specFilter, cancellationToken);

            if (rowCount == 0)
            {
                throw new EntityNotFoundException(nameof(SchedulerConfiguration), schedulerCronInterval.Id);
            }

            // bind to old item
            var item = _mapper.Map <SchedulerConfiguration>(schedulerCronInterval);

            var result = await _schedulerConfigurationService.UpdateAsync(item, cancellationToken);

            if (!result)
            {
                AssignToModelState(_schedulerConfigurationService.Errors);
                return(ValidationProblem());
            }

            return(CreatedAtAction(nameof(ItemByIdAsync), new { id = item.Id }, null));
        }