Ejemplo n.º 1
0
        public async Task <ArticlePriceListOutResponse> EditArticlePriceListOutAsync(EditArticlePriceListOutRequest request)
        {
            ArticlePriceListOut existingRecord = await _articlePriceListOutRespository.GetAsync(request.Id);

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

            if (request.ArticleId != null)
            {
                Article existingArticle = await _articleRespository.GetAsync(request.ArticleId);

                if (existingArticle == null)
                {
                    throw new NotFoundException($"Article with {request.ArticleId} is not present");
                }
            }

            ArticlePriceListOut entity = _articlePriceListOutMapper.Map(request);
            ArticlePriceListOut result = _articlePriceListOutRespository.Update(entity);

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

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

            return(_articlePriceListOutMapper.Map(result));
        }
Ejemplo n.º 2
0
        public async Task <ArticlePriceListOutResponse> AddArticlePriceListOutAsync(AddArticlePriceListOutRequest request)
        {
            ArticlePriceListOut articlePriceListOut = _articlePriceListOutMapper.Map(request);
            ArticlePriceListOut result = _articlePriceListOutRespository.Add(articlePriceListOut);

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

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

            return(_articlePriceListOutMapper.Map(result));
        }
Ejemplo n.º 3
0
        public async Task <ArticlePriceListOutResponse> GetArticlePriceListOutAsync(Guid id)
        {
            if (id == null)
            {
                throw new ArgumentNullException();
            }

            ArticlePriceListOut entity = await _articlePriceListOutRespository.GetAsync(id);

            _logger.LogInformation(Events.GetById, Messages.TargetEntityChanged_id, entity?.Id);

            return(_articlePriceListOutMapper.Map(entity));
        }
Ejemplo n.º 4
0
        public ArticlePriceListOut Map(AddArticlePriceListOutRequest request)
        {
            if (request == null)
            {
                return(null);
            }

            ArticlePriceListOut articlePriceListOut = new ArticlePriceListOut
            {
                Priority           = request.Priority,
                ReorderTime        = request.ReorderTime,
                ScaleUnitQty       = request.ScaleUnitQty,
                ScaleUnitType      = request.ScaleUnitType,
                UnitOrder          = request.UnitOrder,
                MinOrderQty        = request.MinOrderQty,
                IsMultipleOrderQty = request.IsMultipleOrderQty,
                ArticleId          = request.ArticleId,
            };

            return(articlePriceListOut);
        }
Ejemplo n.º 5
0
        public async Task <ArticlePriceListOutResponse> DeleteArticlePriceListOutAsync(DeleteArticlePriceListOutRequest request)
        {
            if (request?.Id == null)
            {
                throw new ArgumentNullException();
            }

            ArticlePriceListOut result = await _articlePriceListOutRespository.GetAsync(request.Id);

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

            result.IsInactive = true;

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

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

            return(_articlePriceListOutMapper.Map(result));
        }
Ejemplo n.º 6
0
        public ArticlePriceListOutResponse Map(ArticlePriceListOut articlePriceListOut)
        {
            if (articlePriceListOut == null)
            {
                return(null);
            }
            ;

            ArticlePriceListOutResponse response = new ArticlePriceListOutResponse
            {
                Id                 = articlePriceListOut.Id,
                Priority           = articlePriceListOut.Priority,
                ReorderTime        = articlePriceListOut.ReorderTime,
                ScaleUnitQty       = articlePriceListOut.ScaleUnitQty,
                ScaleUnitType      = articlePriceListOut.ScaleUnitType,
                UnitOrder          = articlePriceListOut.UnitOrder,
                MinOrderQty        = articlePriceListOut.MinOrderQty,
                IsMultipleOrderQty = articlePriceListOut.IsMultipleOrderQty,
                ArticleId          = articlePriceListOut.ArticleId,
                ArticleRanges      = articlePriceListOut.ArticleRanges.Select(x => _articleRangeMapper.Map(x)).ToList()
            };

            return(response);
        }
Ejemplo n.º 7
0
 public ArticlePriceListOut Update(ArticlePriceListOut articlePriceListOut)
 {
     _context.Entry(articlePriceListOut).State = EntityState.Modified;
     return(articlePriceListOut);
 }
Ejemplo n.º 8
0
        public async Task <ArticlePriceListOut> GetAsync(Guid id)
        {
            ArticlePriceListOut articlePriceListOut = await _context.ArticlePriceListsOut.AsNoTracking().Where(x => x.Id == id).Include(x => x.Article).FirstOrDefaultAsync();

            return(articlePriceListOut);
        }
Ejemplo n.º 9
0
 public ArticlePriceListOut Add(ArticlePriceListOut articlePriceListOut)
 {
     return(_context.ArticlePriceListsOut.Add(articlePriceListOut).Entity);
 }