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); }
public async Task <Stream> GetIconAsync(long id) { if (!await _repository.IsExistAsync(id)) { throw new NotFoundException(ErrorCode.MarketNotFount); } var filePath = Path.Combine(AppContext.BaseDirectory, "Icons", Path.ChangeExtension(id.ToString(), "ico")); _logger.LogInformation($"Downloading market icon \nfrom path - {filePath}"); return(await _fileService.DownloadFileAsync(filePath)); }