public async Task <bool> Post([FromForm] string userID, [FromForm] string assetName, [FromForm] string assetSymbol, [FromForm] string amountUSD, [FromForm] string averagePrice, [FromForm] string cryptoExchange, [FromForm] string transactionType)
        {
            bool isSuccessful = false;

            var query    = "SELECT * FROM c ORDER BY c.id DESC";
            var allItems = await _cosmosDbService.GetItemsAsync(query);

            var count = allItems.Count();

            //string id = "";
            //foreach (var item in allItems)
            //{
            //    string jsonResult = item.ToString();

            //    ExistingInvestmentResponseVM vm = new ExistingInvestmentResponseVM();
            //    vm = JsonConvert.DeserializeObject<ExistingInvestmentResponseVM>(jsonResult);

            //    id = (Convert.ToInt32(vm.ID) + 1).ToString();

            //    break;
            //}

            var amount   = Convert.ToDecimal(amountUSD);
            var price    = Convert.ToDecimal(averagePrice);
            var quantity = amount / price;

            try
            {
                var investment = new ExistingInvestment
                {
                    ID              = (count + 1).ToString(),
                    DbGrouping      = "ExistingInvestment",
                    UserID          = userID,
                    AssetName       = assetName,
                    AssetSym        = assetSymbol,
                    AmountUSD       = amountUSD,
                    AveragePrice    = averagePrice,
                    Quantity        = quantity.ToString(),
                    CryptoExchange  = cryptoExchange,
                    TransactionType = transactionType,
                    EntryDt         = DateTime.Now,
                    ModifyDt        = DateTime.Now,
                    PartitionKey    = 1,
                    IsDeleted       = false
                };

                await _cosmosDbService.AddItemAsync(investment, "ExistingInvestment");

                isSuccessful = true;
            }
            catch (System.Exception ex)
            {
                isSuccessful = false;
            }

            return(isSuccessful);
        }
Esempio n. 2
0
        public async Task UpdateItemAsync(object obj, string dbGrouping)
        {
            if (dbGrouping == "ExistingInvestment")
            {
                ExistingInvestment investment = new ExistingInvestment();

                investment = (ExistingInvestment)obj;

                await this._container.UpsertItemAsync <ExistingInvestment>(investment, new PartitionKey(investment.PartitionKey));
            }
            else if (dbGrouping == "User")
            {
                CMUser user = new CMUser();

                user = (CMUser)obj;

                await this._container.UpsertItemAsync <CMUser>(user, new PartitionKey(user.PartitionKey));
            }
        }
Esempio n. 3
0
        public async Task AddItemAsync(object obj, string dbGrouping)
        {
            ContainerProperties properties = await _container.ReadContainerAsync();

            var path = properties.PartitionKeyPath;

            if (dbGrouping == "ExistingInvestment")
            {
                ExistingInvestment investment = new ExistingInvestment();

                investment = (ExistingInvestment)obj;

                await this._container.CreateItemAsync <ExistingInvestment>(investment, new PartitionKey(investment.PartitionKey));
            }
            else if (dbGrouping == "User")
            {
                CMUser user = new CMUser();

                user = (CMUser)obj;

                await this._container.CreateItemAsync <CMUser>(user, new PartitionKey(user.PartitionKey));
            }
        }