示例#1
0
        public async Task <bool> ListCarsAsync(int carId, int amount, int dealerId)
        {
            //check if car exists
            var car = await _carRepository.GetCarByIdAsync(carId);

            if (car == null)
            {
                throw new KeyNotFoundException();
            }

            //get stock for the dealer and update accordingly
            var stock = await _stockRepository.GetStockAsync(car.Id, dealerId);

            if (stock == null)
            {
                stock = new Stock
                {
                    CarId    = carId,
                    Amount   = amount,
                    DealerId = dealerId
                };
                return(await _stockRepository.CreateStockAsync(stock));
            }
            else
            {
                stock.Amount += amount;
                return(await _stockRepository.UpdateStockAsync(stock));
            }
        }
示例#2
0
        public async Task <StockDetailsModel> CreateStockAsync(StockCreateModel createModel)
        {
            if (createModel == null)
            {
                throw new ArgumentNullException(nameof(createModel));
            }

            if (await _stockRepository.HasStockWithIsinAsync(createModel.Isin))
            {
                throw new ArgumentException();
            }

            var stockEntity   = _mapper.Map <Stock>(createModel);
            var createdEntity = await _stockRepository.CreateStockAsync(stockEntity);

            return(_mapper.Map <StockDetailsModel>(createdEntity));
        }