Esempio n. 1
0
        public async Task AddTimeEntryToHourPoints(Guid userId, TimeEntry timeEntry)
        {
            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsWithTimeEntriesByDateAndUser(timeEntry.DateHourPointed, userId);

            HourPointConfigurations configurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            if (hourPoints is null)
            {
                hourPoints = new HourPoints(timeEntry.DateHourPointed.Date, userId);
                hourPoints.AddTimeEntry(timeEntry, configurations);
                _hourPointsRepository.AddHourPoints(hourPoints);
            }
            else
            {
                if (hourPoints.HasTimeEntry(timeEntry))
                {
                    return;
                }

                hourPoints.AddTimeEntry(timeEntry, configurations);
                _hourPointsRepository.UpdateHourPoints(hourPoints);
            }

            _hourPointsRepository.AddTimeEntry(timeEntry);
            await _hourPointsRepository.Commit();
        }
        public async Task <IActionResult> GetChartSixMonthsData()
        {
            DateTime currentDate = DateTime.Now.GetDateTimeInFirstDate();
            DateTime endDate     = currentDate.GetDateTimeInLastDate();
            DateTime startDate   = endDate.AddMonths(-5).GetDateTimeInFirstDate();

            TimeNotesUser identityUser = await _userManager.GetUserAsync(User);

            if (identityUser is null)
            {
                throw new ArgumentException($"Usuário não encontrado na base de dados.");
            }

            IEnumerable <HourPoints> userHourPoints = await _hourPointsRepository
                                                      .GetHourPointsWhere(x => (x.Date.Date >= startDate.Date && x.Date.Date <= endDate.Date) && x.UserId.Equals(Guid.Parse(identityUser.Id)));

            var userHourPointsByMonth = userHourPoints.ToLookup(x => x.Date.Date.Month);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(Guid.Parse(identityUser.Id));

            IList <HomeDashboardViewModel> userHourPointsFromSixMonths = new List <HomeDashboardViewModel>();

            while (userHourPointsFromSixMonths.Count < CHART_MONTHS_RANGE)
            {
                IEnumerable <HourPoints> hoursPointsOfMonth = userHourPointsByMonth[startDate.Month];

                userHourPointsFromSixMonths.Add(new HomeDashboardViewModel(new MonthExtract(startDate, hoursPointsOfMonth, hourPointConfigurations)));

                startDate = startDate.AddMonths(1);
            }

            return(Json(userHourPointsFromSixMonths));
        }
        public async Task <IActionResult> Create(HourPointConfigurationsModel hourPointConfigurationsModel)
        {
            try
            {
                TimeNotesUser identityUser = await _userManager.GetUserAsync(User);

                HourPointConfigurations hourPointConfigurations = new HourPointConfigurations(hourPointConfigurationsModel.WorkDays,
                                                                                              hourPointConfigurationsModel.BankOfHours,
                                                                                              hourPointConfigurationsModel.OfficeHour,
                                                                                              hourPointConfigurationsModel.LunchTime,
                                                                                              hourPointConfigurationsModel.StartWorkTime,
                                                                                              hourPointConfigurationsModel.ToleranceTime,
                                                                                              Guid.Parse(identityUser.Id),
                                                                                              hourPointConfigurationsModel.HourValue);

                _hourPointConfigurationsRepository.AddHourPointConfiguration(hourPointConfigurations);
                await _hourPointConfigurationsRepository.Commit();

                await EnsurePasscode(hourPointConfigurationsModel, identityUser);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <IActionResult> Index()
        {
            TimeNotesUser identityUser = await _userManager.GetUserAsync(User);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(Guid.Parse(identityUser?.Id));

            return(View(_mapper.Map <HourPointConfigurationsModel>(hourPointConfigurations)));
        }
Esempio n. 5
0
        public async Task RecalculeExtraTimeAndMissingTime(Guid hourPointsId, Guid userId)
        {
            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsById(hourPointsId);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            hourPoints.CalculateExtraTime(hourPointConfigurations);
            hourPoints.CalculateMissingTime(hourPointConfigurations);

            _hourPointsRepository.UpdateHourPoints(hourPoints);
            await _hourPointsRepository.Commit();
        }
Esempio n. 6
0
        public async Task UpdateTimeEntryDateHourPointed(Guid hourPointsId, Guid timeEntryId, Guid userId, DateTime newDateHourPointed)
        {
            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsById(hourPointsId);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            hourPoints.ChangeTimeEntryDateHourPointed(newDateHourPointed, timeEntryId, hourPointConfigurations);

            _hourPointsRepository.UpdateHourPoints(hourPoints);

            await _hourPointsRepository.Commit();
        }
Esempio n. 7
0
        public async Task AutoGenerateHourPointForTodayWithTimeEntries(Guid userId)
        {
            if (await _hourPointsRepository.ExistsHourPointsToDateAndUser(DateTime.Now, userId))
            {
                return;
            }

            HourPointConfigurations configurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            HourPoints hourPoints = HourPoints.CreateWithAutoGeneratedTimeEntries(userId, configurations);

            _hourPointsRepository.AddHourPoints(hourPoints);
            await _hourPointsRepository.Commit();
        }
        public async Task <IActionResult> Index()
        {
            TimeNotesUser identityUser = await _userManager.GetUserAsync(User);

            if (identityUser is null)
            {
                throw new ArgumentException($"Usuário não encontrado na base de dados.");
            }

            DateTime currentDate          = DateTime.Now.GetDateTimeInFirstDate();
            DateTime lastDaySearchedMonth = currentDate.GetDateTimeInLastDate();

            IEnumerable <HourPoints> userHourPoints = await _hourPointsRepository
                                                      .GetHourPointsWhere(x => (x.Date.Date >= currentDate.Date && x.Date.Date <= lastDaySearchedMonth.Date) && x.UserId.Equals(Guid.Parse(identityUser.Id)));

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(Guid.Parse(identityUser.Id));

            HomeDashboardViewModel homeDashboardViewModel = new HomeDashboardViewModel(new MonthExtract(currentDate, userHourPoints, hourPointConfigurations));

            return(View(homeDashboardViewModel));
        }
Esempio n. 9
0
        public async Task RemoveTimeEntryFromHourPoints(Guid userId, Guid timeEntryId)
        {
            TimeEntry timeEntry = await _hourPointsRepository.GetTimeEntryById(timeEntryId);

            HourPoints hourPoints = await _hourPointsRepository.GetHourPointsById(timeEntry.HourPointsId);

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(userId);

            hourPoints.RemoveTimeEntry(timeEntry, hourPointConfigurations);

            _hourPointsRepository.RemoveTimeEntry(timeEntry);

            if (!hourPoints.TimeEntries.Any())
            {
                _hourPointsRepository.RemoveHourPoints(hourPoints);
            }
            else
            {
                _hourPointsRepository.UpdateHourPoints(hourPoints);
            }

            await _hourPointsRepository.Commit();
        }
        public async Task <IActionResult> Edit(HourPointConfigurationsModel hourPointConfigurationsModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }

            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsById(hourPointConfigurationsModel.Id);

            hourPointConfigurations.ChangeWorkDays(hourPointConfigurationsModel.WorkDays);
            hourPointConfigurations.ChangeLunchTime(hourPointConfigurationsModel.LunchTime);
            hourPointConfigurations.ChangeOfficeHour(hourPointConfigurationsModel.OfficeHour);
            hourPointConfigurations.ChangeStartWorkTime(hourPointConfigurationsModel.StartWorkTime);
            hourPointConfigurations.ChangeToleranceTime(hourPointConfigurationsModel.ToleranceTime);
            hourPointConfigurations.ChangeBankOfHours(hourPointConfigurationsModel.BankOfHours);
            hourPointConfigurations.ChangeHourValue(hourPointConfigurationsModel.HourValue);

            TimeNotesUser identityUser = await _userManager.GetUserAsync(User);

            if (hourPointConfigurationsModel.UseAlexaSupport && !hourPointConfigurations.UseAlexaSupport)
            {
                hourPointConfigurations.ActiveAlexaSupport();
                await EnsurePasscode(hourPointConfigurationsModel, identityUser);
            }
            else
            {
                hourPointConfigurations.DisableAlexaSupport();
                identityUser.UnassingAlexaFromUser();
                await _userManager.UpdateAsync(identityUser);
            }

            _hourPointConfigurationsRepository.UpdateHourPointConfiguration(hourPointConfigurations);
            await _hourPointConfigurationsRepository.Commit();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 11
0
 public void UpdateHourPointConfiguration(HourPointConfigurations hourPointConfigurations)
 {
     _context.HourPointConfigurations.Update(hourPointConfigurations);
 }
Esempio n. 12
0
 public void AddHourPointConfiguration(HourPointConfigurations hourPointConfigurations)
 {
     _context.HourPointConfigurations.Add(hourPointConfigurations);
 }
        public async Task <IActionResult> Edit(Guid id)
        {
            HourPointConfigurations hourPointConfigurations = await _hourPointConfigurationsRepository.GetHourPointConfigurationsById(id);

            return(View(_mapper.Map <HourPointConfigurationsModel>(hourPointConfigurations)));
        }