public async Task <IActionResult> Edit(int id, [Bind("Id,Type")] InvestmentType investmentType) { if (id != investmentType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(investmentType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvestmentTypeExists(investmentType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(investmentType)); }
//[Fact] //public async Task Update_Saves_Updated_Investment() //{ // // Arrange // var investment = _context[0]; // var investmentVm = new InvestmentVM // { // Id = investment.Id, // UserId = investment.UserId, // Amount = investment.Amount - 10, // Name = investment.Name, // Type = investment.Type // }; // var mappedInvestment = investment; // mappedInvestment.Amount -= 10; // var mapper = new Mock<IMapper>() // .Setup(x => x.Map<Investment>(investmentVm)) // .Returns(mappedInvestment); // // Act // var result = await _investmentService.Update(investmentVm); // // Assert // investment = _context[0]; // Assert.True(result); // //Assert.Equal(investmentVm.Id, investment.Id); // //Assert.Equal(investmentVm.Amount, investment.Amount - 10); // //Assert.Equal(investmentVm.Name, investment.Name); // //Assert.Equal(investmentVm.Type, investment.Type); // //Assert.Equal(investmentVm.UserId, investment.UserId); //} private IList <Investment> SeedData(int count) { var investmentTypes = new InvestmentType[] { InvestmentType.Crypto, InvestmentType.Currency, InvestmentType.RealEstate, InvestmentType.Stock }; var data = new List <Investment>(); for (int i = 0; i < count; i++) { var investment = new Investment { Id = i.ToString(), UserId = _userService.User.Id, Abbreviation = $"CODE{i}", Amount = i + 100, CreatedOn = DateTime.UtcNow, ModifiedOn = DateTime.UtcNow, Name = $"Name{i}", Type = investmentTypes[i % investmentTypes.Length] }; data.Add(investment); } return(data); }
public async Task <bool> Handle(CreateInvestmentCommand message, CancellationToken cancellationToken) { //Prepare a new investment. try { var investment = Investment.FromType( InvestmentType.FromName(message.InvestmentType), message.ExchangeId, message.BaseCurrency, message.QuoteCurrency, new Account(message.Username) ); _investmentRepository.Add(investment); await _investmentRepository.UnitOfWork .SaveChangesAsync(); } catch (Exception ex) { Console.WriteLine("Handle Command: CreateInvestmentCommand."); Console.WriteLine("Result: Failure."); Console.WriteLine("Error Message: " + ex.Message); return(false); } return(true); }
public InvestmentBalanceChangedDomainEvent(string investmentId, InvestmentType investmentType, Market market, decimal initialBalance, decimal currentBalance) { InvestmentId = investmentId; InvestmentType = investmentType; Market = market; InitialBalance = initialBalance; CurrentBalance = currentBalance; }
public ActionResult Edit([Bind(Include = "InvestmentTypeID,Description")] InvestmentType investmentType) { if (ModelState.IsValid) { db.Entry(investmentType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("InvestmentType")); } return(View(investmentType)); }
public decimal IncomeTax(decimal totalAmount, decimal investedAmount, InvestmentType investmentType) { decimal profitability = totalAmount - investedAmount; return(investmentType switch { InvestmentType.Treasurie => profitability / 100 * 10, InvestmentType.FixedIncome => profitability / 100 * 5, InvestmentType.Fund => profitability / 100 * 15, _ => 0, });
public ActionResult Create([Bind(Include = "InvestmentTypeID,Description")] InvestmentType investmentType) { if (ModelState.IsValid) { db.InvestmentTypes.Add(investmentType); db.SaveChanges(); return(RedirectToAction("InvestmentType")); } return(View(investmentType)); }
public async Task <IActionResult> Create([Bind("Id,Type,ShortDescription,ProjectId")] InvestmentType investmentType) { if (ModelState.IsValid) { _context.Add(investmentType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(investmentType)); }
public DTOData() { name = ""; investmentSystem = 0; investedAmount = 0; totalTerms = 0; currency = 0; retention = 0; ratesTable = null; annualRate = 0; totalProductions = 0; }
public async Task <IActionResult> CreateReward([Bind("Id,Type,ShortDescription,ProjectId")] InvestmentType model) { var type = new InvestmentType { Type = model.Type, ShortDescription = model.ShortDescription, ProjectId = model.ProjectId }; await _context.investmentTypes.AddAsync(type); await _context.SaveChangesAsync(); return(RedirectToAction("ProjectDashboard", "Projects", new { id = model.ProjectId })); }
// GET: InvestmentTypes/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InvestmentType investmentType = db.InvestmentTypes.Find(id); if (investmentType == null) { return(HttpNotFound()); } return(View(investmentType)); }
public ActionResult DeleteConfirmed(int id) { try { InvestmentType investmentType = db.InvestmentTypes.Find(id); db.InvestmentTypes.Remove(investmentType); db.SaveChanges(); } catch (Exception) { ViewBag.mes = "Can not delete, in use by Investment"; return(View()); } return(RedirectToAction("InvestmentType")); }
public static string GetInvestmentType(InvestmentType invType) { string typeName = string.Empty; switch (invType) { case InvestmentType.ShortTerm: typeName = "短期投资"; break; default: break; } return(typeName); }
public IList <InvestmentDetails> ListByType(InvestmentType type) { try { using (var cmd = DbConnection().CreateCommand()) { cmd.CommandText = $"SELECT * FROM {tableName} WHERE InvestmentType = @Type"; cmd.Parameters.AddWithValue("@Type", type); return(FormatReaderToList(cmd.ExecuteReader())); } } catch (Exception ex) { throw ex; } }
public async Task <IEnumerable <Investment> > GetByType(InvestmentType investmentType) { var investments = _context.Investments .Include(i => i.InvestmentRoundtrips); var result = new List <Investment>(); foreach (var investment in investments) { await _context.Entry(investment) .Reference(i => i.InvestmentType).LoadAsync(); if (investment.InvestmentType.Id == investmentType.Id) { await _context.Entry(investment) .Reference(i => i.InvestmentStatus).LoadAsync(); result.Add(investment); } } return(result); }
public RunProfile(InvestmentType investmentType, DataModel dataModel) { // Process data into usable form ContributionLength = dataModel.RetirementAge - dataModel.Age; ContributionLength = ContributionLength > 0 ? ContributionLength : 0; TrialLength = dataModel.DeathAge - dataModel.Age; TrialLength = TrialLength > 0 ? TrialLength : 0; WithdrawalAmount = dataModel.DesiredRetirementIncome; // Calculate proportions to set withdrawals double totalAdditions = dataModel.YearlyStocksContributions + dataModel.YearlyBondsContributions + dataModel.YearlySavingsContributions; double stockContribProportion = dataModel.YearlyStocksContributions / totalAdditions; double bondsContribProportion = dataModel.YearlyBondsContributions / totalAdditions; double savingsContribProportion = dataModel.YearlySavingsContributions / totalAdditions; double stocksWithdrawalAmount = WithdrawalAmount * stockContribProportion; double bondsWithdrawalAmount = WithdrawalAmount * bondsContribProportion; double savingsWithdrawalAmount = WithdrawalAmount * savingsContribProportion; // Set defaults SeedDistribution = DistributionPool.Instance.GetDistribution(Distribution.DiracDelta); StepDistribution = DistributionPool.Instance.GetDistribution(Distribution.Normal, withScale: 1); // Set specific data switch (investmentType) { case InvestmentType.Stocks: InitialAmount = dataModel.StocksAmount; ContributionAmount = dataModel.YearlyStocksContributions; WithdrawalAmount = stocksWithdrawalAmount; // Stock GBM parameters Drift = Constants.GBMValues[dataModel.StocksDataStartDate]["drift"]; Volatility = Constants.GBMValues[dataModel.StocksDataStartDate]["volatility"]; // Stock GBM generator StepDistribution = DistributionPool.Instance.GetDistribution(dataModel.StocksDistributionType, withScale: 1.0); break; case InvestmentType.Bonds: InitialAmount = dataModel.BondsAmount; ContributionAmount = dataModel.YearlyBondsContributions; WithdrawalAmount = bondsWithdrawalAmount; // Bonds random walk generators SeedDistribution = DistributionPool.Instance.GetDistribution(Distribution.DiracDelta, withPeakAt: 2.94); StepDistribution = DistributionPool.Instance.GetDistribution(dataModel.BondsDistributionType, withPeakAt: Constants.BondValues[dataModel.BondsDataStartDate][dataModel.BondsDistributionType]["peak"], withScale: Constants.BondValues[dataModel.BondsDataStartDate][dataModel.BondsDistributionType]["scale"] / Math.Sqrt(TrialLength)); break; case InvestmentType.Savings: default: InitialAmount = dataModel.SavingsAmount; ContributionAmount = dataModel.YearlySavingsContributions; WithdrawalAmount = savingsWithdrawalAmount; // Interest on savings accounts SeedDistribution = DistributionPool.Instance.GetDistribution(Distribution.DiracDelta, withPeakAt: 0.1); StepDistribution = DistributionPool.Instance.GetDistribution(Distribution.DiracDelta); break; } Volatility /= TrialLength <= 0 ? 1 : Math.Sqrt(TrialLength); }
public IList <InvestmentDetails> ListByType(InvestmentType type) { return(investmentRepository.ListByType(type)); }
private static Transaction AddInvestment(MyMoney m, Security s, Account a, DateTime date, decimal units, decimal unitPrice, InvestmentType type) { Transaction t = m.Transactions.NewTransaction(a); t.Date = date; Investment i = t.GetOrCreateInvestment(); i.Security = s; i.Units = units; i.UnitPrice = unitPrice; i.Type = type; m.Transactions.AddTransaction(t); return(t); }