2017-06-12 14:43:31 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BL.DTOs;
|
2017-06-12 17:22:58 +03:00
|
|
|
|
using BL.Interfaces;
|
2017-06-12 14:43:31 +03:00
|
|
|
|
using DAL.Domain;
|
|
|
|
|
|
|
|
|
|
namespace BL.Factories
|
|
|
|
|
{
|
|
|
|
|
public class PostFactory
|
|
|
|
|
{
|
2017-06-12 17:22:58 +03:00
|
|
|
|
private readonly IFoorumService _foorumService;
|
|
|
|
|
public PostFactory(IFoorumService foorumService)
|
|
|
|
|
{
|
|
|
|
|
_foorumService = foorumService;
|
|
|
|
|
}
|
2017-06-12 14:43:31 +03:00
|
|
|
|
|
|
|
|
|
public PostDTO Create(Post p, bool withForum=false)
|
|
|
|
|
{
|
|
|
|
|
var dto = new PostDTO()
|
|
|
|
|
{
|
|
|
|
|
PostId = p.PostId,
|
|
|
|
|
Title = p.Title,
|
|
|
|
|
Author = p.Author,
|
|
|
|
|
Body = p.Body,
|
|
|
|
|
CreationTime = p.CreationTime,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (withForum)
|
|
|
|
|
{
|
2017-06-12 17:22:58 +03:00
|
|
|
|
dto.Foorum = _foorumService.Get(p.ForumId, withPosts:false);
|
2017-06-12 14:43:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
2017-06-12 17:22:58 +03:00
|
|
|
|
|
|
|
|
|
public Post Create(PostDTO p)
|
|
|
|
|
{
|
|
|
|
|
var domain = new Post()
|
|
|
|
|
{
|
|
|
|
|
PostId = p.PostId,
|
|
|
|
|
Title = p.Title,
|
|
|
|
|
Author = p.Author,
|
|
|
|
|
Body = p.Body,
|
|
|
|
|
CreationTime = p.CreationTime,
|
|
|
|
|
};
|
|
|
|
|
return domain;
|
|
|
|
|
}
|
2017-06-12 14:43:31 +03:00
|
|
|
|
}
|
|
|
|
|
}
|