public IActionResult Rebalance(int id, int currentId, [FromBody] ProposedClientProductsViewModel _product) { if (ModelState.IsValid) { var existingProduct = this.context.ProposedClientProducts.Where(b => b.RecId == id).FirstOrDefault(); if (existingProduct == null) { CurrentClientProducts prod = this.context.CurrentClientProducts.Where(a => a.RecId == currentId).FirstOrDefault(); ProposedClientProducts proposedProduct = new ProposedClientProducts(); proposedProduct.RecId = id; proposedProduct.ProductId = prod.ProductId; proposedProduct.Owner = prod.Owner; proposedProduct.ClientId = prod.ClientId; proposedProduct.Percentage = prod.Percentage; proposedProduct.Value = prod.UnutilizedValue; proposedProduct.Status = 1; this.context.ProposedClientProducts.Add(proposedProduct); //this.context.SaveChanges(); // newId = proposedProduct.RecId; ProductReplacement prReplacement = new ProductReplacement(); prReplacement.CurrentId = currentId; prReplacement.ProposedId = id; this.context.ProductReplacement.Add(prReplacement); this.context.SaveChanges(); var res = this.context.Product.Where(b => b.ProductId == proposedProduct.ProductId).FirstOrDefault(); var result = this.mapper.Map <ProposedClientProductsViewModel>(proposedProduct); result.Product = res.ProductName; return(Ok(result)); } else { this.mapper.Map <ProposedClientProductsViewModel, ProposedClientProducts>(_product, existingProduct); this.context.ProposedClientProducts.Update(existingProduct); this.context.SaveChanges(); var res = this.context.Product.Where(b => b.ProductId == _product.ProductId).FirstOrDefault(); var result = this.mapper.Map <ProposedClientProductsViewModel>(_product); result.Product = res.ProductName; return(Ok(result)); } } else { return(BadRequest(ModelState)); } }
public IActionResult CreateFund(int id, int currentId, decimal percentage, [FromBody] ProposedClientFundsViewModel _fund) { if (ModelState.IsValid) { var existingProduct = this.context.ProposedClientProducts.Where(b => b.RecId == id).FirstOrDefault(); if (existingProduct == null) { CurrentClientProducts prod = this.context.CurrentClientProducts.Where(a => a.RecId == currentId).FirstOrDefault(); ProposedClientProducts proposedProduct = new ProposedClientProducts(); proposedProduct.RecId = id; proposedProduct.ProductId = prod.ProductId; proposedProduct.Owner = prod.Owner; proposedProduct.ClientId = prod.ClientId; proposedProduct.Percentage = prod.Percentage; proposedProduct.Value = prod.UnutilizedValue; proposedProduct.Status = 1; this.context.ProposedClientProducts.Add(proposedProduct); //this.context.SaveChanges(); // newId = proposedProduct.RecId; ProductReplacement prReplacement = new ProductReplacement(); prReplacement.CurrentId = currentId; prReplacement.ProposedId = id; this.context.ProductReplacement.Add(prReplacement); this.context.SaveChanges(); } var updatedProduct = this.context.ProposedClientProducts.Where(b => b.RecId == id).FirstOrDefault(); var existingFund = this.context.ProposedClientFunds.Where(b => b.RecId == _fund.RecId).FirstOrDefault(); if (existingFund == null) { var fund = this.mapper.Map <ProposedClientFunds>(_fund); fund.HeaderId = id; this.context.ProposedClientFunds.Add(fund); //updatedProduct.Percentage = percentage; //this.context.ProposedClientProducts.Update(updatedProduct); this.context.SaveChanges(); var result = this.mapper.Map <ProposedClientFundsViewModel>(fund); return(Ok(result)); } else { this.mapper.Map <ProposedClientFundsViewModel, ProposedClientFunds>(_fund, existingFund); this.context.ProposedClientFunds.Update(existingFund); //updatedProduct.Percentage = percentage; //this.context.ProposedClientProducts.Update(updatedProduct); this.context.SaveChanges(); var result = this.mapper.Map <ProposedClientFundsViewModel>(_fund); return(Ok(result)); } } else { return(BadRequest(ModelState)); } }