示例#1
0
        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", "");
        }
示例#2
0
 public EditModel(TimeLogContext context)
 {
     _context = context;
 }
示例#3
0
 public CreateModel(TimeLogContext context)
 {
     _context = context;
 }
示例#4
0
 public IndexModel(TimeLogContext context)
 {
     _context = context;
 }
示例#5
0
 public ReportModel(TimeLogContext context)
 {
     _context = context;
 }
示例#6
0
 public DeleteModel(TimeLogContext context)
 {
     _context = context;
 }
示例#7
0
 public DetailsModel(TimeLogContext context)
 {
     _context = context;
 }
示例#8
0
 protected void PopulateContactDropDownList(TimeLogContext context, object selectedContact = null)
 {
     ContactSelectList = new SelectList(context.Contacts.OrderBy(x => x.DisplayName), "Id", "Name", selectedContact);
 }
示例#9
0
 protected void PopulateClientDropDownList(TimeLogContext context, object selectedClient = null)
 {
     ClientSelectList = new SelectList(context.Clients.OrderByDescending(x => x.IsDefault).ThenBy(x => x.Name), "Id", "Name", selectedClient);
 }
示例#10
0
 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);
 }
示例#11
0
 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);
 }
示例#12
0
 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);
 }