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

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

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

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

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

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

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

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

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