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);
        }
Example #2
0
        public Bill Create(UserGroup userGroup, BillDto billDto, UserGroupMembership creditor, IList <BillUserGroupDebitorDto> debitors,
                           IList <BillGuestDebitorDto> guestDebitors, Peanut peanut, User creator)
        {
            Require.NotNull(creator, "creator");
            Require.NotNull(userGroup, "userGroup");
            Require.NotNull(billDto, "billDto");
            Require.NotNull(creditor, "creditor");
            Require.NotNull(debitors, "debitors");
            Require.NotNull(guestDebitors, "guestDebitors");

            IList <BillUserGroupDebitor> debitorEntities      = GetDebitors(debitors, creator);
            IList <BillGuestDebitor>     guestDebitorEntities = GetGuestDebitors(guestDebitors);
            Bill bill = new Bill(userGroup, billDto, creditor, debitorEntities, guestDebitorEntities, new EntityCreatedDto(creator, DateTime.Now));

            if (peanut != null)
            {
                PeanutService.ClearPeanut(peanut, bill);
            }
            return(BillDao.Save(bill));
        }