vreksam/BL/Services/FoorumService.cs

81 lines
2.1 KiB
C#
Raw Normal View History

2017-06-12 13:37:48 +03:00
using System;
using System.Collections.Generic;
using BL.DTOs;
using BL.Factories;
2017-06-12 13:37:48 +03:00
using BL.Interfaces;
using DAL.Interfaces;
namespace BL.Services
{
public class FoorumService : IFoorumService
{
private readonly IFoorumRepository _foorumRepository;
private readonly FoorumFactory _factory;
2017-06-12 13:37:48 +03:00
public FoorumService(IFoorumRepository foorumRepository)
{
_foorumRepository = foorumRepository;
_factory = new FoorumFactory();
2017-06-12 13:37:48 +03:00
}
2017-06-12 14:16:38 +03:00
public FoorumDTO Add(FoorumDTO foorum)
2017-06-12 13:37:48 +03:00
{
var foorumDomain = _factory.Create(foorum);
foorumDomain.CreationTime = DateTime.Now;
2017-06-12 14:16:38 +03:00
var f = _foorumRepository.Add(foorumDomain);
return _factory.Create(f);
2017-06-12 13:37:48 +03:00
}
public void AddPost(int id, PostDTO post)
{
throw new NotImplementedException();
}
public void Delete(int id)
{
throw new NotImplementedException();
}
public FoorumDTO Get(int id)
{
2017-06-12 14:43:31 +03:00
var f =_foorumRepository.GetById(id);
return _factory.Create(f, withPosts:true);
2017-06-12 13:37:48 +03:00
}
public IEnumerable<FoorumDTO> GetAll()
{
foreach (var f in _foorumRepository.GetAll())
{
yield return _factory.Create(f);
2017-06-12 13:37:48 +03:00
}
}
public void Hide(int id)
{
throw new NotImplementedException();
}
public IEnumerable<FoorumDTO> SearchFoorumAuthor(string query)
{
2017-06-12 15:26:34 +03:00
foreach (var f in _foorumRepository.GetMany(f => f.Author.ToLower().Contains(query.ToLower())))
{
yield return _factory.Create(f);
}
2017-06-12 13:37:48 +03:00
}
public IEnumerable<FoorumDTO> SearchFoorumTitle(string query)
{
throw new NotImplementedException();
}
public IEnumerable<PostDTO> SearchPostAuthor(string query)
{
throw new NotImplementedException();
}
public void Update(FoorumDTO foorum)
{
throw new NotImplementedException();
}
}
}