Example #1
0
        public Bill Create(UserGroup userGroup = null, UserGroupMembership creditor = null, string subject = DEFAULT_BILL_SUBJECT, double amount = DEFAULT_BILL_AMOUNT, IList <BillUserGroupDebitorDto> userGroupDebitorsDtos = null, IList <BillGuestDebitorDto> guestDebitorDtos = null, DateTime?settleDate = null, bool persist = true)
        {
            if (userGroupDebitorsDtos == null && guestDebitorDtos == null)
            {
                userGroupDebitorsDtos = new List <BillUserGroupDebitorDto>();
                guestDebitorDtos      = new List <BillGuestDebitorDto> {
                    new BillGuestDebitorDto("Guest Debitor", "*****@*****.**", 1)
                };
            }
            else if (userGroupDebitorsDtos == null)
            {
                userGroupDebitorsDtos = new List <BillUserGroupDebitorDto>();
            }
            else if (guestDebitorDtos == null)
            {
                guestDebitorDtos = new List <BillGuestDebitorDto>();
            }

            if (userGroup == null)
            {
                userGroup = UserGroupCreator.Create(persist: persist);
            }
            if (creditor == null)
            {
                creditor = UserGroupMembershipCreator.Create(userGroup, persist: persist);
            }

            BillDto billDto = CreateBillDto(subject, amount);
            IList <BillUserGroupDebitor> userGroupDebitors = userGroupDebitorsDtos.Select(dto => new BillUserGroupDebitor(dto.UserGroupMembership, dto.Portion)).ToList();
            IList <BillGuestDebitor>     guestDebitors     = guestDebitorDtos.Select(dto => new BillGuestDebitor(dto.Name, dto.Email, dto.Portion)).ToList();


            Bill bill = new Bill(userGroup, billDto, creditor, userGroupDebitors, guestDebitors, new EntityCreatedDto(creditor.User, DateTime.Now));

            if (settleDate.HasValue)
            {
                bill.Settle(new EntityChangedDto(bill.Creditor.User, settleDate.Value));
            }

            if (persist)
            {
                BillDao.Save(bill);
                BillDao.Flush();
            }

            return(bill);
        }
        public PeanutParticipationType Create(UserGroup userGroup = null, string name = "Test Typ", bool isCreditor = true, bool isProducer = false, int maxParticipators = 1, bool persist = true)
        {
            if (userGroup == null)
            {
                userGroup = UserGroupCreator.Create();
            }
            User user = UserGroupMembershipCreator.Create(userGroup, persist: persist).User;

            var peanutParticipationTypeDto = new PeanutParticipationTypeDto
            {
                IsCreditor             = isCreditor,
                Name                   = name,
                IsProducer             = isProducer,
                MaxParticipatorsOfType = maxParticipators
            };
            PeanutParticipationType peanutParticipationType = new PeanutParticipationType(peanutParticipationTypeDto, userGroup, new EntityCreatedDto(user, DateTime.Now));

            return(peanutParticipationType);
        }