Exemple #1
0
        public async Task <Email> GetByIdAsync(int id, CancellationToken cancellationToken = default)
        {
            var specFilter = new EmailFilterSpecification(id, true);
            var results    = await _unitOfWork.Emails.ListAsync(specFilter, null, cancellationToken);

            if (results?.Count > 0)
            {
                return(results[0]);
            }
            return(null);
        }
Exemple #2
0
        public async Task <ActionResult> UpdateItemAsync([FromBody] EmailDTO email, CancellationToken cancellationToken)
        {
            var specFilter = new EmailFilterSpecification(email.Id);
            var rowCount   = await _emailService.CountAsync(specFilter, cancellationToken);

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

            // bind to old item
            var item = _mapper.Map <Email>(email);

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

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

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