public bool CanExecute(IForecastRegistrationViewModel vm) { vm.SaveDisabledText = string.Empty; if (vm.SelectedUserHandler.SelectedUser == null) { vm.SaveDisabledText = "Please select a workplan owner"; return(false); } if (vm.ForecastMonthIsLocked) { vm.SaveDisabledText = "This workplan is locked. Please contact an admin, if you wish to update it"; return(false); } if (!vm.IsDirty) { return(false); } if (!vm.IsValid()) { vm.SaveDisabledText = "Input is required"; return(false); } return(true); }
public async void Execute(IForecastRegistrationViewModel vm) { if (!vm.IsValid()) { return; } vm.IsBusy = true; var forecastMonthDto = new ForecastMonthDto { Id = vm.ForecastMonthId, Month = vm.SelectedDate.Month, Year = vm.SelectedDate.Year, UserId = _selectedUserHandler.UserId, CreatedById = _userSession.CurrentUser.Id, ForecastDtos = vm.DateColumns .GetItemsToSave(vm.ProjectForecastTypeId) .Select(col => new ForecastDto { Date = col.Date, DedicatedForecastTypeHours = col.SelectedForecastTypeDedicatedHours, ForecastType = col.ForecastType.ToServerDto(), ForecastProjectHoursDtos = col.ProjectHoursWithValue.Select(BuildForecastProjectHoursDto).ToList() }).ToList() }; var saveResponse = await _forecastService.SaveForecasts(forecastMonthDto); // Null if an error occured if (saveResponse != null) { vm.ForecastMonthId = saveResponse.ForecastMonthId; } vm.IsBusy = false; vm.InitializeDirtyCheck(); vm.RaiseCanExecuteActions(); ApplicationCommands.GetForecastStatistics.Execute(vm.SelectedDate); }