示例#1
0
        public void AddEntry(string entryDate   = null,
                             string description = null, string defaultInput = null)
        {
            var isFinished = false;

            while (!isFinished)
            {
                Console.WriteLine("\nPlease provide a date for your entry. Valid format is dd/MM/yy HH:mm\n");

                var inputDate     = entryDate ?? _interface.GetInput();
                var formattedDate = DateTimeExtensions.ValidateDate(inputDate);

                if (formattedDate == null || EntryExists(formattedDate))
                {
                    if (entryDate == null)
                    {
                        continue;
                    }
                    break;
                }

                if (Convert.ToDateTime(formattedDate) < DateTime.Now)
                {
                    Console.WriteLine("\nDate must be later than current date\n");

                    if (entryDate == null)
                    {
                        continue;
                    }
                    break;
                }

                Console.WriteLine("Description:\n");
                description ??= _interface.GetInput();

                while (string.IsNullOrEmpty(description))
                {
                    Console.WriteLine("\nPlease provide a description or press 'd' to exit:\n");

                    var input = defaultInput ?? _interface.GetInput();
                    if (input.ToLower() == "d")
                    {
                        return;
                    }
                    if (defaultInput != null)
                    {
                        break;
                    }
                }

                _entries.Add(new CalendarEntry
                {
                    Date        = formattedDate,
                    Description = description
                });

                _context.SaveChanges(_entries);
                isFinished = true;
            }
        }