2017-06-12 14:28:07 +03:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using BL.DTOs;
|
2017-06-12 17:22:58 +03:00
|
|
|
|
using BL.Interfaces;
|
2017-06-12 14:28:07 +03:00
|
|
|
|
using DAL.Domain;
|
|
|
|
|
|
|
|
|
|
namespace BL.Factories
|
|
|
|
|
{
|
|
|
|
|
public class FoorumFactory
|
|
|
|
|
{
|
2017-06-12 17:22:58 +03:00
|
|
|
|
private readonly PostFactory _postFactory;
|
|
|
|
|
|
|
|
|
|
public FoorumFactory(IFoorumService forumService)
|
|
|
|
|
{
|
|
|
|
|
_postFactory = new PostFactory(forumService);
|
|
|
|
|
}
|
2017-06-12 14:28:07 +03:00
|
|
|
|
public FoorumDTO Create(Foorum f, bool withPosts = false)
|
|
|
|
|
{
|
|
|
|
|
var dto = new FoorumDTO()
|
|
|
|
|
{
|
|
|
|
|
FoorumId = f.FoorumId,
|
|
|
|
|
Title = f.Title,
|
|
|
|
|
Author = f.Author,
|
|
|
|
|
Body = f.Body,
|
|
|
|
|
CreationTime = f.CreationTime,
|
|
|
|
|
Description = f.Description,
|
|
|
|
|
Visible = f.Visible
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (withPosts)
|
|
|
|
|
{
|
2017-06-12 14:43:31 +03:00
|
|
|
|
dto.Posts = new List<PostDTO>();
|
|
|
|
|
f.Posts.ForEach(p => {dto.Posts.Add(_postFactory.Create(p));});
|
2017-06-12 14:28:07 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Foorum Create(FoorumDTO f)
|
|
|
|
|
{
|
|
|
|
|
return new Foorum()
|
|
|
|
|
{
|
|
|
|
|
Author = f.Author,
|
|
|
|
|
Body = f.Body,
|
|
|
|
|
CreationTime = f.CreationTime,
|
|
|
|
|
Description = f.Description,
|
|
|
|
|
Title = f.Title
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-06-12 15:46:53 +03:00
|
|
|
|
|
|
|
|
|
public Foorum Update(Foorum domain, FoorumDTO dto)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
domain.Title = dto.Title ?? domain.Title;
|
|
|
|
|
domain.Body = dto.Body ?? domain.Body;
|
|
|
|
|
domain.Description = dto.Description ?? domain.Description;
|
|
|
|
|
return domain;
|
|
|
|
|
}
|
2017-06-12 14:28:07 +03:00
|
|
|
|
}
|
|
|
|
|
}
|