main
 1using System.Linq;
 2using gorilla.commons.utility;
 3using MoMoney.Domain.accounting;
 4using MoMoney.Domain.repositories;
 5
 6namespace MoMoney.Service.Application
 7{
 8    public interface IGetTheCurrentCustomerQuery : Query<IAccountHolder> {}
 9
10    public class GetTheCurrentCustomerQuery : IGetTheCurrentCustomerQuery
11    {
12        readonly IAccountHolderRepository account_holders;
13
14        public GetTheCurrentCustomerQuery(IAccountHolderRepository account_holders)
15        {
16            this.account_holders = account_holders;
17        }
18
19        public IAccountHolder fetch()
20        {
21            var c = account_holders.all().SingleOrDefault();
22
23            if (null == c)
24            {
25                var customer = new AccountHolder();
26                account_holders.save(customer);
27                return customer;
28            }
29
30            return c;
31        }
32    }
33}