示例#1
0
        public ArticleRangeResponse Map(ArticleRange articleRange)
        {
            if (articleRange == null)
            {
                return(null);
            }
            ;

            ArticleRangeResponse response = new ArticleRangeResponse
            {
                Id                    = articleRange.Id,
                Quantity              = articleRange.Quantity,
                NetPrice              = articleRange.NetPrice,
                Discount              = articleRange.Discount,
                Addition              = articleRange.Addition,
                Price                 = articleRange.Price,
                ArticleId             = articleRange.ArticleId,
                Article               = _articleMapper.Map(articleRange.Article),
                ArticlePriceListInId  = articleRange.ArticlePriceListInId,
                ArticlePriceListIn    = _articlepriceListInMapper.Map(articleRange.ArticlePriceListIn),
                ArticlePriceListOutId = articleRange.ArticlePriceListOutId,
                ArticlePriceListOut   = _articlepriceListOutMapper.Map(articleRange.ArticlePriceListOut)
            };

            return(response);
        }
示例#2
0
        private ArticleRange GetRange(int offset, int length)
        {
            var start = 0;

            var result = new ArticleRange();

            foreach (var articlePart in Parts)
            {
                var end = start + articlePart.Text.Length;

                var a = offset;
                var b = offset + length;

                if (a >= start && a < end ||
                    b >= start && b < end)
                {
                    if (result.Parts.Any() == false)
                    {
                        result.StartingOffset = offset - start;
                    }

                    result.Parts.Add(articlePart);
                }

                start = end;
            }

            return(result);
        }
示例#3
0
        public async Task <ArticleRangeResponse> AddArticleRangeAsync(AddArticleRangeRequest request)
        {
            ArticleRange articleRange = _articleRangeMapper.Map(request);
            ArticleRange result       = _articleRangeRespository.Add(articleRange);

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

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

            return(_articleRangeMapper.Map(result));
        }
示例#4
0
        public async Task <ArticleRangeResponse> GetArticleRangeAsync(Guid id)
        {
            if (id == null)
            {
                throw new ArgumentNullException();
            }

            ArticleRange entity = await _articleRangeRespository.GetAsync(id);

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

            return(_articleRangeMapper.Map(entity));
        }
示例#5
0
        public async Task <ArticleRangeResponse> EditArticleRangeAsync(EditArticleRangeRequest request)
        {
            ArticleRange existingRecord = await _articleRangeRespository.GetAsync(request.Id);

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

            ArticleRange entity = _articleRangeMapper.Map(request);
            ArticleRange result = _articleRangeRespository.Update(entity);

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

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

            return(_articleRangeMapper.Map(result));
        }
示例#6
0
        public ArticleRange Map(AddArticleRangeRequest request)
        {
            if (request == null)
            {
                return(null);
            }

            ArticleRange articleRange = new ArticleRange
            {
                Quantity              = request.Quantity,
                NetPrice              = request.NetPrice,
                Discount              = request.Discount,
                Addition              = request.Addition,
                Price                 = request.Price,
                ArticleId             = request.ArticleId,
                ArticlePriceListInId  = request.ArticlePriceListInId,
                ArticlePriceListOutId = request.ArticlePriceListOutId,
            };

            return(articleRange);
        }
示例#7
0
        public async Task <ArticleRangeResponse> DeleteArticleRangeAsync(DeleteArticleRangeRequest request)
        {
            if (request?.Id == null)
            {
                throw new ArgumentNullException();
            }

            ArticleRange result = await _articleRangeRespository.GetAsync(request.Id);

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

            result.IsInactive = true;

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

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

            return(_articleRangeMapper.Map(result));
        }
示例#8
0
 public ArticleRange Update(ArticleRange articleRange)
 {
     _context.Entry(articleRange).State = EntityState.Modified;
     return(articleRange);
 }
示例#9
0
        public async Task <ArticleRange> GetAsync(Guid id)
        {
            ArticleRange articleRange = await _context.ArticleRanges.AsNoTracking().Where(x => x.Id == id).FirstOrDefaultAsync();

            return(articleRange);
        }
示例#10
0
 public ArticleRange Add(ArticleRange articleRange)
 {
     return(_context.ArticleRanges.Add(articleRange).Entity);
 }