public async Task <Post> CreatePost(CreatePostDto input) { var com = await _communityRepository.GetAll().FirstOrDefaultAsync(x => x.Slug == input.CommunitySlug); var noHtml = Slug.HtmlToPlainText(input.Content); var slug = Slug.FriendlyUrlTitle(noHtml); var hasSlug = await _postRepository.GetAll() .FirstOrDefaultAsync(x => x.IsDeleted == false && x.Slug == slug); if (hasSlug != null) { var newContent = input.Content + "" + RandomString.GenerateString(3); slug = Slug.FriendlyUrlTitle(newContent); } var post = new Post { Content = input.Content, CommunityId = com.Id, UserId = input.UserId, ContentType = input.ContentType, Slug = slug }; var user = await _userRepository.GetByIdAsync(input.UserId); if (input.ContentFile != null) { var path = await _blobService.InsertFile(input.ContentFile); post.MediaContentPath = path; } if (input.ContentType == ContentType.Link || input.ContentType == ContentType.YoutubeLink) { post.LinkUrl = input.LinkUrl; } await _postRepository.AddAsync(post); var mods = await _communityUserRepository.GetAll().Include(x => x.User).Where(x => !x.IsDeleted && x.IsAdmin && x.CommunityId == com.Id && x.UserId != input.UserId) .ToListAsync(); var msg = user.Username + " moderatörü olduğun" + " " + com.Name + " " + "topluluğunda paylaşım yaptı." + " " + "https://saalla.com/t/" + com.Slug; var subject = "Bir yeni paylaşım"; foreach (var mod in mods) { await _emailSender.SendEmail(mod.User.EmailAddress, subject, msg); } return(post); }
public async Task <Response> CreateCommunity(CreateCommunity input) { var responseModel = new Response(); var userComs = await _communityUserRepository.GetAll() .Where(x => x.UserId == input.UserId && x.IsAdmin && x.IsDeleted == false) .ToListAsync(); var user = await _userRepository.GetByIdAsync(input.UserId); if (userComs.Count > 1 && !user.IsAdmin) { responseModel.Status = false; responseModel.Message = "Daha fazla topluluk oluşturamazsınız"; return(responseModel); } var slug = Slug.FriendlyUrlTitle(input.Name); var isExist = _communityRepository.GetAll().Any(x => x.Slug == slug); if (isExist) { responseModel.Status = false; responseModel.Message = "Bu isimde bir topluluk zaten var"; return(responseModel); } var category = await _categoryRepository.GetAll().FirstOrDefaultAsync(x => x.Slug == input.CatSlug); var model = new Community { Name = input.Name, Description = input.Description, CategoryId = category.Id, Slug = slug }; if (input.LogoFile != null) { var path = await _blobService.InsertFile(input.LogoFile); model.LogoPath = path; } if (input.CoverImage != null) { var path = await _blobService.InsertFile(input.CoverImage); model.CoverImagePath = path; } var result = await _communityRepository.AddAsync(model); var communityUser = new CommunityUser { CommunityId = result.Id, UserId = input.UserId, IsAdmin = true }; await _communityUserRepository.AddAsync(communityUser); responseModel.Message = "Topluluk başarıyla oluşturuldu"; responseModel.Status = true; responseModel.Slug = model.Slug; return(responseModel); }