Exemplo n.º 1
0
        public async Task <ActionResult> CreateItemAsync([FromBody] JobConfigurationDTO schedulerCronInterval, CancellationToken cancellationToken)
        {
            var newItem = _mapper.Map <JobConfiguration>(schedulerCronInterval);

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

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

            return(CreatedAtAction(nameof(ItemByIdAsync), new { id = newItem.Id }, null));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> UpdateItemAsync([FromBody] JobConfigurationDTO jobConfiguration, CancellationToken cancellationToken)
        {
            var specFilter = new JobConfigurationFilterSpecification(jobConfiguration.Id);
            var rowCount   = await _jobConfigurationService.CountAsync(specFilter, cancellationToken);

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

            // bind to old item
            var item = _mapper.Map <JobConfiguration>(jobConfiguration);

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

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

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