Exemple #1
0
        public async Task AddSoldInstrumentToDBTable(SoldInstrumentDTO soldInstrument)
        {
            var soldInstrumentDBObject = _mapper.Map <SoldInstrument>(soldInstrument);

            await _unitOfWork.SoldInstruments.Insert(soldInstrumentDBObject);

            await _unitOfWork.Save();
        }
        private async Task InsertToSoldInstrumentTable(Stock stockDbOBj, SellStockDTO stockSaleInfo)
        {
            var client = _httpClientFactory.CreateClient(_exchangeRateApiSettings.ClientName);

            var exRateResponse = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, _exchangeRateApiSettings.BaseClient + _exchangeRateApiSettings.GetExchangeRateUri));

            // placeholder for when ExRateStorage Cache is not working
            var exchangeRate = 1.33;

            if (exRateResponse.StatusCode == HttpStatusCode.OK)
            {
                var content = await exRateResponse.Content.ReadAsStringAsync();

                exchangeRate = double.Parse(content);
            }

            if (stockDbOBj.Country == "US")
            {
                // create SoldInstrumentDTO with stockObj data and send to SoldInstrumentService
                var soldInstrumentDTO = new SoldInstrumentDTO
                {
                    Amount          = stockSaleInfo.Amount,
                    Name            = stockSaleInfo.Name,
                    PurchasePrice   = stockDbOBj.PurchasePrice,
                    PuchaseDate     = stockDbOBj.PurchaseDate,
                    SalePrice       = stockSaleInfo.SellPrice,
                    SaleDate        = DateTime.Now,
                    DiscountApplied = stockDbOBj.PurchaseDate.AddMonths(12) <= DateTime.Now ? true : false,
                    Profit          = ((stockSaleInfo.SellPrice * exchangeRate) * stockSaleInfo.Amount) - ((stockDbOBj.PurchasePrice * exchangeRate) * stockSaleInfo.Amount)
                };

                soldInstrumentDTO.CGTPayable = soldInstrumentDTO.DiscountApplied ? (soldInstrumentDTO.Profit * .5) : soldInstrumentDTO.Profit;

                await _soldInstrumentsRepository.AddSoldInstrumentToDBTable(soldInstrumentDTO);
            }
            else
            {
                // create SoldInstrumentDTO with stockObj data and send to SoldInstrumentService
                var soldInstrumentDTO = new SoldInstrumentDTO
                {
                    Amount          = stockSaleInfo.Amount,
                    Name            = stockSaleInfo.Name,
                    PurchasePrice   = stockDbOBj.PurchasePrice,
                    PuchaseDate     = stockDbOBj.PurchaseDate,
                    SalePrice       = stockSaleInfo.SellPrice,
                    SaleDate        = DateTime.Now,
                    DiscountApplied = stockDbOBj.PurchaseDate.AddMonths(12) <= DateTime.Now ? true : false,
                    Profit          = stockSaleInfo.SellPrice * stockSaleInfo.Amount - stockDbOBj.PurchasePrice * stockSaleInfo.Amount
                };

                soldInstrumentDTO.CGTPayable = !soldInstrumentDTO.DiscountApplied ? (soldInstrumentDTO.Profit * .5) : soldInstrumentDTO.Profit;

                await _soldInstrumentsRepository.AddSoldInstrumentToDBTable(soldInstrumentDTO);
            }
        }
        public async Task <Response> AddToSoldInstrumentsTable(SoldInstrumentDTO soldInstrument)
        {
            if (soldInstrument == null)
            {
                return(new Response <Task>((int)HttpStatusCode.BadRequest));
            }

            await _soldInstrumentsRepository.AddSoldInstrumentToDBTable(soldInstrument);

            return(new Response <Task>((int)HttpStatusCode.OK));
        }