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"); } }
//public void AddServiceContract(ServiceContract entity) //{ // var cu = _contractUnitRepsoitory.GetById(entity.CustomerAccountId); // cu.AddContract(entity); // _contractUnitRepsoitory.Update(cu); //} public void AddContractUnit(PurchaseAccount entity) { _contractUnitRepsoitory.Add(entity); //entity.Stock = _stockService.GetStock(entity.StockId); throw new NotImplementedException("SetStockAppropriateLifeCycle not called"); //entity.SetStockAppropriateLifeCycle(); // _stockService.SetCustomerAccountId(entity.CustomerAccountId,entity.StockId); // _stockService.UpdateStock(entity.Stock); }
public void UpdatePurchaseAccountStock(PurchaseAccount purchaseAccount, int oldStockId, int oldStockProductCycleId) { //purchaseAccount.Stock = _stockService.GetStock(purchaseAccount.StockId); throw new NotImplementedException("SetStockAppropriateLifeCycle not called"); //purchaseAccount.SetStockAppropriateLifeCycle(); //_stockService.UpdateStock(purchaseAccount.Stock); UpdateCustomerAccount(purchaseAccount); _stockService.ChangeStockLifeCycle(oldStockId, oldStockProductCycleId); _stockService.SetCustomerAccountId(null, oldStockId); }
public PurchaseAccountVM(PurchaseAccount contractUnit) { _contractUnit = contractUnit; }
public async Task <IActionResult> CommitPurchaseAccount([FromBody] PurchaseAccountRequest data) { MicroCoin.Transactions.TransferTransaction transaction = null; try { transaction = PurchaseAccountRequestToTransaction(data); } catch (MicroCoinRPCException e) { return(this.HandlerError(e)); } catch (Exception e) { return(StatusCode(500, new MicroCoinError(ErrorCode.UnknownError, e.Message, ""))); } Hash hash = transaction.GetHash(); if (data.Signature != null) { transaction.Signature = new ECSignature { R = (Hash)data.Signature.R.PadLeft(64, '0'), S = (Hash)data.Signature.S.PadLeft(64, '0') }; if (Utils.ValidateSignature(hash, transaction.Signature, transaction.AccountKey)) { using (var ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms, System.Text.Encoding.Default, true)) { bw.Write(1); bw.Write(6); } transaction.SaveToStream(ms); ms.Position = 0; Hash h = ms.ToArray(); var resp = await client.ExecuteOperationsAsync(h); if (resp.Count() > 0 && resp.First().Errors == null) { var r = resp.First(); var tr = new PurchaseAccount { FounderAccount = (uint)r.Account, AccountNumber = (uint)r.DestAccount, Type = r.Type.ToString(), SubType = r.SubType.ToString(), Fee = r.Fee, Confirmations = r.Maturation, OpHash = r.Ophash, Balance = r.Balance }; return(Ok(tr)); } else { return(BadRequest(new MicroCoinError(ErrorCode.InvalidOperation, resp.Count() > 0 ? resp.First().Errors : "Invalid transaction", "Your transaction is invalid" ))); } } } else { return(StatusCode(403, MicroCoinError.Error(ErrorCode.InvalidSignature))); } } return(BadRequest("Missing signature")); }
public ActionResult AddAccount(NewAccountVM mNewAccountVm) { if (!ModelState.IsValid) { return(View(mNewAccountVm)); } var newAccVm = TempRepository <NewAccountVM> .Entity; if (TryUpdateModel(newAccVm)) { CustomerAccount account = null; switch (newAccVm.AccountType) { case AccountType.Purchase: account = new PurchaseAccount(); break; case AccountType.Rent: account = new RentalAccount(); break; } account.AlternateAddressInstructions = newAccVm.AlternateAddressInstructions; account.AlternateAddress = newAccVm.AlternateAddress; account.CustomerId = newAccVm.CustomerId; account.OpenedDate = newAccVm.StartDate; _accountService.AddAccount(account); _accountService.CommitChanges(); return(RedirectToAction("Edit", "Customer", new { id = account.CustomerId, moveOnToEditAccount = account.CustomerAccountId })); } //if (TryUpdateModel(newAccVm)) //{ // if (TempAccount == null || TempAccount.AccountType != newAccVm.AccountType) // { // TempAccount = _accountService.AccountBuilder(newAccVm.AccountType, newAccVm.CustomerId); // //TempAccount.OneOffItems = InitiateOneOffItems(); // } // switch (TempAccount.AccountType) // { // case AccountType.Purchase: // if ((TempAccount as AddPurchaseAccountVM) == null) // { // TempAccount = Mapper.Map<PurchaseAccount, AddPurchaseAccountVM>(TempAccount as PurchaseAccount); // //TempAccount.OneOffItems = InitiateOneOffItems(c => c.PurchaseDefault); // (TempAccountAsAddPurchaseAccountVM()).StartDate = mNewAccountVm.StartDate; // } // else // { // if (mNewAccountVm.StartDate != TempAccountAsAddPurchaseAccountVM().StartDate) // { // var newStartDate = mNewAccountVm.StartDate; // TempAccountAsAddPurchaseAccountVM().StartDate = newStartDate; // TempAccountAsAddPurchaseAccountVM().PurchasedUnits.ForEach(u => u.PurchasedDate = newStartDate); // TempAccountAsAddPurchaseAccountVM().PurchasedUnits.ForEach(u => u.Contracts.ForEach(c => c.SetStartDate(newStartDate))); // } // } // BuildPurchaseAccountStepper(); // return RedirectToAction(Stepper2.NextStep()); // case AccountType.Rent: // TempAccount = (TempAccount is AddRentAccountVM) ? TempAccount : Mapper.Map<RentalAccount, AddRentAccountVM>(TempAccount as RentalAccount); // TempAccount.OneOffItems = InitiateOneOffItems(c => c.RentalDefault); // (TempAccountAsAddRentAccountVM()).StartDate = mNewAccountVm.StartDate; // BuildRentAccountStepper(); // return RedirectToAction(Stepper2.NextStep()); // } //} return(View(mNewAccountVm)); }
public ActionResult AddPurchaseAccountStep6(AddPurchaseAccountVM mAddPurchaseAccountVm) { if (ModelState.IsValid) { var purAcc = TempAccountAsAddPurchaseAccountVM(); if (TryUpdateModel(purAcc)) { var newAccount = new PurchaseAccount { AlternateAddressInstructions = purAcc.AlternateAddressInstructions, AlternateAddress = purAcc.AlternateAddress, CustomerId = purAcc.CustomerId, Customer = _customerService.GetCustomer(purAcc.CustomerId), OneOffItems = new List <OneOffItem>(), PurchasedUnits = new List <PurchaseUnit>(), }; foreach (var unit in purAcc.PurchasedUnits) { var newUnit = new PurchaseUnit { PurchasedDate = unit.PurchasedDate, RetailCost = unit.RetailCost, DiscountedAmount = unit.DiscountedAmount, //Stock = unit.Stock, StockId = unit.StockId, Contracts = unit.Contracts.Select(c => new ServiceContract { ContractTypeId = c.ContractTypeId, //ContractType = c.ContractType, ContractLengthInMonths = c.ContractLengthInMonths, StartDate = c.StartDate, Charge = c.Charge, ExpiryDate = c.ExpiryDate, PaymentPeriodId = c.PaymentPeriodId, }).ToList(), }; newAccount.PurchasedUnits.Add(newUnit); } foreach (var oneOffItem in purAcc.OneOffItems) { var newOneOffItem = new OneOffItem { Description = oneOffItem.Description, Charge = oneOffItem.Charge, Date = purAcc.StartDate, Quantity = oneOffItem.Quantity, OneOffTypeId = oneOffItem.OneOffTypeId }; newAccount.OneOffItems.Add(newOneOffItem); } if (ExecuteRepositoryAction(() => { _accountService.AddTempAccount(newAccount); _accountService.CommitChanges(); })) { Session["_accountId"] = newAccount.CustomerAccountId; return(RedirectToAction(Stepper2.NextStep())); } } } return(View(mAddPurchaseAccountVm)); }