Exemple #1
0
        public PeanutParticipation(Peanut peanut, UserGroupMembership userGroupMembership, PeanutParticipationDto participationDto, EntityCreatedDto entityCreatedDto)
        {
            Require.NotNull(peanut, "peanut");
            Require.NotNull(userGroupMembership, "userGroupMembership");
            Require.NotNull(participationDto, "participationDto");
            Require.NotNull(entityCreatedDto, "entityCreatedDto");

            _peanut = peanut;
            _userGroupMembership = userGroupMembership;
            _createdBy           = entityCreatedDto.CreatedBy;
            _createdAt           = entityCreatedDto.CreatedAt;

            Update(participationDto);
        }
Exemple #2
0
        private static IDictionary <Peanut, PeanutPriceDevelopmentItem> CalculatePriceDevelopment(UserGroupMembership member, IList <Peanut> allPeanutsInGroup)
        {
            IList <Peanut> relevantPeanuts = allPeanutsInGroup.Where(p => p.IsCanceled == false && p.IsCleared).OrderBy(p => p.Day).ToList();
            IDictionary <Peanut, PeanutPriceDevelopmentItem> priceDevelopment = new Dictionary <Peanut, PeanutPriceDevelopmentItem>();

            double avaragePeanutsPrice = 0;

            for (int i = 0; i < relevantPeanuts.Count; i++)
            {
                IList <Peanut> takenPeanuts = relevantPeanuts.Take(i + 1).ToList();
                Peanut         peanut       = relevantPeanuts[i];
                double         peanutPrice  = peanut.Bills.Sum(b => b.Amount / b.DebitorCount);
                avaragePeanutsPrice = (avaragePeanutsPrice * i + peanutPrice) / (i + 1);
                PeanutPriceDevelopmentItem devItem = new PeanutPriceDevelopmentItem(peanutPrice, avaragePeanutsPrice);
                priceDevelopment.Add(peanut, devItem);
            }

            return(priceDevelopment);
        }