private async Task <ContentNews> UploadImage(ContentNews news)
        {
            if (news.NewsImage.Length > 0)
            {
                //  var fileName = news.NewsImage.FileName.Split('\\').Last();
                //  var filePath = $"{_hostingEnvironment.WebRootPath}{smartFunds.Common.Constants.NewsImageFolder.Path}{fileName}";


                var fileName = Guid.NewGuid() + Path.GetExtension(news.NewsImage.FileName).ToLower();



                var path = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot/images/news",
                    fileName);


                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await news.NewsImage.CopyToAsync(stream);
                }
                news.ImageThumb = fileName;
            }

            return(news);
        }
 public async Task UpdateContentNews(ContentNewsModel newsModel)
 {
     try
     {
         ContentNews news = _mapper.Map <ContentNews>(newsModel);
         await _newsManager.UpdateContentNews(news);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <ContentNewsModel> GetContentNews(int?newsId)
        {
            try
            {
                ContentNews news = await _newsManager.GetContentNews(newsId);

                ContentNewsModel newsModel = _mapper.Map <ContentNewsModel>(news);
                return(newsModel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <ContentNewsModel> SaveContentNews(ContentNewsModel newsModel)
        {
            try
            {
                ContentNews news      = _mapper.Map <ContentNews>(newsModel);
                ContentNews savedNews = await _newsManager.SaveContentNews(news);

                ContentNewsModel savedNewsModel = _mapper.Map <ContentNewsModel>(savedNews);
                return(savedNewsModel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #5
0
 public static ContentNewsModel ToModel(ContentNews entity)
 {
     if (entity == null)
     {
         return(null);
     }
     return(new ContentNewsModel()
     {
         Id = entity.Id,
         ByText = entity.ByText,
         Language = entity.Language,
         ReadMoreText = entity.ReadMoreText,
         NewsPageTitle = entity.NewsPageTitle,
         RelatedText = entity.RelatedText,
         ShareThisText = entity.ShareThisText
     });
 }
 public async Task UpdateContentNews(ContentNews news)
 {
     try
     {
         news.DateLastUpdated = DateTime.Now;
         news.LastUpdatedBy   = _userManager.CurrentUser();
         news.Title           = news.Title.Replace("\r\n", "<br/>");
         news.Contents        = HttpUtility.HtmlDecode(news.Contents);
         if (news.NewsImage?.Length > 0)
         {
             news = UploadImage(news).Result;
         }
         _unitOfWork.ContentNewsRepository.Update(news);
         await _unitOfWork.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }