コード例 #1
0
        public async Task <Watchlist> CreateAsync(Watchlist item)
        {
            if (!await _identityHttpService.IsExistUserAsync(item.UserId))
            {
                throw new InvalidDataException(ErrorCode.UserNotFound);
            }

            foreach (var i in await _repository.GetAsync(w => w.UserId == item.UserId))
            {
                if (i.Name == item.Name)
                {
                    throw new InvalidDataException(ErrorCode.InvalidMarket, "Watchlist name must be unique");
                }
            }

            foreach (var mw in item.MarketWatchlists)
            {
                if (!await _marketRepository.IsExistAsync(mw.MarketId))
                {
                    throw new NotFoundException(ErrorCode.MarketNotFount);
                }
            }

            var entity = await _repository.InsertAsync(item);

            await _repository.UnitOfWork.SaveChangesAsync();

            return(entity);
        }