private void PopulateTimeFrameDropDownList(TimeLogContext context, string selected) { //create a list of 1 week start/end times with a label such as this week, 1 week ago, 2 weeks ago, etc DateTimeOffset reportStartTime = DateTimeOffset.UtcNow.ToLocalTime(); DateTimeOffset reportEndTime; reportStartTime = reportStartTime.AddMilliseconds(-reportStartTime.Millisecond) .AddSeconds(-reportStartTime.Second) .AddMinutes(-reportStartTime.Minute) .AddHours(-reportStartTime.Hour); //get current day of week var dayOfWeek = reportStartTime.DayOfWeek; //if Sunday subtract 6 to get the previous Monday, otherwise subtract the day of week index plus one var daysToSubtract = (dayOfWeek) == DayOfWeek.Sunday ? -6 : -(int)dayOfWeek + 1; reportStartTime = reportStartTime.AddDays(daysToSubtract); reportEndTime = reportStartTime.AddDays(6).AddHours(23).AddMinutes(59).AddSeconds(59).AddMilliseconds(999); List <MyDropDownItem> listOfReportDates = new List <MyDropDownItem>(); var firstItem = new MyDropDownItem() { Name = $"{reportStartTime:yyyy/MM/dd} - {reportEndTime:yyyy/MM/dd}", Value = $"{reportStartTime:yyyy/MM/dd} - {reportEndTime:yyyy/MM/dd}" }; if (firstItem.Name == selected) { firstItem.Selected = true; } listOfReportDates.Add(firstItem); for (int i = 0; i < 52; i++) { reportStartTime = reportStartTime.AddDays(-7); reportEndTime = reportEndTime.AddDays(-7); var item = new MyDropDownItem() { Name = $"{reportStartTime:yyyy/MM/dd} - {reportEndTime:yyyy/MM/dd}", Value = $"{reportStartTime:yyyy/MM/dd} - {reportEndTime:yyyy/MM/dd}" }; if (item.Name == selected) { item.Selected = true; } listOfReportDates.Add(item); } TimeFramesSelectList = new SelectList(listOfReportDates, "Name", "Value", ""); }
public EditModel(TimeLogContext context) { _context = context; }
public CreateModel(TimeLogContext context) { _context = context; }
public IndexModel(TimeLogContext context) { _context = context; }
public ReportModel(TimeLogContext context) { _context = context; }
public DeleteModel(TimeLogContext context) { _context = context; }
public DetailsModel(TimeLogContext context) { _context = context; }
protected void PopulateContactDropDownList(TimeLogContext context, object selectedContact = null) { ContactSelectList = new SelectList(context.Contacts.OrderBy(x => x.DisplayName), "Id", "Name", selectedContact); }
protected void PopulateClientDropDownList(TimeLogContext context, object selectedClient = null) { ClientSelectList = new SelectList(context.Clients.OrderByDescending(x => x.IsDefault).ThenBy(x => x.Name), "Id", "Name", selectedClient); }
protected void PopulateLocationDropDownList(TimeLogContext context, object selectedLocation = null) { LocationSelectList = new SelectList(context.Locations.AsNoTracking().OrderByDescending(x => x.IsDefault).ThenBy(x => x.Name), "Id", "Name", selectedLocation); }
protected void PopulateActivityTypesDropDownList(TimeLogContext context, object selectedActivityType = null) { ActivityTypesSelectList = new SelectList(context.ActivityTypes.AsNoTracking().OrderByDescending(x => x.IsDefault).ThenBy(x => x.Name), "Id", "Name", selectedActivityType); }
protected void PopulateProjectsDropDownList(TimeLogContext context, object selectedProject = null) { ProjectsSelectList = new SelectList(context.Projects.AsNoTracking().OrderByDescending(x => x.IsDefault).ThenBy(x => x.Name), "Id", "Name", selectedProject); }