/// <inheritdoc/>
        public async Task <EmailBodyResponse> PutItem(Guid id, IFormFile formFile)
        {
            _logger.LogInformation($"{nameof(EmailBodyRepositoryService)} " +
                                   $"- {nameof(PutItem)} - Started, Id: {id}");

            if (formFile == null)
            {
                _logger.LogInformation($"{nameof(EmailBodyRepositoryService)} " +
                                       $"- {nameof(PutItem)} - Formfile is null, Id: {id}");
                throw new ArgumentException();
            }

            var item = await _repository.Get(id);

            if (item == null)
            {
                _logger.LogError($"{nameof(EmailBodyRepositoryService)} " +
                                 $"- {nameof(PutItem)} - Not found");
                throw new KeyNotFoundException();
            }

            item.File = await FormFileToByteArray(formFile);

            item.Name = formFile.FileName;
            await _repository.Update(item);

            _logger.LogInformation($"{nameof(EmailBodyRepositoryService)} " +
                                   $"- {nameof(PutItem)} - Finished, Id: {id}");
            return(_mapper.Map <EmailBodyResponse>(item));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task <EmailResponse> PutItem(Guid id, EmailRequest request)
        {
            _logger.LogInformation($"{nameof(EmailRepositoryService)} " +
                                   $"- {nameof(PutItem)} - Started, Request: {JsonConvert.SerializeObject(request)}");
            var item = await _repository.Get(id);

            if (item == null)
            {
                _logger.LogInformation($"{nameof(EmailRepositoryService)} " +
                                       $"- {nameof(PutItem)} - Not found, Request: {JsonConvert.SerializeObject(request)}");
                throw new KeyNotFoundException();
            }

            _mapper.Map(request, item);
            await _repository.Update(item);

            _logger.LogInformation($"{nameof(EmailRepositoryService)} " +
                                   $"- {nameof(PutItem)} - Finished, Request: {JsonConvert.SerializeObject(request)}");
            return(_mapper.Map <EmailResponse>(item));
        }