public void AddNetWorth(NetWorthModel netWorthModel) { var cash = new Cash { Id = Guid.NewGuid() }; var investedAssets = new InvestedAssets { Id = Guid.NewGuid() }; var useAssets = new UseAssets { Id = Guid.NewGuid() }; var liabilities = new Liabilities { Id = Guid.NewGuid() }; _mapper.Map(netWorthModel, cash); _mapper.Map(netWorthModel, investedAssets); _mapper.Map(netWorthModel, useAssets); _mapper.Map(netWorthModel, liabilities); var netWorth = new NetWorth { Id = Guid.NewGuid(), UserId = netWorthModel.UserId, DateTimeCreated = DateTime.Now, Total = cash.GetTotal() + investedAssets.GetTotal() + useAssets.GetTotal() - liabilities.GetTotal() }; _netWorthRepository.InsertNetWorth(netWorth); _cashRepository.InsertCash(cash, netWorth.Id); _investedAssetsRepository.InsertInvestedAssets(investedAssets, netWorth.Id); _useAssetsRepository.InsertUseAssets(useAssets, netWorth.Id); _liabilitiesRepository.InsertLiabilities(liabilities, netWorth.Id); }
public async Task <IActionResult> NetWorth([FromBody] NetWorthModel netWorthModel) { try { var authenticateInfo = await HttpContext.GetTokenAsync("access_token"); var userId = _authService.GetUserIdFromToken(authenticateInfo); if (userId.Equals(Guid.Empty)) { return(Unauthorized()); } netWorthModel.UserId = userId; _netWorthService.AddNetWorth(netWorthModel); return(Ok()); } catch (Exception e) { return(Problem(e.Message)); } }