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 <TraderInfoEntity> CreateAsync(TraderInfoEntity entity) { var validationResult = await new TraderInfoEntityValidation().ValidateAsync(entity); if (!validationResult.IsValid) { throw new InvalidDataException(ErrorCode.CannotCreateTraderInfo, string.Join(" ", validationResult.Errors)); } if (await _repository.IsExistAsync(entity.Id)) { throw new InvalidDataException(ErrorCode.TraderInfoIdExist); } if (!await _identityHttpService.IsExistUserAsync(entity.Id)) { throw new InvalidDataException(ErrorCode.UserNotFound); } var result = await _repository.InsertAsync(entity); if (result == null) { throw new InvalidDataException(ErrorCode.CannotCreateTraderInfo); } await _repository.UnitOfWork.SaveChangesAsync(); return(result); }