Esempio n. 1
0
        public UseAssets GetUseAssets(Guid netWorthId)
        {
            const string selectCommand =
                "SELECT id, principalhome, vacationhome, carstrucksboats, homefurnishing, artsantiquescoinscollectibles, jewelryfurs" +
                " FROM useassets WHERE networthid = @networthid";

            using var conn = new NpgsqlConnection(_config["ConnectionString"]);
            conn.Open();
            using var cmd = new NpgsqlCommand(selectCommand, conn);
            cmd.Parameters.AddWithValue("networthid", netWorthId);
            using var reader = cmd.ExecuteReader();
            if (!reader.HasRows)
            {
                return(null);
            }
            reader.Read();
            var useAssets = new UseAssets
            {
                Id              = reader.GetGuid(0),
                PrincipalHome   = reader.GetDecimal(1),
                VacationHome    = reader.GetDecimal(2),
                CarsTrucksBoats = reader.GetDecimal(3),
                HomeFurnishings = reader.GetDecimal(4),
                ArtAntiquesCoinsCollectibles = reader.GetDecimal(5),
                JewelryFurs = reader.GetDecimal(6)
            };

            return(useAssets);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void InsertUseAssets(UseAssets useAssets, Guid netWorthId)
        {
            using var conn = new NpgsqlConnection(_config["ConnectionString"]);
            conn.Open();
            const string insertCommand = "INSERT INTO useassets (id, principalhome, vacationhome, carstrucksboats, homefurnishing, artsantiquescoinscollectibles, jewelryfurs, networthid)" +
                                         " VALUES (@id, @principalhome, @vacationhome, @carstrucksboats, @homefurnishing, @artsantiquescoinscollectibles, @jewelryfurs, @networthid)";

            using var cmd = new NpgsqlCommand(insertCommand, conn);
            cmd.Parameters.AddWithValue("id", useAssets.Id);
            cmd.Parameters.AddWithValue("principalhome", useAssets.PrincipalHome);
            cmd.Parameters.AddWithValue("vacationhome", useAssets.VacationHome);
            cmd.Parameters.AddWithValue("carstrucksboats", useAssets.CarsTrucksBoats);
            cmd.Parameters.AddWithValue("homefurnishing", useAssets.HomeFurnishings);
            cmd.Parameters.AddWithValue("artsantiquescoinscollectibles", useAssets.ArtAntiquesCoinsCollectibles);
            cmd.Parameters.AddWithValue("jewelryfurs", useAssets.JewelryFurs);
            cmd.Parameters.AddWithValue("networthid", netWorthId);
            cmd.ExecuteNonQuery();
        }