using System; using System.Collections.Generic; using BL.DTOs; using DAL.Domain; namespace BL.Factories { public class FoorumFactory { private readonly PostFactory _postFactory = new PostFactory(); 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) { dto.Posts = new List(); f.Posts.ForEach(p => {dto.Posts.Add(_postFactory.Create(p));}); } 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 }; } 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; } } }