Beispiel #1
0
        internal static Volunteer AddVolunteerfromCmd()//Aici se creaza un nou voluntar de la tastatura
        {
            Volunteer vol = new Volunteer();

            Console.WriteLine("You have chosen to add a Volunteer");
            Console.WriteLine("Please enter the persons:");
            Console.WriteLine("Firstname: ");
            vol.Firstname = Console.ReadLine();
            Console.WriteLine("Lastname: ");
            vol.Lastname = Console.ReadLine();
            do
            {
                try
                {
                    vol.Age = 0;
                    Console.WriteLine("Age: ");
                    vol.Age = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception)
                {
                    Console.WriteLine("Please enter a Number");
                    vol.Age = 0;
                }
            } while (vol.Age < 1);// int  pentru age

            /*Console.WriteLine("Country: ");
             * vol.Address.Country = Console.ReadLine();
             * Console.WriteLine("City: ");
             * vol.Address.City = Console.ReadLine();
             * Console.WriteLine("Street: ");
             * vol.Address.Street = Console.ReadLine();
             * Console.WriteLine("Number: ");
             * vol.Address.Number = Console.ReadLine();
             * Console.WriteLine("Gender: ");
             * vol.Gender = Console.ReadLine();*/
            do
            {
                try
                {
                    vol.birthdate.Year = 0;
                    Console.WriteLine("Birth Year: ");
                    vol.birthdate.Year = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception)
                {
                    Console.WriteLine("Please enter a Number");
                    vol.birthdate.Year = 0;
                }
            } while (vol.birthdate.Year < 1);//int pentru brthyear
            do
            {
                try
                {
                    vol.birthdate.Month = 0;
                    Console.WriteLine("Birth Month: ");
                    vol.birthdate.Month = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception)
                {
                    Console.WriteLine("Please enter a Number");
                    vol.birthdate.Month = 0;
                }
            } while (vol.birthdate.Month < 1);//int pentru brthmonth
            do
            {
                try
                {
                    vol.birthdate.Day = 0;
                    Console.WriteLine("Birth Day: ");
                    vol.birthdate.Day = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception)
                {
                    Console.WriteLine("Please enter a Number");
                    vol.birthdate.Day = 0;
                }
            } while (vol.birthdate.Day < 1);//int pentru birthday

            /* Console.WriteLine("Has Driving License? (true/false)"); //trebe facut pentru boolean
             * vol.AditionalInfo.HasDrivingLicence = Convert.ToBoolean(Console.ReadLine());
             * Console.WriteLine("Has Car? (true/false)");//trebe facut pentru boolean
             * vol.AditionalInfo.HasCar = Convert.ToBoolean(Console.ReadLine());
             * Console.WriteLine("EmailAddress: : ");
             * vol.ContactInformations.MailAdress = Console.ReadLine();
             * Console.WriteLine("PhoneNumber: : ");
             * vol.ContactInformations.PhoneNumber = Console.ReadLine();
             * Console.WriteLine("HasContract (true/false)");//trebe facut pentru boolean
             * vol.Contract.HasContract = Convert.ToBoolean(Console.ReadLine());
             * Console.WriteLine("Contract Period in months");
             * vol.Contract.ContractPeriod = Convert.ToInt16(Console.ReadLine());
             * Console.WriteLine("Number of Registration: : ");
             * vol.Contract.NumberOfRegistration = Convert.ToInt16(Console.ReadLine());
             * Console.WriteLine("Registration Year");
             * vol.registrationday.Year = Convert.ToInt16(Console.ReadLine());
             * Console.WriteLine("Registration Month");
             * vol.registrationday.Month = Convert.ToInt16(Console.ReadLine());
             * Console.WriteLine("Registration Day");
             * vol.registrationday.Day = Convert.ToInt16(Console.ReadLine());
             * Console.WriteLine("Desired Workplace");
             * vol.Desired_workplace = Console.ReadLine();
             * Console.WriteLine("Field of activity");
             * vol.Field_of_activity = Console.ReadLine();
             * Console.WriteLine("Hour Count");
             * vol.HourCount = Convert.ToInt16(Console.ReadLine());
             * Console.WriteLine("Active? (true/false)");//trebe facut pentru boolean
             * vol.InActivity = Convert.ToBoolean(Console.ReadLine());
             * Console.WriteLine("Occupation");
             * vol.Occupation = Console.ReadLine();
             * Console.WriteLine("Occupation Description");
             * vol.Occupation_description = Console.ReadLine();
             * Console.WriteLine("How many Hours a week");
             * vol.WorkSchedule.HoursWeek = Console.ReadLine();
             * Console.WriteLine("Which days is he available");
             * vol.WorkSchedule.Comments.Days = Console.ReadLine();
             * Console.WriteLine("What hours is he available");
             * vol.WorkSchedule.Comments.TimeAvailability = Console.ReadLine();*/

            Console.WriteLine("Volunteer successfully added!");

            return(vol);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var              client = new MongoClient();
            var              db     = client.GetDatabase("SiemensProject");                    //craeaza baza de date cu numele ...
            var              volunteercollection = db.GetCollection <Volunteer>("Volunteers"); //Adauga o colectie in baza de date anterior creata
            var              eventcollection     = db.GetCollection <Event>("Events");         //creeaza baza de date cu numele..
            bool             finished            = false;
            int              choice;
            List <Volunteer> allvolunteers2 = new List <Volunteer>();
            List <Event>     allevents      = new List <Event>();
            //DONE
            //Intrebare daca Nar fi bine sa sterg characterul care cauzeaza problema
            string jsontext = File.ReadAllText(@"volunteer.json");
            bool   success  = false;

            //while (success = true)
            //{
            try
            {
                var tmpObj = JsonValue.Parse(jsontext);
                JsonConvert.PopulateObject(jsontext, allvolunteers2); //Daca Jsonul este empty da eroare, insa este necesar pentru a trece datele in array din json
                success = true;
            }
            catch (FormatException fex)
            {
                //Invalid json format
                Console.WriteLine(fex);
                finished = true;
            }
            catch (Exception ex) //some other exception
            {
                Console.WriteLine(ex.ToString());
                finished = true;
            }
            //}
            string jsontext_e = File.ReadAllText(@"event.jason");
            bool   success2   = false;

            try
            {
                var tmpObj = JsonValue_e.Parse(jsontext);
                JsonConvert.PopulateObject(jsontext, allevents); //Daca Jsonul este empty da eroare, insa este necesar pentru a trece datele in array din json
                success2 = true;
            }
            catch (FormatException fex)
            {
                //Invalid json format
                Console.WriteLine(fex);
                finished = true;
            }
            catch (Exception ex) //some other exception
            {
                Console.WriteLine(ex.ToString());
                finished = true;
            }



            while (finished != true)
            {
                Console.WriteLine("Press 1 to add a person!");
                Console.WriteLine("Press 2 to Remove a person!");
                Console.WriteLine("Press 3 to Edit a person!");
                Console.WriteLine("Press 4 to Show Everyone!");
                Console.WriteLine("Press 5 to Show Upcoming birthdays!");
                Console.WriteLine("Press 6 to Show Upcoming contract expirations!");
                Console.WriteLine("Press 7 to add an event!");
                Console.WriteLine("Press 8 to remove an event!");
                Console.WriteLine("Press 9 to Edit an Event!");
                Console.WriteLine("Press 10 to Show all events!");
                Console.WriteLine("Press 11 to Exit!");
                Console.WriteLine("Please enter your choice!");
                try
                {
                    choice = Convert.ToInt16(Console.ReadLine());
                    {
                        switch (choice)
                        {
                        case 1:
                            Volunteer vol = Db.AddVolunteerfromCmd();
                            allvolunteers2.Add(vol);
                            Db.SavetoJson(allvolunteers2);

                            break;

                        case 2:
                            int y = Db.Selector(allvolunteers2);
                            allvolunteers2.RemoveAt(y);    //metoda pre definita
                            Console.WriteLine("Volunteer Deleted");
                            Db.SavetoJson(allvolunteers2); //mereu daca modificam ceva in allvollunteers2 trebuie sa facem schimbarea si in json ca data viitoare sa continuam tot de aici
                            break;

                        case 3:
                        /* int z = Db.Selector(allvolunteers2);
                         * Db.Edit(allvolunteers2, z);
                         * Db.SavetoJson(allvolunteers2);
                         * break;*/

                        case 4:
                            Db.Showallvolunteers(allvolunteers2);

                            break;

                        case 5:
                            Db.ShowVolunteerbd(allvolunteers2);

                            break;

                        case 6:
                            Db.ShowVolunteercontractexp(allvolunteers2);
                            break;

                        case 7:
                            Event new_event = Db.AddEventFromKeyboard();
                            allevents.Add(new_event);
                            Db.SavetoJson_Event(allevents);
                            break;

                        case 8:
                            int x = Db.Selector_Event(allevents);
                            allevents.RemoveAt(x);
                            Console.WriteLine("Event Deleted");
                            Db.SavetoJson_Event(allevents);
                            break;

                        case 9:
                        /*  int w = Db.Selector_Event(allevents);
                         * Db.Edit_e(allevents, w);
                         * Db.SavetoJson_Event(allevents);
                         * break;*/
                        case 10:
                            Db.ShowallvolunteersEvent(allevents);
                            break;

                        case 11:
                            finished = true;

                            break;

                        default:
                            Console.WriteLine("Not a valid option!");

                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }