Exemple #1
0
        public async Task <ArticleGroupResponse> DeleteArticleGroupAsync(DeleteArticleGroupRequest request)
        {
            if (request?.Id == null)
            {
                throw new ArgumentNullException();
            }

            ArticleGroup result = await _articleGroupRespository.GetAsync(request.Id);

            if (result == null)
            {
                throw new ArgumentException($"Entity with {request.Id} is not present");
            }

            result.IsInactive = true;

            _articleGroupRespository.Update(result);
            int modifiedRecords = await _articleGroupRespository.UnitOfWork.SaveChangesAsync();

            _logger.LogInformation(Logging.Events.Delete, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords);

            return(_articleGroupMapper.Map(result));
        }
Exemple #2
0
        public async Task <ArticleResponse> EditArticleAsync(EditArticleRequest request)
        {
            Article existingArticle = await _articleRespository.GetAsync(request.Id);

            if (existingArticle == null)
            {
                throw new ArgumentException($"Entity with {request.Id} is not present");
            }

            if (request.ArticleTypeId != null)
            {
                ArticleType existingType = await _articleTypeRespository.GetAsync(request.ArticleTypeId);

                if (existingType == null)
                {
                    throw new NotFoundException($"ArticleType with {request.ArticleTypeId} is not present");
                }
            }

            if (request.ArticleGroupId != null)
            {
                ArticleGroup existingArticleGroup = await _articleGroupRespository.GetAsync(request.ArticleGroupId);

                if (existingArticleGroup == null)
                {
                    throw new NotFoundException($"ArticleGroup with {request.ArticleGroupId} is not present");
                }
            }

            Article entity = _articleMapper.Map(request);
            Article result = _articleRespository.Update(entity);

            int modifiedRecords = await _articleRespository.UnitOfWork.SaveChangesAsync();

            _logger.LogInformation(Logging.Events.Edit, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords);
            _logger.LogInformation(Logging.Events.Edit, Messages.ChangesApplied_id, result?.Id);

            return(_articleMapper.Map(result));
        }