private void BuildAttachAttachments(Post post) { post.CannotBeNull("post"); var res =_fileManager.GetTempAttachMentsByUserId(post.UserId); post.Attachments = res.Select(x => new PostAttachments() { FileName = x.FileName, ContentType = x.ContentType, Size = x.Size, }).ToList(); }
public BaseResponse AddPost(Post post) { post.CannotBeNull("post"); BuildAttachAttachments(post); int res; var editCode = GetRandomString(); var founded = false; if (_postRepository.GetPostByEditCode(editCode) != null) { while (!founded) { editCode = GetRandomString(); if (_postRepository.GetPostByEditCode(editCode) == null) founded = true; } } post.EditCode = editCode; post.SlugUrl = Slug.CreateSlug(true, post.Title); if (!post.HasAttachments) res = _postRepository.InserPost(post); else { res = _postRepository.InserPostWithAttachment(post); if (res > 0) _fileManager.MoveTempInFinalFolder(post.UserId,res.ToString()); } bool success = res > 0; return new BaseResponse { Success = success, Message = res.ToString() }; }
public void UpdatePost(Post post) { post.CannotBeNull("post"); BuildAttachAttachments(post); post.SlugUrl = Slug.CreateSlug(true, post.Title); if (!post.HasAttachments) _postRepository.UpdatePost(post); else { _postRepository.UpdatePostWithAttachment(post); _fileManager.MoveTempInFinalFolder(post.UserId, post.IdPost.ToString()); } }