Esempio n. 1
0
        public async Task<ActionResult<TradeViewModel>> Add(TradeViewModel tradeViewModel)
        {
            try
            {
                if (!ModelState.IsValid) return CustomResponse(ModelState);

                if (tradeViewModel.Value >= 1000000 && tradeViewModel.Sector.Description == "Public")
                {
                    tradeViewModel.Category = await _categoryRepository.GetCategoryByInitials("B");
                }
                else if (tradeViewModel.Value >= 1000000 && tradeViewModel.Sector.Description == "Private")
                {
                    tradeViewModel.Category = await _categoryRepository.GetCategoryByInitials("C");
                }
                else
                {
                    tradeViewModel.Category = await _categoryRepository.GetCategoryByInitials("A");
                }

                //await _tradeService.Add(_mapper.Map<Trade>(tradeViewModel));

                await _tradeRepository.AddTradeWithSector(_mapper.Map<Trade>(tradeViewModel));

                return CustomResponse(tradeViewModel);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.ToString());
            }
        }