Exemple #1
0
        public int DeleteBankDetails(UserBankDetails objuser)
        {
            int id = 0;

            try
            {
                using (var conn = new SqlConnection(ContexDetails.Connectiondetails()))
                {
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "sp_DeleteBankDetails";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Id", objuser.Id < 0 ? 0 : objuser.Id);
                        cmd.Parameters.AddWithValue("@UserId", objuser.CreatedBy);
                        cmd.ExecuteNonQuery();
                        id = 1;
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(id);
        }
Exemple #2
0
        public int AddUpdateUserBankDetails(UserBankDetails objuser)
        {
            int id = 0;

            try
            {
                using (var conn = new SqlConnection(ContexDetails.Connectiondetails()))
                {
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "sp_AddUpdateUserBankDetails";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Id", objuser.Id < 0 ? 0 : objuser.Id);
                        cmd.Parameters.AddWithValue("@AccountHolderName", objuser.AccountHolderName);
                        cmd.Parameters.AddWithValue("@BankName", objuser.BankName);
                        cmd.Parameters.AddWithValue("@AccountNumber", objuser.AccountNumber);
                        cmd.Parameters.AddWithValue("@IFSCCode", objuser.IFSCCode);
                        cmd.Parameters.AddWithValue("@CreatedBy", objuser.CreatedBy);
                        id = cmd.ExecuteNonQuery();
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(id);
        }
        public async Task ReturnTheBankDetils_WhenTheyAreDeleted()
        {
            //Arrange
            const string user1Id        = "poesho";
            const string user2Id        = "goesho";
            Guid         bankDetails1Id = Guid.NewGuid();
            Guid         bankDetails2Id = Guid.NewGuid();

            BankDetails mapInput            = null;
            var         mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(mpm => mpm.MapTo <BankDetailsViewModel>(It.IsAny <BankDetails>()))
            .Callback <object>(inputArg => mapInput = inputArg as BankDetails);

            var user1 = new User {
                Id = user1Id
            };
            var user2 = new User {
                Id = user2Id
            };
            var bankDetails1 = new BankDetails {
                Id = bankDetails1Id
            };
            var bankDetails2 = new BankDetails {
                Id = bankDetails2Id
            };
            var userBankDetails11 = new UserBankDetails {
                UserId = user1Id, BankDetailsId = bankDetails1Id, BankDetails = bankDetails1
            };
            var userBankDetails12 = new UserBankDetails {
                UserId = user1Id, BankDetailsId = bankDetails2Id, BankDetails = bankDetails2
            };
            var userBankDetails21 = new UserBankDetails {
                UserId = user2Id, BankDetailsId = bankDetails1Id, BankDetails = bankDetails1
            };
            var userBankDetails22 = new UserBankDetails {
                UserId = user2Id, BankDetailsId = bankDetails2Id, BankDetails = bankDetails2
            };
            var userBankDetailsRepoMock = new Mock <IRepository <UserBankDetails> >();

            userBankDetailsRepoMock
            .Setup(ubdrm => ubdrm.All())
            .Returns(new List <UserBankDetails> {
                userBankDetails11, userBankDetails12, userBankDetails21, userBankDetails22
            }
                     .AsQueryable()
                     .BuildMock()
                     .Object);

            var sut = new UserBankDetailsServices(mappingProviderMock.Object, userBankDetailsRepoMock.Object);
            //Act
            var result = await sut.DeleteUserBankDetailsAsync(bankDetails2Id.ToString(), user1Id);

            //Assert
            Assert.IsTrue(userBankDetails12.IsDeleted);
            mappingProviderMock.Verify(mpm => mpm.MapTo <BankDetailsViewModel>(bankDetails2), Times.Once);
            userBankDetailsRepoMock.Verify(ubdr => ubdr.SaveAsync(), Times.Once);
        }
        public async Task <BankDetailsViewModel> AddBankDetailsAsync(string number, int cvv, DateTime expiryDate, string userId)
        {
            int dateResult = DateTime.Compare(expiryDate, dateTime.Now());

            if (dateResult < 0)
            {
                throw new ArgumentOutOfRangeException("The card is expired!");
            }

            var potentialBankDetails = await bankDetailsRepo.All().Where(bd => bd.Number == number).FirstOrDefaultAsync();

            if (!(potentialBankDetails is null))
            {
                var potentialUserBankDetails = await userBankDetailsRepo.All()
                                               .Where(ubd => ubd.UserId == userId &&
                                                      ubd.BankDetailsId == potentialBankDetails.Id)
                                               .FirstOrDefaultAsync();

                if (potentialUserBankDetails is null)
                {
                    throw new ArgumentException("The card is already being used!");
                }
                if (potentialUserBankDetails.IsDeleted)
                {
                    potentialUserBankDetails.IsDeleted = false;
                    await userBankDetailsRepo.SaveAsync();

                    var modelToReturn = mappingProvider.MapTo <BankDetailsViewModel>(potentialBankDetails);
                    return(modelToReturn);
                }
                else
                {
                    throw new ArgumentException("Bank details already exists and it is connected to the user!");
                }
            }

            var bankDetails = new BankDetails
            {
                Number          = number,
                Cvv             = cvv,
                ExpiryDate      = expiryDate,
                CreatedOn       = DateTime.Now,
                IsDeleted       = false,
                UserBankDetails = new List <UserBankDetails>()
            };

            bankDetailsRepo.Add(bankDetails);
            var userBankDetails = new UserBankDetails {
                UserId = userId, BankDetailsId = bankDetails.Id
            };

            bankDetails.UserBankDetails.Add(userBankDetails);
            await bankDetailsRepo.SaveAsync();

            var model = mappingProvider.MapTo <BankDetailsViewModel>(bankDetails);

            return(model);
        }
        public async Task ThrowArgumentException_WhenUserBankDetailsAreNotFoundByUser()
        {
            //Arrange
            const string user1Id        = "poesho";
            const string user2Id        = "goesho";
            Guid         bankDetails1Id = Guid.NewGuid();
            Guid         bankDetails2Id = Guid.NewGuid();

            BankDetails mapInput            = null;
            var         mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(mpm => mpm.MapTo <BankDetailsViewModel>(It.IsAny <BankDetails>()))
            .Callback <object>(inputArg => mapInput = inputArg as BankDetails);

            var user1 = new User {
                Id = user1Id
            };
            var user2 = new User {
                Id = user2Id
            };
            var bankDetails1 = new BankDetails {
                Id = bankDetails1Id
            };
            var bankDetails2 = new BankDetails {
                Id = bankDetails2Id
            };
            var userBankDetails11 = new UserBankDetails {
                UserId = user1Id, BankDetailsId = bankDetails1Id, BankDetails = bankDetails1
            };
            var userBankDetails12 = new UserBankDetails {
                UserId = user1Id, BankDetailsId = bankDetails2Id, BankDetails = bankDetails2
            };
            var userBankDetails21 = new UserBankDetails {
                UserId = user2Id, BankDetailsId = bankDetails1Id, BankDetails = bankDetails1
            };
            var userBankDetails22 = new UserBankDetails {
                UserId = user2Id, BankDetailsId = bankDetails2Id, BankDetails = bankDetails2
            };
            var userBankDetailsRepoMock = new Mock <IRepository <UserBankDetails> >();

            userBankDetailsRepoMock
            .Setup(ubdrm => ubdrm.All())
            .Returns(new List <UserBankDetails> {
                userBankDetails11, userBankDetails12, userBankDetails21, userBankDetails22
            }
                     .AsQueryable()
                     .BuildMock()
                     .Object);

            var sut = new UserBankDetailsServices(mappingProviderMock.Object, userBankDetailsRepoMock.Object);
            //Act && Assert
            await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.DeleteUserBankDetailsAsync(bankDetails2Id.ToString(), "not" + user2Id));
        }
Exemple #6
0
        public async Task CreateTwoUserBalances()
        {
            //Arrange
            const string userId = "poesho";

            var mapInputList        = new List <BankDetails>();
            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(mpm => mpm.MapTo <ICollection <BankDetailsViewModel> >(It.IsAny <List <BankDetails> >()))
            .Callback <object>(inpt => mapInputList = inpt as List <BankDetails>);

            var memoryCache      = new MemoryCache(new MemoryCacheOptions());
            var currencyRepoMock = new Mock <IRepository <Currency> >();
            var balanceRepoMock  = new Mock <IRepository <Balance> >();

            var bankDetails1     = new BankDetails();
            var bankDetails2     = new BankDetails();
            var userBankDetails1 = new UserBankDetails {
                UserId = userId, BankDetails = bankDetails1
            };
            var userBankDetails2 = new UserBankDetails {
                UserId = userId, BankDetails = bankDetails2
            };
            var userBankDetails3 = new UserBankDetails {
                UserId = "not" + userId
            };
            var userBankDetailsMock = new Mock <IRepository <UserBankDetails> >();

            userBankDetailsMock
            .Setup(ubdm => ubdm.All())
            .Returns(new List <UserBankDetails> {
                userBankDetails1, userBankDetails2, userBankDetails3
            }
                     .AsQueryable()
                     .BuildMock()
                     .Object);

            var balanceTypeRepo = new Mock <IRepository <BalanceType> >();
            var userRepoMock    = new Mock <IRepository <User> >();

            var sut = new UserServices(userRepoMock.Object, mappingProviderMock.Object, memoryCache, currencyRepoMock.Object, balanceRepoMock.Object, userBankDetailsMock.Object, balanceTypeRepo.Object);
            //Act
            await sut.GetBankDetailsInformation(userId);

            //Assert
            Assert.IsTrue(mapInputList.Any(bankD => bankD.Equals(bankDetails1)));
            Assert.IsTrue(mapInputList.Any(bankD => bankD.Equals(bankDetails2)));
        }
Exemple #7
0
        public async Task <Tuple <bool, string, UserBankDetails> > InsertorUpdateUserBankDetails(UserBankDetails obj)
        {
            Tuple <bool, string, UserBankDetails> objKey = null;
            UserBankDetails userBank = new UserBankDetails();

            try
            {
                var parameters = new DynamicParameters();
                using (SqlConnection cxn = new SqlConnection(_dvDb))
                {
                    if (obj.ID != 0)
                    {
                        parameters.Add("@ID", obj.ID, DbType.Int32);
                    }
                    parameters.Add("@UserID", obj.UserID, DbType.Int32);
                    parameters.Add("@BankID", obj.BankID, DbType.Int32);
                    parameters.Add("@AccountHolderName", obj.AccountHolderName, DbType.String);
                    parameters.Add("@AccountNumber", obj.AccountNumber, DbType.String);
                    parameters.Add("@IFSCCode", obj.IFSCCode, DbType.String);
                    parameters.Add("@BranchName", obj.BranchName, DbType.String);
                    parameters.Add("@BranchAddress", obj.BranchAddress, DbType.String);
                    parameters.Add("@CreatedBy", Helper.FindUserByID().UserID, DbType.Int32);

                    var resultObj = await cxn.QueryAsync <UserBankDetails>("dbo.InsertorUpdate_UserBankDetails", parameters, commandType : CommandType.StoredProcedure);

                    userBank = resultObj.Single() as UserBankDetails;

                    cxn.Close();
                }
                if (obj.ID != 0)
                {
                    objKey = Tuple.Create(true, "User Bank Details inserted successfully.", userBank);
                }
                else
                {
                    objKey = Tuple.Create(true, "User Bank Details updated successfully.", userBank);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Write(ex);
                objKey = Tuple.Create(false, "Oops! User Bank Details inserted/updated failed.Please try again.", userBank);
            }

            return(objKey);
        }
        public ResponseModel AddUpdateUserBankDetails(UserBankDetails request)
        {
            IUserDetails _repository = new UserDetails();
            int          response    = 0;

            response = _repository.AddUpdateUserBankDetails(request);
            string        Status = "0";
            ResponseModel model  = new ResponseModel();

            if (response == 1)
            {
                model.Status  = "1";
                model.Message = "New bank details added successfully";
            }
            else
            {
                model.Status = "0";
            }
            return(model);
        }
Exemple #9
0
        public IList <UserBankDetails> GetBankDetailsByUser(int UserId)
        {
            IList <UserBankDetails> BankDetails = new List <UserBankDetails>();

            try
            {
                using (var conn = new SqlConnection(ContexDetails.Connectiondetails()))
                {
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "sp_GetBankDetailsByUser";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@UserId", UserId);
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                UserBankDetails model = new UserBankDetails();
                                model.Id = Convert.ToInt32(reader["Id"]);
                                model.AccountHolderName = Convert.ToString(reader["AccountHolderName"]);
                                model.BankName          = Convert.ToString(reader["BankName"]);
                                model.AccountNumber     = Convert.ToString(reader["AccountNumber"]);
                                model.IFSCCode          = Convert.ToString(reader["IFSCCode"]);
                                model.CreatedBy         = Convert.ToInt32(reader["CreatedBy"]);
                                model.UserId            = Convert.ToInt32(reader["UserId"]);
                                BankDetails.Add(model);
                            }
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(BankDetails);
        }
        public async Task <Tuple <bool, string, UserBankDetails> > InsertorUpdateUserBankDetails(UserBankDetails obj)
        {
            Tuple <bool, string, UserBankDetails> result = null;

            try
            {
                result = await _repo.InsertorUpdateUserBankDetails(obj);
            }
            catch (Exception ex)
            {
                ErrorLog.Write(ex);
            }

            return(result);
        }