Refactor BL foorum service to use a factory for DTOS
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BL.DTOs;
|
||||
using BL.Factories;
|
||||
using BL.Interfaces;
|
||||
using DAL.Domain;
|
||||
using DAL.Interfaces;
|
||||
@@ -13,32 +14,19 @@ namespace BL.Services
|
||||
{
|
||||
public class FoorumService : IFoorumService
|
||||
{
|
||||
private IFoorumRepository _foorumRepository;
|
||||
private readonly IFoorumRepository _foorumRepository;
|
||||
private readonly FoorumFactory _factory;
|
||||
public FoorumService(IFoorumRepository foorumRepository)
|
||||
{
|
||||
_foorumRepository = foorumRepository;
|
||||
_factory = new FoorumFactory();
|
||||
}
|
||||
public FoorumDTO Add(FoorumDTO foorum)
|
||||
{
|
||||
var foorumDomain = new Foorum()
|
||||
{
|
||||
Author = foorum.Author,
|
||||
Body = foorum.Body,
|
||||
CreationTime = DateTime.Now,
|
||||
Description = foorum.Description,
|
||||
Title = foorum.Title
|
||||
};
|
||||
var foorumDomain = _factory.Create(foorum);
|
||||
foorumDomain.CreationTime = DateTime.Now;
|
||||
var f = _foorumRepository.Add(foorumDomain);
|
||||
return new FoorumDTO()
|
||||
{
|
||||
FoorumId = f.FoorumId,
|
||||
Title = f.Title,
|
||||
Author = f.Author,
|
||||
Body = f.Body,
|
||||
CreationTime = f.CreationTime,
|
||||
Description = f.Description,
|
||||
Visible = f.Visible
|
||||
};
|
||||
return _factory.Create(f);
|
||||
}
|
||||
|
||||
public void AddPost(int id, PostDTO post)
|
||||
@@ -60,16 +48,7 @@ namespace BL.Services
|
||||
{
|
||||
foreach (var f in _foorumRepository.GetAll())
|
||||
{
|
||||
yield return new FoorumDTO()
|
||||
{
|
||||
FoorumId = f.FoorumId,
|
||||
Title = f.Title,
|
||||
Author = f.Author,
|
||||
Body = f.Body,
|
||||
CreationTime = f.CreationTime,
|
||||
Description = f.Description,
|
||||
Visible = f.Visible
|
||||
};
|
||||
yield return _factory.Create(f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user