private void AddIssueToTimesheets(Issue issue) { //Created Timesheet Row based on Assigned and Favorites Issues var timesheetRow = new TimesheetRow { Timesheet = mTimesheet, IssueId = issue.Id, Issue = issue, TimesheetValues = new List<TimesheetValue>() }; //Add hours for next 7 days for (int i = 0; i < 7; i++) { TimesheetValue timesheetValue = new TimesheetValue { Date = mTimesheet.StartDate.AddDays(i), TimesheetRow = timesheetRow, Hours = 0 }; timesheetRow.TimesheetValues.Add(timesheetValue); } var timesheetRowModel = new IssueTimesheetRowModel(mView, timesheetRow, QuickIssues, mAdminCodes); mIssueTimesheetRowModels.Add(timesheetRowModel); mTimesheet.TimesheetRows.Add(timesheetRow); }
/// <summary> /// This will add Assigned and Favorited Issues and all codes under Timesheet Admin /// </summary> private void PopulateDefaultTimesheetRows() { mIssueTimesheetRowModels.Clear(); var getDefaultIssuesForTimesheet = DatabaseLoader.GetDefaultIssuesForTimesheet(mTimesheet.UserId); var getPreviousTimesheetReferences = DatabaseLoader.GetPreviousTimesheetReferences(mTimesheet.UserId, mTimesheet.StartDate); List<Task> tasks = new List<Task>(); tasks.Add(getDefaultIssuesForTimesheet); tasks.Add(getPreviousTimesheetReferences); Task.Factory.ContinueWhenAll(tasks.ToArray(), x => { //Add Admin Codes timesheets foreach (var adminCode in mAdminCodes) { //Created Timesheet Row based on Assigned and Favorites Issues var timesheetRow = new TimesheetRow { Timesheet = mTimesheet, TimesheetCodeId = adminCode.Id, TimesheetValues = new List<TimesheetValue>() }; //Add hours for next 7 days for (int i = 0; i < 7; i++) { TimesheetValue timesheetValue = new TimesheetValue { Date = mTimesheet.StartDate.AddDays(i), TimesheetRow = timesheetRow, Hours = 0 }; timesheetRow.TimesheetValues.Add(timesheetValue); } var timesheetRowModel = new IssueTimesheetRowModel(mView, timesheetRow, QuickIssues, mAdminCodes); mIssueTimesheetRowModels.Add(timesheetRowModel); mTimesheet.TimesheetRows.Add(timesheetRow); } foreach (var issue in getDefaultIssuesForTimesheet.Result) { AddIssueToTimesheets(issue); } //Set previous Reference Numbers if (getPreviousTimesheetReferences.Result.Any()) { foreach (var previousIsseuReference in getPreviousTimesheetReferences.Result) { var issueId = previousIsseuReference.Key; var referenceNumber = previousIsseuReference.Value; var timesheetRow = mTimesheet.TimesheetRows.FirstOrDefault(t => t.IssueId == issueId); if (timesheetRow != null) { timesheetRow.SystemReferenceNumber = referenceNumber; } } } CMS.UiFactory.StartNew(() => { mView.TelerikGrid.Rebind(); RaisePropertyChanged("IssueTimesheetRowModels"); RaisePropertyChanged("TotalHours"); RaisePropertyChanged("Week"); RaisePropertyChanged("User"); RaisePropertyChanged("LastModifiedBy"); OkButtonCommand.RaiseCanExecuteChanged(); SubmitButtonCommand.RaiseCanExecuteChanged(); AddIssueButtonCommand.RaiseCanExecuteChanged(); mView.IsBusyIndicator.IsBusy = false; }); }); }
public TimesheetViewModel(TimesheetDialog view, int timesheetId) { mView = view; //need this to update aggregates on RadGridView!!! var getPropertyListNames = DatabaseLoader.GetTimesheetCodes(); var getTimesheet = DatabaseLoader.GetTimesheet(timesheetId); var getQuickIssuesTask = DatabaseLoader.GetQuickIssues(new IssueFilterObject()); List<Task> tasks = new List<Task>(); tasks.Add(getPropertyListNames); tasks.Add(getTimesheet); tasks.Add(getQuickIssuesTask); Task.Factory.ContinueWhenAll(tasks.ToArray(), x => { mAdminCodes = getPropertyListNames.Result; mTimesheet = getTimesheet.Result; QuickIssues = getQuickIssuesTask.Result; if (!mTimesheet.TimesheetRows.Any()) { PopulateDefaultTimesheetRows(); } else { mIssueTimesheetRowModels.Clear(); foreach (var timesheetRow in mTimesheet.TimesheetRows) { var timesheetRowModel = new IssueTimesheetRowModel(mView, timesheetRow, QuickIssues, mAdminCodes); mIssueTimesheetRowModels.Add(timesheetRowModel); } CMS.UiFactory.StartNew(() => { mView.TelerikGrid.Rebind(); RaisePropertyChanged("IssueTimesheetRowModels"); RaisePropertyChanged("TotalHours"); RaisePropertyChanged("TotalMonday"); RaisePropertyChanged("TotalTuesday"); RaisePropertyChanged("TotalWednesday"); RaisePropertyChanged("TotalThursday"); RaisePropertyChanged("TotalFriday"); RaisePropertyChanged("TotalSaturday"); RaisePropertyChanged("TotalSunday"); RaisePropertyChanged("Week"); RaisePropertyChanged("User"); RaisePropertyChanged("LastModifiedBy"); OkButtonCommand.RaiseCanExecuteChanged(); SubmitButtonCommand.RaiseCanExecuteChanged(); AddIssueButtonCommand.RaiseCanExecuteChanged(); mView.IsBusyIndicator.IsBusy = false; }); } }); OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanExecuteOkButtonHandler); CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, CanExecuteCancelButtonHandler); SubmitButtonCommand = new DelegateCommand<object>(SubmitButtonHander, CanExecuteSubmitButtonHandler); AddIssueButtonCommand = new DelegateCommand<object>(AddIssueButtonHandler, CanExecuteOkButtonHandler); RemoveIssueButtonCommand = new DelegateCommand<object>(RemoveIssueButtonHandler, CanExecuteOkButtonHandler); }