public IEnumerable<Dividend> CalculateDividends(int year, Deposit deposit, IEnumerable<GeneralMeeting> generalMeetings)
        {
            Guard.AgainstNull(() => deposit, () => generalMeetings);

            var generalMeetingsInYear = 
                generalMeetings.Where(p => p.MeetingDate.Year == year && p.DividendRate > 0);

            foreach (var generalMeeting in generalMeetingsInYear)
            {
                var position = _stockPositionCalculator.GetStockPosition(
                    deposit, generalMeeting.Stock.Splitted.Id, generalMeeting.MeetingDate);

                var quantity = position.Quantity;

                if (quantity > 0)
                {
                    var createdDividend = deposit.GetDividendForGeneralMeeting(generalMeeting.Id);

                    bool isCreated = false;
                    bool isDifferent = false;

                    if (createdDividend != null)
                    {
                        isCreated = true;
                        isDifferent = createdDividend.Quantity != quantity;
                    }

                    var dividend = new Dividend(0, quantity, generalMeeting.Id, deposit.Id, generalMeeting, isCreated, isDifferent);
                    yield return dividend;
                }
            }
        }
        public Dividend CreateDividend(Dividend dividend)
        {
            Guard.AgainstNull(() => dividend);

            using (var uow = _uowFactory.Create())
            {
                uow.RepoOf<Dividend>().Add(dividend);
                uow.SaveChanges();
                return dividend;
            }
        }
        private Dividend GetDividend(DividendViewModel dividendVm)
        {
            var dividend = new Dividend(
                dividendVm.Id, 
                dividendVm.Quantity, 
                dividendVm.GeneralMeeting.Id, 
                dividendVm.Deposit.Id, 
                GetGeneralMeeting(dividendVm.GeneralMeeting),
                false,
                false
            );

            return dividend;
        }
        private DividendViewModel GetDividendViewModel(Dividend dividend)
        {
            var vm = new DividendViewModel
            {
                Id = dividend.Id,
                Quantity = dividend.Quantity,
                DividendPayment = dividend.DividendPayment,
                IsCreated = dividend.IsCreated,
                IsDifferent = dividend.IsDifferent
            };

            if (dividend.GeneralMeeting != null)
                vm.GeneralMeeting = GetGeneralMeetingViewModel(dividend.GeneralMeeting);

            return vm;
        }
示例#5
0
 public void AddDividend(Dividend dividend)
 {
     Dividends.Add(dividend);
 }