Exemplo n.º 1
0
        public async Task<CommonResult<CreateNewsResult>> CreateNewsAsync(CreateNewsRequest request)
        {
            var newsId = GetNewsId();

            var saveNewsImageResult = await _newsProvider.SaveImageAsync(request.Image);

            var data = new NewsData
            {
                Id = newsId,
                Author = request.Author,
                AuthorUserName = request.AuthorUserName,
                Title = request.Title,
                Date = DateTime.Now,
                ImageName = saveNewsImageResult.ImagePath,
                Tags = GetTagsFromTagsString(request.TagsString),
            };

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

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

            return CommonResult<CreateNewsResult>.Success(new CreateNewsResult { Id = newsId });
        }
        public async Task SaveDataAsync(NewsData data)
        {
            var fileName = $"{data.Id}.json";
            var path = Path.Combine(_newsPath, fileName);
            data.ImagePath = _newsImagesPath + data.ImageName;

            await SaveFileAsync(path, JsonConvert.SerializeObject(data));
        }