Beispiel #1
0
        public async Task <NewsResponse> EditNewsAsync(EditNewsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }

            var newsExists = await _newsRepository.GetAsync(request.Id);

            if (newsExists == null)
            {
                throw new ArgumentException($"News with id {request.Id} does not exist");
            }

            var news   = _mapper.Map <Entities.News>(request);
            var result = _newsRepository.Update(news);
            await _newsRepository.UnitOfWork.SaveChangesAsync();

            var response = _mapper.Map <NewsResponse>(result);

            return(response);
        }
Beispiel #2
0
        public CommonResult EditNews(EditNewsRequest request)
        {
            var data = _newsProvider.GetById(request.Id);

            if (request.Title.NotNullNorEmpty())
            {
                data.Title = request.Title;
            }

            if (request.TagsString.NotNullNorEmpty() && GetTagsFromTagsString(request.TagsString).Any())
            {
                data.Tags = GetTagsFromTagsString(request.TagsString);
            }

            var contentData = new NewsContentData
            {
                Id = request.Id,
                Content = request.Content
            };

            if (request.Image != null)
            {
                var saveNewsImageResult = _newsProvider.SaveImageAsync(request.Image);
                data.ImageName = saveNewsImageResult.Result.ImagePath;
            }

            _newsProvider.SaveDataAsync(data);
            _newsProvider.SaveContentAsync(contentData);

            return CommonResult.Success();
        }
Beispiel #3
0
        public async Task <IActionResult> Update(EditNewsRequest request)
        {
            var result = await _newsService.EditNewsAsync(request);

            return(Ok(result));
        }