コード例 #1
0
        public static CustomerAccount CreateContractUnit(AccountType accountType, int customerId, Stock.Stock stock, DateTime startDate, decimal rentalAmount, IEnumerable <ContractType> contractTypes, int paymentPeriodId)
        {
            switch (accountType)
            {
            case AccountType.Purchase:
                var contractUnitPurchase = new PurchaseAccount {
                    CustomerId = customerId
                };
                GetDefaultContracts(contractTypes, startDate).ForEach(contractUnitPurchase.AddContract);
                return(contractUnitPurchase);

            case AccountType.Rent:
                var cur = new RentalAccount
                {
                    CustomerId     = customerId,
                    RentedContract = new RentalContract {
                        StartDate = startDate, PaymentPeriodId = paymentPeriodId
                    },
                    RequiresInvoicingProErrata = true,
                };
                if (stock != null)
                {
                    cur.AddRentedUnitAndUpdateContract(new RentedUnit {
                        StockId = stock.StockId, Stock = stock, Amount = rentalAmount, RentedDate = startDate
                    });
                }
                return(cur);

            default:
                throw new ApplicationException("Unknown Contract type supplied to ContractUnitFactory");
            }
        }
コード例 #2
0
        public ActionResult AddRentAccountStep5(AddRentAccountVM mAddRentAccountVm)
        {
            if (ModelState.IsValid)
            {
                var rentAcc = TempAccountAsAddRentAccountVM();
                if (TryUpdateModel(rentAcc))
                {
                    var newAccount = new RentalAccount
                    {
                        AlternateAddressInstructions = rentAcc.AlternateAddressInstructions,
                        AlternateAddress             = rentAcc.AlternateAddress,
                        CustomerId        = rentAcc.CustomerId,
                        AttachedContracts = new List <Contract>(),
                        RentedUnits       = new List <RentedUnit>(),
                        OneOffItems       = new List <OneOffItem>(),
                    };
                    foreach (RentedUnit mRentedUnit in rentAcc.RentedUnits)
                    {
                        var rentedUnit = new RentedUnit
                        {
                            Amount     = mRentedUnit.Amount,
                            RentedDate = mRentedUnit.RentedDate,
                            StockId    = mRentedUnit.StockId,
                            Stock      = _stockService.GetStock(mRentedUnit.StockId),
                            Deposit    = mRentedUnit.Deposit,
                        };
                        newAccount.AddRentedUnitAndUpdateContract(rentedUnit);
                    }
                    foreach (var oneOffItem in rentAcc.OneOffItems)
                    {
                        var newOneOffItem = new OneOffItem
                        {
                            Description  = oneOffItem.Description,
                            Charge       = oneOffItem.Charge,
                            Date         = rentAcc.StartDate,
                            Quantity     = oneOffItem.Quantity,
                            OneOffTypeId = oneOffItem.OneOffTypeId
                        };
                        newAccount.OneOffItems.Add(newOneOffItem);
                    }

                    if (ExecuteRepositoryAction(() =>
                    {
                        _accountService.AddTempAccount(newAccount);
                        _accountService.CommitChanges();
                    }))
                    {
                        var acceptAccount = new AcceptAccountVM
                        {
                            CustomerAccountId = newAccount.CustomerAccountId,
                            FullPayment       = (mAddRentAccountVm.Payment > 0)
                        };
                        Session["_accountId"] = acceptAccount;
                        return(RedirectToAction(Stepper2.NextStep()));
                    }
                }
            }
            return(View(mAddRentAccountVm));
        }