Exemple #1
0
        private void Add()
        {
            Console.Clear();

            Event events = new Event();

            Console.WriteLine("Add new Event:");

            Console.Write("Name: ");
            events.Name = Console.ReadLine();

            Console.Write("Location: ");
            events.Location = Console.ReadLine();

            while (!ValidDate)
            {
                Console.Write("Please enter Start Date in format DD.MM.YYYY: ");
                events.StartDateInput = Console.ReadLine();
                ValidDate             = ValidateDate.ValidateData(events.StartDateInput);

                Console.Write("Please enter End Date in format DD.MM.YYYY: ");
                events.EndDateInput = Console.ReadLine();
                ValidDate           = ValidateDate.ValidateData(events.EndDateInput);
            }
            while (!ValidTime)
            {
                Console.Write("Please enter Start Time in format HH:mm:ss: ");
                events.StartTimeInput = Console.ReadLine();
                ValidTime             = ValidateTime.ValidatingTime(events.StartTimeInput);

                Console.Write("Please enter End Time in format HH:mm:ss: ");
                events.EndTimeInput = Console.ReadLine();
                ValidTime           = ValidateTime.ValidatingTime(events.EndTimeInput);
            }

            Repository.EventRepository eventsRepository = new Repository.EventRepository("events.txt");
            eventsRepository.Save(events);

            Console.WriteLine("Event saved successfully.");
            Console.ReadKey(true);
        }
Exemple #2
0
        private void Update()
        {
            Console.Clear();

            Console.Write("Event ID: ");
            int eventId = Convert.ToInt32(Console.ReadLine());

            Repository.EventRepository eventsRepository = new Repository.EventRepository("events.txt");
            Event events = eventsRepository.GetById(eventId);

            if (events == null)
            {
                Console.Clear();
                Console.WriteLine("Event not found.");
                Console.ReadKey(true);
                return;
            }

            Console.WriteLine("Editing Event (" + events.Name + ")");
            Console.WriteLine("ID:" + events.Id);

            Console.WriteLine("Name :" + events.Name);
            Console.Write("New Name:");
            string name = Console.ReadLine();

            Console.WriteLine("Location :" + events.Location);
            Console.Write("New Location:");
            string location = Console.ReadLine();

            Console.WriteLine("Start Date :" + events.StartDateInput);
            Console.Write("New Start Date in format DD.MM.YYYY: ");
            string startDate = Console.ReadLine();

            ValidDate = ValidateDate.ValidateData(startDate);

            Console.WriteLine("End Date :" + events.EndDateInput);
            Console.Write("New End Date in format DD.MM.YYYY: ");
            string endDate = Console.ReadLine();

            ValidDate = ValidateDate.ValidateData(endDate);

            Console.WriteLine("Start Time :" + events.StartTimeInput);
            Console.Write("New Start Time in format HH:mm:ss: ");
            string startTime = Console.ReadLine();

            ValidTime = ValidateTime.ValidatingTime(startTime);

            Console.WriteLine("End Time :" + events.EndTimeInput);
            Console.Write("New End Time in format HH:mm:ss: ");
            string endTime = Console.ReadLine();

            ValidTime = ValidateTime.ValidatingTime(endTime);

            if (!string.IsNullOrEmpty(name))
            {
                events.Name = name;
            }
            if (!string.IsNullOrEmpty(location))
            {
                events.Location = location;
            }
            if (!string.IsNullOrEmpty(startDate))
            {
                events.StartDateInput = startDate;
            }
            if (!string.IsNullOrEmpty(endDate))
            {
                events.EndDateInput = endDate;
            }
            if (!string.IsNullOrEmpty(startTime))
            {
                events.StartTimeInput = startTime;
            }
            if (!string.IsNullOrEmpty(endTime))
            {
                events.EndTimeInput = endTime;
            }

            eventsRepository.Save(events);

            Console.WriteLine("Event saved successfully.");
            Console.ReadKey(true);
        }