private async Task SendReminders() { var thisWeek = WeekDTO.CreateWithWeekContaining(DateTime.Now); if (thisWeek.IsPPE.Value) { var beginDate = thisWeek.Previous().WeekStart; var endDate = thisWeek.WeekEnd; var entries = (await _timeApprovalService.GetByStatus(beginDate, endDate, TimeApprovalStatus.Unkown)).ToList(); var template = await System.IO.File.ReadAllTextAsync(@"wwwroot\email-submit-time-reminder.html"); foreach (var entry in entries.GroupBy(x => x.EmployeeId)) { try { var emp = await _employeeRepository.GetSingleEmployeeAsync(entry.Key); _logger.Information($"sending reminder to {emp.First} {emp.Last} [{emp.UserName}]"); _smtpProxy.SendMail(emp.UserName, template, $"Reminder to submit time for {beginDate.ToShortDateString()}-{endDate.ToShortDateString()}"); } catch (Exception e) { _logger.Error(e, "error trying to send reminder"); } } } }
public async Task <ActionResult> Edit(int weekid, string originUrl, int expenseItemId) { var jobs = await _jobsService.GetAsync(await _sessionAdapter.EmployeeIdAsync()); var expense = await _expenseService.GetExpenseById(expenseItemId); var vm = new EditExpenseViewModel() { AvailableJobs = jobs.ToList(), ExpenseToSave = new ExpenseModel() { AddtionalNotes = expense.AddtionalNotes, Amount = expense.Amount, AttachmentName = expense.AttatchmentName, Classification = expense.Classification, RelatedJob = expense.RelatedJob, SaveDate = expense.SaveDate }, Week = WeekDTO.CreateForWeekId(weekid), CancelUrl = originUrl, WeekId = weekid, SelectedJobId = expense.RelatedJob.JobId, ExpenseItemId = expense.ExpenseItemId }; return(View("Edit", vm)); }
WeekDTO GetPastMatchesByWeekId(long weekId, DateTime date) { match[] _matches = null; List <MatchDTO> matches = new List <MatchDTO>(); week _week = null; using (var context = new escorcenterdbEntities()) { _week = (from w in context.weeks where w.enabled == true && w.id == weekId select w).FirstOrDefault <week>(); _matches = (from m in context.matches where m.enabled == true && m.week == _week.id && m.date < date select m).OrderByDescending(m => m.date).ToArray <match>(); } matches = ParseMatches(_matches); if (matches == null || _week == null) { return(null); } WeekDTO week = new WeekDTO() { DateFrom = _week.dateFrom.ToString(), DateTo = _week.dateTo.ToString(), Description = _week.description, Id = _week.id, Season = _week.season, Title = _week.title }; week.matches.AddRange(matches); return(week); }
public TimeSpentViewModel EmptyViewModel(DayOfWeek dayOfWeek, WeekDTO week) { return(new TimeSpentViewModel() { Date = week.GetDateFor(dayOfWeek), Hours = 0 }); }
public static List <WeekDTO> getWeekList() { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { List <Week> WeekList = new List <Week>(); WeekList = GSDE.Weeks.ToList(); return(WeekDTO.ConvertListToDTO(WeekList)); } }
public static WeekDTO GetWeekDetailsByWeekId(int id) { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { Week Week = new Week(); Week = GSDE.Weeks.FirstOrDefault(x => x.Id == id); return(WeekDTO.ConvertToDTO(Week)); } }
private ExcelReport <PayPeriodReportCriteria> GetPayPeriodReportViewModel(bool isCurrentUserAdmin) { var vm2 = new PayPeriodReportCriteria(); vm2.PayPeriodEnd = WeekDTO.CreateWithWeekContaining(DateTime.Now).WeekEnd; vm2.PayPeriodList = PayPeriodRepository.GetPPRange(rangeSize: 25); var rpt = new ExcelReport <PayPeriodReportCriteria>(PayPeriodReportCriteria.PAY_PERIOD_REPORT_NAME, vm2, isCurrentUserAdmin); return(rpt); }
private ReportingPeriod GetDefaultPeriodSettings() { var wk = WeekDTO.CreateWithWeekContaining(DateTime.Now); var ps = new ReportingPeriod() { Start = wk.WeekStart, End = wk.WeekEnd }; return(ps); }
private static PayPeriodDTO MapForPPStartWeek(WeekDTO currentWeek) { var next = currentWeek.Next(); return(new PayPeriodDTO() { PayPeriodStart = currentWeek.WeekStart, PayPeriodEnd = next.WeekEnd, StartWeekId = currentWeek.WeekId.Value, EndWeekId = next.WeekId.Value, }); }
private static PayPeriodDTO MapForPPEndWeek(WeekDTO currentWeek) { var previous = currentWeek.Previous(); return(new PayPeriodDTO() { PayPeriodStart = previous.WeekStart, PayPeriodEnd = currentWeek.WeekEnd, StartWeekId = previous.WeekId.Value, EndWeekId = currentWeek.WeekId.Value }); }
public async Task <ActionResult> Current(int?employeeId) { var emp = await sessionAdapter.EmployeeIdAsync(); if (User.IsInRole(UserRoleName.Admin) && employeeId.HasValue) { emp = employeeId.Value; } var current = WeekDTO.CreateWithWeekContaining(DateTime.Now); return(RedirectToAction("Edit", new { weekId = current.WeekId.Value, employeeId = emp })); }
public IHttpActionResult CreateWeek(WeekDTO _week) { week w = new week { dateFrom = DateTime.Now, dateTo = new DateTime(2016, 02, 29), enabled = true, description = _week.Description, season = (int)_week.Season, title = _week.Title }; using (var context = new escorcenterdbEntities()) { context.weeks.Add(w); context.SaveChanges(); } return(Ok(w)); }
private async Task <string> CreateEmailBody(WeekDTO week, EmployeeDTO emp, string greetingName, string action, string actionBy, string followup) { var baseUrl = configuration.GetValue <string>("BaseHostAddress"); var template = await File.ReadAllTextAsync(@"wwwroot\email-template.html"); var finalEmailText = Regex.Replace(template, "(\\{\\{name}})", greetingName); finalEmailText = Regex.Replace(finalEmailText, "(\\{\\{action}})", action); finalEmailText = Regex.Replace(finalEmailText, "(\\{\\{action-by}})", actionBy); finalEmailText = Regex.Replace(finalEmailText, "(\\{\\{followup}})", followup); finalEmailText = Regex.Replace(finalEmailText, "(\\{\\{link}})", $"{baseUrl}/Edit/Employee/{emp.EmployeeId}/Week/{week.WeekId.Value}"); return(finalEmailText); }
public IHttpActionResult UpdateWeeks([FromBody] WeekDTO _week) { week weekMap = AutoMapper.Mapper.Map <WeekDTO, week>(_week); week w; using (var context = new escorcenterdbEntities()) { w = (from r in context.weeks where r.id == weekMap.id select r).FirstOrDefault(); w = weekMap; context.SaveChanges(); } return(Ok(w)); }
private TimeSpentViewModel MapToViewModel(WeekDTO week, DayOfWeek dayOfWeek, IEnumerable <TimeEntryBaseDTO> allEntriesThisWeek) { var thisDaysEntry = allEntriesThisWeek.SingleOrDefault(x => x.Date.DayOfWeek == dayOfWeek); var date = week.GetDateFor(dayOfWeek); return(new TimeSpentViewModel() { DayOfWeek = dayOfWeek, Date = date, Hours = thisDaysEntry?.Hours ?? 0, OvertimeHours = thisDaysEntry?.OvertimeHours ?? 0, }); }
private async Task <NewJobTaskCombo> GenerateEmptyJobTaskAsync(int weekId, int employeeId) { var jobList = (await jobService.GetAsync(employeeId)).ToList(); var taskList = (await taskService.GetTasks()).Where(x => x.UsageStatus.Enum == JobTasks.UsageStatus.Enabled).ToList().OrderBy(x => x.LegacyCode).ThenBy(x => x.Name); var week = WeekDTO.CreateForWeekId(weekId); return(new NewJobTaskCombo() { SelectedJobId = null, SelectedTaskId = null, AvailableJobs = jobList, AvailableTasks = taskList, }); }
public async Task CopyPreviousWeekTime(int employeeId, int id) { var prev = WeekDTO.CreateForWeekId(id).Previous(); var timeEntries = await _timeService.GetAsync(prev.WeekId.Value, employeeId); foreach (var entry in timeEntries.GroupBy(x => new { x.JobId, x.JobTaskId })) { var entryForEveryDayOfWeek = _timeSpentRepository.CreateEmptyWeekForCombo(id, entry.Key.JobTaskId, entry.Key.JobId, employeeId);; foreach (var day in entryForEveryDayOfWeek) { await _timeService.SaveAsync(employeeId, day); } } }
public static PayPeriodDTO GetPPFor(DateTime date) { var currentPP = new PayPeriodDTO(); var currentWeek = WeekDTO.CreateWithWeekContaining(date); if (currentWeek.IsPPE.Value) { return(MapForPPEndWeek(currentWeek)); } else { return(MapForPPStartWeek(currentWeek)); } }
public void PayPeriodsWork() { var start = WeekDTO.CreateWithWeekContaining(new DateTime(2021, 4, 20)); Assert.IsTrue(start.IsPPE.Value); var next = start.Next(); Assert.IsFalse(next.IsPPE.Value); var next2 = next.Next(); Assert.IsTrue(next2.IsPPE.Value); }
public async Task <ActionResult> Index(int weekid, string originUrl) { var jobs = await _jobsService.GetAsync(await _sessionAdapter.EmployeeIdAsync()); var vm = new AddExpenseViewModel() { AvailableJobs = jobs.ToList(), ExpenseToSave = new ExpenseModel(), Week = WeekDTO.CreateForWeekId(weekid), CancelUrl = originUrl, WeekId = weekid, }; return(View("New", vm)); }
private WeekOfTimeDTO ToDTO(int employeeId, int weekId, FullTimeEntryViewModel vm) { var w = WeekDTO.CreateForWeekId(weekId); return(new WeekOfTimeDTO() { WeekId = weekId, Monday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Monday), vm.TimeEntryRow, x => x.Monday), Tuesday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Tuesday), vm.TimeEntryRow, x => x.Tuesday), Wednesday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Wednesday), vm.TimeEntryRow, x => x.Wednesday), Thursday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Thursday), vm.TimeEntryRow, x => x.Thursday), Friday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Friday), vm.TimeEntryRow, x => x.Friday), Saturday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Saturday), vm.TimeEntryRow, x => x.Saturday), Sunday = ToDaysEntries(employeeId, weekId, w.GetDateFor(DayOfWeek.Sunday), vm.TimeEntryRow, x => x.Sunday) }); }
public IEnumerable <TimeEntryDTO> CreateEmptyWeekForCombo(int weekId, int JobTaskId, int JobId, int employeeId) { var week = WeekDTO.CreateForWeekId(weekId); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Monday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Tuesday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Wednesday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Thursday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Friday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Saturday)); yield return(CreateDTO(week, JobTaskId, JobId, employeeId, DayOfWeek.Sunday)); }
public void InternallyConsistandWeekCycles() { var start = new WeekDTO(new DateTime(WeekDTO.WeekEpoch.Year, WeekDTO.WeekEpoch.Month, WeekDTO.WeekEpoch.Day)); Assert.AreEqual(0, start.WeekId.Value); var next = start.Next(); Assert.AreEqual(1, next.WeekId.Value); var next2 = next.Next(); Assert.AreEqual(2, next2.WeekId.Value); var stillNext2 = WeekDTO.CreateWithWeekContaining(next2.WeekEnd.AddDays(-2)); Assert.AreEqual(next2, stillNext2); }
public void UpdateWeek_NewWeekValidDTO_Success() { var wc = initializeTest(); var mockUser = _testContext.MockUsers[ADMIN_DEP_ONE]; _testContext.MockUserManager.MockLoginAsUser(mockUser); var week = _testContext.MockUsers[ADMIN_DEP_ONE].WeekSchedule.First(); // modify name var newWeek = new WeekDTO(week) { Name = "new name" }; var res = wc.UpdateWeek(mockUser.Id, 2018, 20, newWeek).Result; Assert.Equal(ErrorCode.NoError, res.ErrorCode); Assert.True(res.Success); Assert.Equal("new name", res.Data.Name); }
public IHttpActionResult GetPastMatchesByLeagueId(long leagueId) { DateTime now = DateTime.Now; long seasonId = GetCurrentSeasonId(leagueId, now); if (seasonId < 0) { return(Ok()); } season _season = null; List <WeekDTO> weeks = new List <WeekDTO>(); using (var context = new escorcenterdbEntities()) { week[] _weeks = (from w in context.weeks where w.enabled == true && w.season == seasonId && w.dateFrom <= now select w).OrderByDescending(w => w.dateFrom).ToArray <week>(); foreach (week _week in _weeks) { WeekDTO week = GetPastMatchesByWeekId(_week.id, now); if (week != null) { weeks.Add(week); } } _season = (from s in context.seasons where s.id == seasonId select s).FirstOrDefault <season>(); } if (_season == null) { return(Ok()); } SeasonDTO season = new SeasonDTO { Title = _season.title, DateFrom = _season.dateFrom.ToString(), DateTo = _season.dateTo.ToString(), Description = _season.description, Id = _season.id, League = _season.league }; season.Weeks.AddRange(weeks); return(Ok(season)); }
protected override async Task <IProcessResult <MiscExpenditure> > Handle(UpdateMiscExpenditureMessage msg) { var existing = await _repo.FindByExternalId(msg.ExternalExpenditureId); if (existing == null || msg.ExternalExpenditureId == default(Guid)) { existing = new DataAccess.EF.MiscExpenditure(); existing.ExternalId = Guid.NewGuid(); existing.Id = 0; existing.LastModified = DateTimeOffset.Now; existing.WeekId = WeekDTO.CreateWithWeekContaining(msg.Model.ExpensedOn).WeekId.Value; } var updateMsg = UpdateMessage.CreateFrom(msg, existing); var mapped = _mapper.Map <DataAccess.EF.MiscExpenditure>(updateMsg); var saved = await _repo.SaveEntity(mapped); return(Success(_mapper.Map <MiscExpenditure>(saved))); }
public static bool EditWeek(WeekDTO WeekDTO) { using (Gymnastics_Studio_DataEntities context = new Gymnastics_Studio_DataEntities()) { var week = context.Weeks.FirstOrDefault(x => x.Id == WeekDTO.Id); if (week != null) { week.Note = WeekDTO.Note?.TrimStart().TrimEnd(); week.Date = Convert.ToDateTime(WeekDTO.Date); week.WeeklyPortion = WeekDTO.WeeklyPortion?.TrimStart().TrimEnd(); context.SaveChanges(); return(true); } else { return(false); } } }
public static int AddWeek(WeekDTO WeekDTO) { try { using (Gymnastics_Studio_DataEntities context = new Gymnastics_Studio_DataEntities()) { Week Week = new Week(); Week.Note = WeekDTO.Note?.TrimStart().TrimEnd(); Week.Date = Convert.ToDateTime(WeekDTO.Date); Week.WeeklyPortion = WeekDTO.WeeklyPortion?.TrimStart().TrimEnd(); context.Weeks.Add(Week); context.SaveChanges(); return(context.Weeks.Max(o => o.Id)); } } catch (Exception e) { throw e; } }
private async Task <DataAccess.EF.ScheduleTask> CreateReminderTask(string taskName, bool isPpeOnly) { var thisWeek = WeekDTO.CreateWithWeekContaining(DateTime.Now); if (isPpeOnly) { if (!thisWeek.IsPPE.Value) { thisWeek = thisWeek.Previous(); } } _logger.Information($"Creating new Reminder Task [{taskName}]"); return(await _scheduleTaskRepo.CreateNewScheduledTask(new BLL.ScheduledTasks.NewScheduledTask() { EndDate = null, OnFriday = true, RecurEveryNWeeks = isPpeOnly ? 2 : 1, StartDate = thisWeek.WeekStart, TaskName = taskName })); }
private TimeEntryDTO CreateDTO(WeekDTO week, int SelectedTaskId, int SelectedJobId, int employeeId, DayOfWeek dayOfWeek) { var candidate = week.WeekStart; while (candidate.DayOfWeek != dayOfWeek) { candidate = candidate.AddDays(1); } var dto = new TimeEntryDTO() { Date = candidate, EmployeeId = employeeId, Hours = 0, OvertimeHours = 0, JobId = SelectedJobId, JobTaskId = SelectedTaskId, TimeEntryId = 0, WeekId = week.WeekId.Value }; return(dto); }