public VarlikResult AddWalletAddress(UserWalletDto userWalletDto) { var result = new VarlikResult(); using (var ctx = new VarlikContext()) { var isAdded = ctx.UserWallet.Any(l => l.IdUser == userWalletDto.IdUser && l.IdCoinType == userWalletDto.IdCoinType); if (isAdded) { result.Status = ResultStatus.AlreadyAdded; return(result); } var entity = userWalletDto.ToEntity(userWalletDto); var persistent = ctx.UserWallet.Add(entity); try { ctx.SaveChanges(); result.Success(); result.ObjectId = persistent.Id; } catch (Exception e) { Log.Error("AddWalletAddress", e); } } return(result); }
public async Task <Result <UserDto> > Update(Guid userId, UserWalletDto userWalletDto) { var user = await Context.Users.AsNoTracking().FirstOrDefaultAsync(u => u.Id == userId); if (user == null) { return(Result <UserDto> .Failed(new NotFoundObjectResult(new ApiMessage { Message = ResponseMessage.UserNotFound }))); } user.UserWallet = _mapper.Map <UserWallet>(userWalletDto); await Context.SaveChangesAsync(); return(Result <UserDto> .SuccessFull(_mapper.Map <UserDto>(user))); }
public IActionResult AddWalletToUser([FromBody] UserWalletDto userWallet) { if (_userRepository.GetUser(userWallet.UserId) == null) { return(NotFound()); } if (_walletRepository.GetWalletById(userWallet.WalletId) == null) { return(NotFound()); } var userWalletForCreate = _mapper.Map <UserWallet>(userWallet); _userWalletRepository.AddWalletToUser(userWalletForCreate); var userWalletToReturn = _mapper.Map <UserWalletDto>(userWalletForCreate); return(CreatedAtRoute("GetUserWallets", new { userId = userWalletToReturn.UserId }, userWalletToReturn)); }
public VarlikResult <UserWalletDto> GetWalletAddresByIdCoinType(long idUser, string idCoinType) { var result = new VarlikResult <UserWalletDto>(); using (var ctx = new VarlikContext()) { var fromEntity = new UserWalletDto().FromEntity().Expand(); result.Data = ctx.UserWallet .AsExpandable() .Where(l => l.IdUser == idUser && l.IdCoinType == idCoinType) .Select(fromEntity) .FirstOrDefault(); if (result.Data == null) { result.Status = ResultStatus.UserDoesNotHaveThisAddress; } else { result.Success(); } } return(result); }
public VarlikResult <WalletResultDto> AddWalletAddress(string idCoinType) { var result = new VarlikResult <WalletResultDto>(); result.Data = new WalletResultDto(); var userId = IdentityHelper.Instance.CurrentUserId; // has this wallet or not var alreadyAdded = DoesUserHaveThisAddress(userId, idCoinType); if (!alreadyAdded.IsSuccess) { result.Status = alreadyAdded.Status; return(result); } if (alreadyAdded.Data) { result.Status = ResultStatus.AlreadyAdded; return(result); } if (idCoinType == CoinTypeEnum.DogeCoin || idCoinType == CoinTypeEnum.LiteCoin || idCoinType == CoinTypeEnum.Btc) { // block io var walletManager = new BlockioWalletManager(); var walletApiRes = walletManager.CreateNewAddress(idCoinType); if (walletApiRes.IsSuccess) { UserWalletDto userWalletDto = new UserWalletDto(); userWalletDto.Address = walletApiRes.Data; userWalletDto.IdUser = userId; userWalletDto.IdCoinType = idCoinType; _userOperation.AddWalletAddress(userWalletDto); result.Data.Address = walletApiRes.Data; result.Success(); return(result); } } else if (idCoinType == CoinTypeEnum.Iota) { var walletManager = new IotaWalletManager(); var walletApiRes = walletManager.CreateNewAddress(); UserWalletDto userWalletDto = new UserWalletDto(); userWalletDto.Address = walletApiRes.Data.Address; userWalletDto.Secret = walletApiRes.Data.Secret; userWalletDto.IdUser = userId; userWalletDto.IdCoinType = idCoinType; _userOperation.AddWalletAddress(userWalletDto); result.Data = walletApiRes.Data; result.Success(); return(result); } else if (idCoinType == CoinTypeEnum.Ripple) { var walletManager = new RippleWalletManager(); var walletApiRes = walletManager.CreateNewAddress(); UserWalletDto userWalletDto = new UserWalletDto(); userWalletDto.Address = walletApiRes.Data.Address; userWalletDto.Secret = walletApiRes.Data.Secret; userWalletDto.IdUser = userId; userWalletDto.IdCoinType = idCoinType; _userOperation.AddWalletAddress(userWalletDto); result.Data = walletApiRes.Data; result.Success(); return(result); } return(new VarlikResult <WalletResultDto>()); }