Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PostServices : IPostServices
- {
- private const int PAGE_SIZE = 10;
- IPostRepository postRepository;
- public IList<Post> Recent(int pageNumber)
- {
- return this.postRepository.GetNewest(pageNumber, PAGE_SIZE);
- }
- public PostServices(IPostRepository postRepository)
- {
- this.postRepository = postRepository;
- }
- private bool postDoesNotExist(string url)
- {
- return postRepository.GetByID(url) != null && postRepository.GetByID(url).ID != null;
- }
- private string getUniqueUrl(Post post)
- {
- string url = post.Subject.ToUrl();
- if (postDoesNotExist(url))
- url += "-" + post.Owner.UserName;
- while (postDoesNotExist(url))
- {
- url += "-1";
- }
- return url;
- }
- public Post GetByID(string id)
- {
- return postRepository.GetByID(id);
- }
- public void Save(Post post)
- {
- if (String.IsNullOrEmpty(post.ID))
- post.ID = getUniqueUrl(post);
- postRepository.Save(post);
- }
- }
Add Comment
Please, Sign In to add comment