Example #1
0
        public async Task UpdateAsync(Guid id, string name, string description,
                                      IFormFile file, decimal price, string language)
        {
            var article = await _articleSqlRepository.GetAsync(id);

            if (article == null)
            {
                throw new JppcException(Codes.ArticleNotFound,
                                        $"Article: '{id}' doesn't exists.");
            }

            byte[] content = null;
            using (Stream stream = file.OpenReadStream())
            {
                using (MemoryStream mStream = new MemoryStream())
                {
                    await stream.CopyToAsync(mStream);

                    content = mStream.ToArray();
                }
            }

            article.SetName(name);
            article.SetDescription(description);
            article.SetFile(file.FileName, content);
            article.SetPrice(price);
            article.SetLanguage(language);
            await _articleSqlRepository.UpdateAsync(article);

            var articleDto = _mapper.Map <ArticleDto>(article);
            await _articleElasticRepository.AddAsync(articleDto);
        }