Example #1
0
        private void prepWork(ViewModels.WorkViewModel vm)
        {
            var cycles = GetPayCycles();
            int cycle  = int.Parse(cycles.First().Value);

            vm.Jobs = _WorkRepo.GetJobs("- Select -").Select(x => new SelectListItem {
                Text = x.Descr, Value = x.Id.ToString()
            });
            vm.WorkTypes = _LookupRepo.GetLookups("WorkType", "- Select -").Select(x => new SelectListItem {
                Text = x.Descr, Value = x.Id.ToString()
            });
            vm.PayCycles = cycles;
            if (vm.SelectedCycle == 0)
            {
                vm.SelectedCycle = cycle;
            }
            vm.WorkEntries = _WorkRepo.GetWork(vm.Contractor.Id, vm.SelectedCycle, true);
            if (vm.EditWork == null)
            {
                vm.EditWork = new Domain.Work {
                    ContractorId = vm.Contractor.Id, WorkDay = DateRef.GetWorkDay(DateTime.Today)
                };
            }
            vm.EditDays = GetEditDays(vm.SelectedCycle);
        }
Example #2
0
        private void prepWork(Models.WorkViewModel vm, bool clearEdit = false)
        {
            var cycles = GetPayCycles();
            int cycle  = int.Parse(cycles.First().Value);

            vm.WorkTypes = LookupRepo.GetLookups("WorkType", "- Select -").Select(x => new SelectListItem {
                Text = x.Descr, Value = x.Id.ToString()
            });
            vm.PayCycles     = cycles;
            vm.IsCycleOpen   = false;
            vm.CanCloseCycle = true;
            if (vm.SelectedCycle == 0)
            {
                vm.SelectedCycle = cycle;
            }
            if (vm.SelectedCycle == cycle)
            {
                vm.IsCycleOpen   = true;
                vm.CanCloseCycle = false;
            }

            vm.Jobs = _JobRepo.GetJobsForWork(vm.SelectedContractorId, vm.SelectedCycle).Select(x => new SelectListItem {
                Text = x.Descr, Value = x.Id.ToString()
            });

            vm.WorkEntries = _WorkRepo.GetWork(vm.SelectedContractorId, vm.SelectedCycle, true);
            if (vm.SortByJob)
            {
                vm.WorkEntries = vm.WorkEntries.OrderBy(x => x.Job).ThenBy(x => x.WorkDay);
            }
            if (vm.EditWork == null)
            {
                vm.EditWork = new TimeCard.Domain.Work {
                    ContractorId = vm.SelectedContractorId, WorkDay = DateRef.GetWorkDay(DateTime.Today)
                };
            }
            if (clearEdit)
            {
                vm.EditWork = new TimeCard.Domain.Work {
                    ContractorId = vm.SelectedContractorId, WorkDay = vm.EditWork.WorkDay, JobId = vm.EditWork.JobId, WorkType = vm.EditWork.WorkType
                };
            }
            vm.EditDays    = GetEditDays(vm.SelectedCycle);
            vm.DailyTotals = new decimal[2][];
            for (int i = 0; i < 2; i++)
            {
                vm.DailyTotals[i] = new decimal[8];
                for (int j = 0; j < 7; j++)
                {
                    vm.DailyTotals[i][j]  = vm.WorkEntries.Where(x => x.WeekDay == j + i * 7).Sum(x => x.Hours);
                    vm.DailyTotals[i][7] += vm.DailyTotals[i][j];
                }
            }

            if (!vm.IsCycleOpen)
            {
                vm.IsCycleOpen = _WorkRepo.GetWorkOpen(vm.SelectedContractorId).Any(x => x == vm.SelectedCycle);
            }
        }