public static SearchFDResponse SearchFD(string searchKey) { var dataAccess = GenericDataAccess.GetDatabase(); var mongoCollection = GetMongoDBCollection <FixedDeposite> .GetDatabaseCollection(dataAccess, "FixedDeposits"); var fds = mongoCollection.Find(x => x.FdId == searchKey).ToList(); if (fds == null) { throw new MongoDBDataAccessException("Exception while sarching FD"); } List <FixedDeposite> ListFDs = new List <FixedDeposite>(); if (fds.Capacity > 0) { foreach (FixedDeposite fd in fds) { ListFDs.Add(fd); } } return(new SearchFDResponse() { ListOfFDs = ListFDs }); }
//static MongoClient mongoClient; public static CreateFdResponse Insert(FixedDeposite fd) { try { var dataAccess = GenericDataAccess.GetDatabase(); var mongoCollection = GetMongoDBCollection <FixedDeposite> .GetDatabaseCollection(dataAccess, "FixedDeposits"); mongoCollection.InsertOne(fd); if (fd.ID == null) { throw new MongoDBDataAccessException("Exception while creating fd"); } } catch (MongoDBDataAccessException ex) { throw new MongoDBDataAccessException(ex.Message, ex); } catch (Exception ex) { throw new Exception("Undefined Exception." + ex.Message, ex); } return(new CreateFdResponse() { FDId = ObjectId.GenerateNewId(), IsFdCreated = true, IsOperationSuccess = true }); }
public static CreateUserResponse CreateUser(User user) { try { var dataAccess = GenericDataAccess.GetDatabase(); var mongoCollection = GetMongoDBCollection <User> .GetDatabaseCollection(dataAccess, "Users"); mongoCollection.InsertOne(user); if (user.ID == null) { throw new MongoDBDataAccessException("Exception while creating user"); } } catch (Exception ex) { throw new Exception(ex.Message, ex); } return(new CreateUserResponse() { ID = ObjectId.GenerateNewId(), IsUserCreated = true, Message = "User Created" }); }
public static bool ValidateIfUserExists(string username, string pan) { var dataAccess = GenericDataAccess.GetDatabase(); var mongoCollection = GetMongoDBCollection <User> .GetDatabaseCollection(dataAccess, "Users"); if (mongoCollection.Find(x => x.UserName == username && x.PAN == pan).CountDocuments() == 1) { return(true); } else { return(false); } }
public static string GetSalt(string username) { string salt; try { var dataAccess = GenericDataAccess.GetDatabase(); var mongoCollection = GetMongoDBCollection <User> .GetDatabaseCollection(dataAccess, "Users"); salt = mongoCollection.Find(x => x.UserName == username).FirstOrDefault().Salt; // check how can you select the salt value from json/single value if (salt == null) { throw new MongoDBDataAccessException("Unable to find salt for respective user"); } } catch (Exception ex) { throw new Exception(ex.Message, ex); } return(salt); }