Ejemplo n.º 1
0
        public ActionResult <Habit> Log(Guid userID, Guid id)
        {
            NpgsqlConnection _connection = new NpgsqlConnection(_connstringgg);

            _connection.Open();

            ILogsRepository  repoLog = new PostgresLogsRepository(_connection, null);
            IHabitRepository repo    = new PostgresHabitRepository(_connection, null);

            Logs founded_log = repoLog.FindByHabitIdAndUserId(id, userID);

            if (founded_log == null)
            {
                return(NotFound("This habit has no log history"));
            }

            Habit founded_habit = repo.FindByIdAndUserId(id, userID);

            if (founded_habit == null)
            {
                return(NotFound("The habit is doesn't exist"));
            }

            Habit founded = new Habit(founded_habit.ID, founded_habit.UserId, founded_habit.Name, founded_habit.DayOff, new Logs(founded_log.LogCount, founded_log.GetLogDate));

            _connection.Close();
            return(founded);
        }
        public void CheckAchievementDominating()
        {
            IAchievementGainer _dominate = new DominatingGain();

            NpgsqlConnection connection = new NpgsqlConnection(_connstring);

            connection.Open();

            User popo = User.NewUser("Popo");

            IHabitRepository habitRepo = new PostgresHabitRepository(connection, null);
            IBadgeRepository badgeRepo = new PostgresBadgeRepository(connection, null);

            Habit belajar = Habit.addNewHabit(popo.ID, "Belajar", new string[] { "Sat", "Mon" });

            habitRepo.Create(belajar);
            Habit olahraga = Habit.addNewHabit(popo.ID, "Olahraga", new string[] { "Mon" });

            habitRepo.Create(olahraga);
            List <Habit> habitList = new List <Habit>();

            habitList.Add(belajar);
            habitList.Add(olahraga);
            AbcApplication daily = new HabitTracker(habitList);

            ILogsRepository repoLogs = new PostgresLogsRepository(connection, null);

            Track track;

            track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 1));
            daily.Do(track);
            repoLogs.AddLogs(track);

            track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 2));
            daily.Do(track);
            repoLogs.AddLogs(track);

            track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 3));
            daily.Do(track);
            repoLogs.AddLogs(track);

            track = new HabitTrack(belajar, popo.ID, new DateTime(2020, 3, 4));
            daily.Do(track);
            repoLogs.AddLogs(track);

            Habit founded_habit = habitRepo.FindByIdAndUserId(belajar.ID, popo.ID);
            int   listSize      = founded_habit.Log.GetLogDate.Count;

            Assert.True(founded_habit.isDominating() == true);

            if (founded_habit.isDominating())
            {
                badgeRepo.CreateBadge(_dominate.GainAchievement(popo.ID), founded_habit.Log.GetLogDate[listSize - 1]);
            }

            connection.Close();
        }