public async Task <int> CreateAsync(string title, string content, string userId, List <string> imageUrls, string latinTitle, string author) { var newsPost = new NewsPost { Title = title, Content = content, UserId = userId, ImageUrl = imageUrls.First().Insert(54, "c_fill,h_500,w_500/"), LatinTitle = latinTitle, Author = author, }; await this.newsPostsRepository.AddAsync(newsPost); await this.newsPostsRepository.SaveChangesAsync(); foreach (var url in imageUrls) { var newsPostPicture = new NewsPostPicture { PictureUrl = url.Insert(54, "c_fill,h_960,w_1920/"), NewsPostId = newsPost.Id, }; await this.newsPostPicturesRepository.AddAsync(newsPostPicture); await this.newsPostPicturesRepository.SaveChangesAsync(); } return(newsPost.Id); }
public async Task <int> EditAsync(string title, string content, string userId, List <string> imageUrls, string latinTitle, string author, int id) { var newsPost = await this.newsPostsRepository .All() .FirstOrDefaultAsync(l => l.Id == id); if (imageUrls.Count > 0) { newsPost.ImageUrl = imageUrls.First().Insert(54, "c_fill,h_500,w_500/"); var locationPictures = await this.newsPostPicturesRepository .All() .Where(m => m.NewsPostId == id) .ToListAsync(); foreach (var newsPic in locationPictures) { newsPic.IsDeleted = true; newsPic.DeletedOn = DateTime.UtcNow; this.newsPostPicturesRepository.Update(newsPic); } foreach (var url in imageUrls) { var newsPicture = new NewsPostPicture { PictureUrl = url.Insert(54, "c_fill,h_960,w_1920/"), NewsPostId = newsPost.Id, }; await this.newsPostPicturesRepository.AddAsync(newsPicture); await this.newsPostPicturesRepository.SaveChangesAsync(); } } newsPost.Title = title; newsPost.Content = content; newsPost.UserId = userId; newsPost.LatinTitle = latinTitle; newsPost.Author = author; await this.newsPostsRepository.SaveChangesAsync(); return(newsPost.Id); }