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> RegisterAlexa(string alexaUserId, string passcode) { if (string.IsNullOrWhiteSpace(alexaUserId) || string.IsNullOrWhiteSpace(passcode)) { return(BadRequest("As informações enviadas não podem ser vazia, verifique o código e tente novamente.")); } string userId = await _cache.GetAsync <string>(passcode); if (string.IsNullOrWhiteSpace(userId)) { return(BadRequest("Código informado inválido ou expirado, tente novamente ou solicite um novo código.")); } TimeNotesUser user = await _userManager.FindByIdAsync(userId); _logger.LogInformation("Usuário para cadastrar alexa encontrado."); user.AssignedAlexaToUser(alexaUserId); IdentityResult updateResult = await _userManager.UpdateAsync(user); await _cache.RemoveAsync(passcode); if (updateResult.Succeeded) { return(Ok("Alexa registrada com sucesso.")); } return(BadRequest("Ocorreram problemas ao tentar vincular sua alexa ao time notes, fale com os administradores do site.")); }
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))); }
public async Task <IActionResult> RecalculateTimes(Guid hourPointsId) { TimeNotesUser identityUser = await _userManager.GetUserAsync(User); await _hourPointsServices.RecalculeExtraTimeAndMissingTime(hourPointsId, Guid.Parse(identityUser.Id)); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> ExportUserHourPointsToExcel(DateTime searchDate) { TimeNotesUser identityUser = await _userManager.GetUserAsync(User); IEnumerable <HourPointsModel> userHourPointsModel = await GetHourPointsFromUserInSearchedDate(searchDate, identityUser); byte[] fileBytes = _excelExport.ExportExcel(userHourPointsModel); return(File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{searchDate.ToString("MMMM")}_{searchDate.Year}.xlsx")); }
public async Task <IActionResult> ExistsUserRegisteredWithAlexaId(string alexaUserId) { if (string.IsNullOrWhiteSpace(alexaUserId)) { return(BadRequest("As informações enviadas não podem ser vazia, entre em contato com a administração do time notes.")); } TimeNotesUser user = await FindUserByAlexaUserId(alexaUserId); return(Ok(user != null)); }
public async Task <IActionResult> Delete(TimeEntryModel timeEntryModel) { try { TimeNotesUser identityUser = await _userManager.GetUserAsync(User); await _hourPointsServices.RemoveTimeEntryFromHourPoints(Guid.Parse(identityUser.Id), timeEntryModel.Id); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View(timeEntryModel)); } }
public async Task <IActionResult> Edit(TimeEntryModel timeEntryModel) { try { TimeNotesUser identityUser = await _userManager.GetUserAsync(User); await _hourPointsServices.UpdateTimeEntryDateHourPointed(timeEntryModel.HourPointsId, timeEntryModel.Id, Guid.Parse(identityUser.Id), timeEntryModel.DateHourPointed); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> RegisterPointAt(string alexaUserId, string time) { DateTime point = DateTime.Today + TimeSpan.Parse(time); TimeNotesUser user = await FindUserByAlexaUserId(alexaUserId); if (user is null) { return(BadRequest("Parece que você não registrou sua alexa no time notes. Para cadastrá-la, basta ir no site na aba de configurações e habilitar a opção Use Alexa Support e depois falar comigo novamente me passando o código que você recebeu.")); } await _hourPointsServices.AddTimeEntryToHourPoints(Guid.Parse(user.Id), new TimeEntry(point)); return(Ok($"Apontamento realizado às {point.Hour}:{point.Minute}")); }
public async Task <IActionResult> Create(TimeEntryModel timeEntryModel) { if (ModelState.IsValid) { TimeNotesUser identityUser = await _userManager.GetUserAsync(User); if (identityUser is null) { throw new ArgumentException($"Usuário não encontrado na base de dados."); } await _hourPointsServices.AddTimeEntryToHourPoints(Guid.Parse(identityUser.Id), _mapper.Map <TimeEntry>(timeEntryModel)); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> AutoGenerateTimeEntriesToday() { TimeNotesUser identityUser = await _userManager.GetUserAsync(User); var config = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(Guid.Parse(identityUser.Id)); if (config.StartWorkTime <= TimeSpan.Zero || config.ToleranceTime <= TimeSpan.Zero) { return(RedirectToAction("Edit", "HourPointConfigurations", config)); } if (identityUser is null) { throw new ArgumentException($"Usuário não encontrado na base de dados."); } await _hourPointsServices.AutoGenerateHourPointForTodayWithTimeEntries(Guid.Parse(identityUser.Id)); return(RedirectToAction(nameof(Index))); }
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)); }
public async Task <IActionResult> Index(DateTime?searchDate = null) { if (!searchDate.HasValue) { searchDate = DateTime.Now.GetDateTimeInFirstDate(); } ViewData["CurrentSearchDate"] = searchDate.Value.ToString("yyyy-MM"); TimeNotesUser identityUser = await _userManager.GetUserAsync(User); var config = await _hourPointConfigurationsRepository.GetHourPointConfigurationsByUserId(Guid.Parse(identityUser.Id)); if (config is null) { return(RedirectToAction("Create", "HourPointConfigurations")); } IEnumerable <HourPointsModel> userHourPointsModel = await GetHourPointsFromUserInSearchedDate(searchDate, identityUser); return(View(nameof(Index), userHourPointsModel.OrderBy(h => h.Date))); }
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))); }
private async Task EnsurePasscode(HourPointConfigurationsModel hourPointConfigurationsModel, TimeNotesUser identityUser) { if (hourPointConfigurationsModel.UseAlexaSupport && string.IsNullOrWhiteSpace(identityUser.AlexaUserId)) { string passcode = await GetPasscode(); await _cache.SetAsync(passcode, identityUser.Id); TempData["passcode"] = passcode; } }