Owen Bonham
Owen Bonham

Reputation: 35

RAVENDB The name "Store" doesn't exist in the current context

I've been working on getting this to work all day, and haven't had any success. I want to clean up my code and separate different chunks of code into different classes and functions. Here is a chunk of code that refuses to run.

using System;
using Raven.Client.Documents;

namespace RavendbTest
{


    class Program
    { 
        static void Main(string[] args)
        {
            var store = new DocumentStore
            {
                Urls = new[] { "http://localhost:8080" },
                Database = "Tasks"
            };

            store.Initialize();

        }
        
    
    

        static void Checking()
        {
            Console.WriteLine("Login or Sign Up? (L/S)");
            string userInput = Console.ReadLine();

            if (userInput.ToLower() == "l")
            {
                Console.WriteLine("Logging you in");
            }
            else if (userInput.ToLower() == "s")
            {
                Console.WriteLine("Signing you up\n");
                Console.Write("First Name: ");
                string firstName = Console.ReadLine();
                char firstNameInitial = firstName.ToLower()[0];
                Console.WriteLine(firstNameInitial);
                Console.Write("Last Name: ");
                string lastName = Console.ReadLine();
                char lastNameInitial = lastName.ToLower()[0];
                Console.WriteLine(lastNameInitial);
                Console.Write("Email: ");
                string email = Console.ReadLine();
                string combinedInitial = firstNameInitial.ToString() + lastNameInitial.ToString();
                Console.WriteLine(combinedInitial);

                // Checking if email has a '@' symbol in it. Determine validity
                bool isVerified = false;
                for (int i = 0; email.Length > i; i++)
                {
                    if (email[i] != '@')
                    {
                        continue;
                    }
                    else if (email[i] == '@')
                    {
                        isVerified = true;
                    }
                }

                if (isVerified == true)
                {


                    using (var session = Store.OpenSession())
                    {
                        var task = session.Load<Entity>(combinedInitial + email);
                        if (task == null)
                        {
                            Console.WriteLine("Creating your account");
                            var newUser = new Entity
                            {
                                Id = combinedInitial + email,
                                FirstName = firstName,
                                LastName = lastName,
                                Email = email
                            };

                            session.Store(newUser);
                            session.SaveChanges();
                        }
                        else
                        {
                            Console.WriteLine("This email is already in use... Would you like to login? (Y/N)");
                            string changeChoice = Console.ReadLine();
                            if (changeChoice.ToLower()[0] == 'y')
                            {

                            }
                            else
                            {
                                Console.WriteLine("Exiting Program");

                            }
                        }
                        using (var session = store.OpenSession())
                        {
                            var task = session.Load<Entity>(combinedInitial + email);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Please enter a valid email address");
                    Console.WriteLine("Exiting Program");
                }

            }
            else
            {
                Console.WriteLine("Error");
            }



        }


    }
}

I thinking that I'm getting errors because my function checking can't see that I've already initialize a DocumentStore. Any help is greatly appreciated

Upvotes: 2

Views: 84

Answers (0)

Related Questions