Exemple #1
0
        public ConsoleCommandResult Execute(ParameterCollection parameterCollection)
        {
            using (BucketListRepository repo = new BucketListRepository())
            {
                switch (parameterCollection[0])
                {
                case "all":
                    List <BucketListEntry> allEntries = repo.Query
                                                        .ToList();
                    PrintEntryList(allEntries);
                    break;

                case "unchecked":
                    List <BucketListEntry> uncheckedEntries = repo.Query
                                                              .Where(e => !e.CheckedDate.HasValue)
                                                              .ToList();
                    PrintEntryList(uncheckedEntries);
                    break;

                case "checked":
                    List <BucketListEntry> checkedEntries = repo.Query
                                                            .Where(e => e.CheckedDate.HasValue)
                                                            .ToList();
                    PrintEntryList(checkedEntries);
                    break;

                case "random":
                    List <BucketListEntry> randomEntries = GetRandomEntries(repo);
                    PrintEntryList(randomEntries);
                    break;

                case "findbyid":
                    int entryId = Convert.ToInt32(parameterCollection[1]);
                    List <BucketListEntry> entryById = repo.Query
                                                       .Where(e => e.Id == entryId)
                                                       .ToList();
                    PrintEntryList(entryById);
                    break;

                case "findbydescription":
                    List <BucketListEntry> foundEntries = repo.Query
                                                          .Where(e => e.Description.Contains(parameterCollection[1]))
                                                          .ToList();
                    PrintEntryList(foundEntries);
                    break;

                default:
                    return(ConsoleCommandResult.BadInvoke);
                }
                return(ConsoleCommandResult.Success);
            }
        }
Exemple #2
0
        public ConsoleCommandResult Execute(ParameterCollection parameterCollection)
        {
            using (BucketListRepository repo = new BucketListRepository())
            {
                switch (parameterCollection[0])
                {
                    case "all":
                        List<BucketListEntry> allEntries = repo.Query
                            .ToList();
                        PrintEntryList(allEntries);
                        break;

                    case "unchecked":
                        List<BucketListEntry> uncheckedEntries = repo.Query
                            .Where(e => !e.CheckedDate.HasValue)
                            .ToList();
                        PrintEntryList(uncheckedEntries);
                        break;

                    case "checked":
                        List<BucketListEntry> checkedEntries = repo.Query
                            .Where(e => e.CheckedDate.HasValue)
                            .ToList();
                        PrintEntryList(checkedEntries);
                        break;

                    case "random":
                        List<BucketListEntry> randomEntries = GetRandomEntries(repo);
                        PrintEntryList(randomEntries);
                        break;

                    case "findbyid":
                        int entryId = Convert.ToInt32(parameterCollection[1]);
                        List<BucketListEntry> entryById = repo.Query
                            .Where(e => e.Id == entryId)
                            .ToList();
                        PrintEntryList(entryById);
                        break;

                    case "findbydescription":
                        List<BucketListEntry> foundEntries = repo.Query
                            .Where(e => e.Description.Contains(parameterCollection[1]))
                            .ToList();
                        PrintEntryList(foundEntries);
                        break;

                    default:
                        return ConsoleCommandResult.BadInvoke;
                }
                return ConsoleCommandResult.Success;
            }
        }
Exemple #3
0
        private ConsoleCommandResult CreateEntry(string description, EntryDifficulty difficulty)
        {
            using (BucketListRepository repo = new BucketListRepository())
            {
                BucketListEntry entry = repo.Create(description, difficulty);

                if (entry != null)
                {
                    ConsoleWriter.WriteLine("Added entry with Id {0}", ConsoleColor.Green, entry.Id);
                    return(ConsoleCommandResult.Success);
                }
                else
                {
                    ConsoleWriter.WriteLine("Error occurred while saving entry", ConsoleColor.Red);
                    return(ConsoleCommandResult.Exception);
                }
            }
        }
Exemple #4
0
        private ConsoleCommandResult CreateEntry(string description, EntryDifficulty difficulty)
        {
            using (BucketListRepository repo = new BucketListRepository())
            {
                BucketListEntry entry = repo.Create(description, difficulty);

                if (entry != null)
                {
                    ConsoleWriter.WriteLine("Added entry with Id {0}", ConsoleColor.Green, entry.Id);
                    return ConsoleCommandResult.Success;
                }
                else
                {
                    ConsoleWriter.WriteLine("Error occurred while saving entry", ConsoleColor.Red);
                    return ConsoleCommandResult.Exception;
                }
            }
        }
Exemple #5
0
        private List <BucketListEntry> GetRandomEntries(BucketListRepository repo)
        {
            // TODO replace stupid algorithm
            List <BucketListEntry> list    = new List <BucketListEntry>(RandomEntriesCount);
            List <BucketListEntry> entries = repo.Query.Where(e => !e.CheckedDate.HasValue).ToList();

            while (entries.Any() && list.Count < RandomEntriesCount)
            {
                BucketListEntry entry = entries[Rand.Next(0, entries.Count)];

                if ((int)entry.Difficulty < Rand.Next(1, 8))
                {
                    list.Add(entry);
                    entries.Remove(entry);
                }
            }

            return(list);
        }
Exemple #6
0
        public ConsoleCommandResult Execute(ParameterCollection parameterCollection)
        {
            switch (parameterCollection[0])
            {
            case "check":
                int id = Convert.ToInt32(parameterCollection[1]);
                BucketListRepository repo = new BucketListRepository();
                bool isChecked            = repo.Check(id);
                if (isChecked)
                {
                    ConsoleWriter.WriteLine($"Checked entry with Id {id}", ConsoleColor.Green);
                }
                else
                {
                    ConsoleWriter.WriteLine($"Could not check entry with Id {id}", ConsoleColor.Yellow);
                }
                break;

            default:
                return(ConsoleCommandResult.BadInvoke);
            }
            return(ConsoleCommandResult.Success);
        }
Exemple #7
0
 public HomeController(BucketListRepository bucketListRepository)
 {
     this.bucketListRepository = bucketListRepository;
 }
Exemple #8
0
        private List<BucketListEntry> GetRandomEntries(BucketListRepository repo)
        {
            // TODO replace stupid algorithm
            List<BucketListEntry> list = new List<BucketListEntry>(RandomEntriesCount);
            List<BucketListEntry> entries = repo.Query.Where(e => !e.CheckedDate.HasValue).ToList();

            while (entries.Any() && list.Count < RandomEntriesCount)
            {
                BucketListEntry entry = entries[Rand.Next(0, entries.Count)];

                if ((int)entry.Difficulty < Rand.Next(1, 8))
                {
                    list.Add(entry);
                    entries.Remove(entry);
                }
            }

            return list;
        }