public IActionResult SetTargetPortfolio([FromBody] AllocationsViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model.Allocations.Count == 0) { ModelState.AddModelError(string.Empty, $"There must be at least one item in the allocation."); return(BadRequest(ModelState)); } if (model.Allocations.Count > 0) { decimal sum = Math.Round(model.Allocations.Values.Aggregate((a, b) => a + b)); if (Math.Round(sum) != 100) { ModelState.AddModelError(string.Empty, $"The allocations must add up to 100%, received {sum}%."); return(BadRequest(ModelState)); } } string userId = m_userManager.GetUserId(HttpContext.User); bool success = m_allocationsManager.SetTargetPortfolio(userId, model.Allocations); if (!success) { return(StatusCode(StatusCodes.Status500InternalServerError)); } return(Ok()); }
//[Authorize(Roles = "Administrator")] public ActionResult Allocations(AllocationsViewModel allocationsViewModel) { if (Session["userId"] != null && Session["userId"].Equals(_username)) { } else { return(RedirectToAction("Login", "Account")); } List <Allocations> originalAllocations = dbcontext.Allocations.ToList(); foreach (var item in originalAllocations) { foreach (var allocation in allocationsViewModel.allocations) { if (item.Strategy.Equals(allocation.Strategy)) { if (!item.Amount.Equals(allocation.Amount)) { item.Amount = allocation.Amount; dbcontext.SaveChanges(); } if (item.IsActive != allocation.IsActive) { item.IsActive = allocation.IsActive; dbcontext.SaveChanges(); } } } } return(RedirectToAction("EditTransactionsPage", "Actual"));; }
ViewModelBase createModel() { var model = new AllocationsViewModel(); PrepareViewModel(model, EvolutionResources.bnrAllocations, 0, MenuOptionFlag.RequiresNoSale); model.BrandCategoryId = CurrentUser.DefaultBrandCategoryId.Value; model.BrandCategoryList = ProductService.FindBrandCategoryListItemModel(CurrentCompany); model.LocationId = CurrentCompany.DefaultLocationID.Value; model.LocationList = LookupService.FindLocationListItemModel(CurrentCompany); return(model); }
public ActionResult Allocations() { if (Session["userId"] != null && Session["userId"].Equals(_username)) { } else { return(RedirectToAction("Login", "Account")); } List <Allocations> allocations = dbcontext.Allocations.ToList(); AllocationsViewModel theAllocations = new AllocationsViewModel(); theAllocations.allocations = allocations; return(View(theAllocations)); }
public ActionResult Index() { List <Allocations> allocations = dbcontext.Allocations.ToList(); AllocationsViewModel theAllocations = new AllocationsViewModel(); theAllocations.allocations = allocations; List <RiskAmount> riskAmountList = new List <RiskAmount>(); foreach (var item in theAllocations.allocations) { RiskAmount riskAmount = new RiskAmount(); riskAmount.Strategy = item.Strategy; Double strAmount; Double.TryParse(item.Amount, out strAmount); riskAmount.Amount = strAmount; double riskPercentageAmount = 0; double targetPercentage = 0; if (item.Strategy.Equals("ShortMorningSpike")) { riskPercentageAmount = 0.018; targetPercentage = 0.0425; } else if (item.Strategy.Equals("TenAmSpike")) { riskPercentageAmount = 0.014; targetPercentage = 0.045; } else if (item.Strategy.Equals("Breakdown")) { riskPercentageAmount = 0.025; targetPercentage = 0.031; } else if (item.Strategy.Equals("Breakout")) { riskPercentageAmount = 0.031; targetPercentage = 0.02; } else if (item.Strategy.Equals("ShortBreakout")) { riskPercentageAmount = 0.02; targetPercentage = 0.02; } else if (item.Strategy.Equals("jnugBreakout")) { riskPercentageAmount = 0.03; targetPercentage = 0.036; } else if (item.Strategy.Equals("jnugShort")) { riskPercentageAmount = 0.024; targetPercentage = 0.03; } else if (item.Strategy.Equals("gushShortTwoPercent")) { riskPercentageAmount = 0.04; targetPercentage = 0.05; } riskAmount.RiskPercentage = riskPercentageAmount; riskAmount.TargetPercentage = targetPercentage; riskAmount.RiskDollarAmount = CalculateRiskDollarAmount(riskPercentageAmount, strAmount); riskAmount.TargetAmount = CalculateTargetAmount(targetPercentage, strAmount); riskAmountList.Add(riskAmount); } return(View(riskAmountList)); }