private void InitializeCommands() { ActionCommand = ReactiveCommand.Create(); ActionCommand.Subscribe(x => ActionCommandExecuted(x)); LoadAnalyticCommand = ReactiveCommand.CreateAsyncTask(async _ => await Task.Run(() => { var id = new DTO.Analytic(SelectedEntity.Id); var a = ((APLPX.UI.WPF.Data.MockAnalyticService)_analyticService).LoadAnalytic(new DTO.Session <DTO.Analytic>() { Data = id }); SelectedAnalytic = a.Data.ToDisplayEntity(); })); SaveAnalyticIdentityCommand = ReactiveCommand.CreateAsyncTask(async _ => await Task.Run(() => { var session = new DTO.Session <DTO.Analytic>() { Data = SelectedAnalytic.ToDto() }; var status = _analyticService.SaveIdentity(session); })); SaveFiltersCommand = ReactiveCommand.CreateAsyncTask(async _ => await Task.Run(() => { var session = new DTO.Session <DTO.Analytic>() { Data = SelectedAnalytic.ToDto() }; var status = _analyticService.SaveFilters(session); })); SavePriceListsCommand = ReactiveCommand.CreateAsyncTask(async _ => await Task.Run(() => { var session = new DTO.Session <DTO.Analytic>() { Data = SelectedAnalytic.ToDto() }; var status = _analyticService.SavePriceLists(session); })); SaveValueDriversCommand = ReactiveCommand.CreateAsyncTask(async _ => await Task.Run(() => { var session = new DTO.Session <DTO.Analytic>() { Data = SelectedAnalytic.ToDto() }; var status = _analyticService.SaveDrivers(session); })); }
//TODO: flesh out implementation. This is a starting point only. private void HandleSelectedAction(DisplayEntities.Action action) { switch (action.TypeId) { //Create a new current entity. case DTO.ModuleFeatureStepActionType.PlanningAnalyticsSearchAnalyticsNew: //Create a new (blank) entity. TODO: refactor. var newAnalytic = new DisplayEntities.Analytic(); newAnalytic.Identity.Name = "Analytic name (new)"; newAnalytic.Identity.Description = "Description (new)"; newAnalytic.IsDirty = true; SelectedAnalytic = newAnalytic; SelectedFeature.SelectedStep = SelectedFeature.DefaultActionStep; SelectedFeature.DisableRemainingSteps(); break; case DTO.ModuleFeatureStepActionType.PlanningEverydayPricingSearchEverydayNew: case DTO.ModuleFeatureStepActionType.PlanningPromotionPricingSearchPromotionsNew: case DTO.ModuleFeatureStepActionType.PlanningKitPricingSearchKitsNew: //Create a new (blank) entity. TODO: refactor. var newPriceRoutine = new DisplayEntities.Pricing(); newPriceRoutine.Identity.Name = "Analytic name (new)"; newPriceRoutine.Identity.Description = "Description (new)"; newPriceRoutine.IsDirty = true; SelectedPriceRoutine = newPriceRoutine; SelectedFeature.SelectedStep = SelectedFeature.DefaultActionStep; SelectedFeature.DisableRemainingSteps(); break; case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningAnalyticsSearchAnalyticsEdit: SelectedFeature.SelectedStep = SelectedFeature.DefaultActionStep; ExecuteAsyncCommand(LoadAnalyticCommand, x => SelectedFeatureViewModel = GetViewModel(SelectedStep), "Retrieving analytic...", "Analytic was successfully retrieved."); break; case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningEverydayPricingSearchEverydayEdit: case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningPromotionPricingSearchPromotionsEdit: case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningKitPricingSearchKitsEdit: //TODO: get the full entity from the server and load edit screen. //This is a simulation only. SelectedPriceRoutine = SelectedEntity as DisplayEntities.Pricing; SelectedFeature.SelectedStep = SelectedFeature.DefaultActionStep; break; //Copy current entity. case DTO.ModuleFeatureStepActionType.PlanningAnalyticsSearchAnalyticsCopy: //Create a copy of the existing entity and load edit screen. SelectedAnalytic = SelectedAnalytic.Copy(); SelectedFeature.SelectedStep = SelectedFeature.DefaultActionStep; SelectedFeature.DisableRemainingSteps(); break; case DTO.ModuleFeatureStepActionType.PlanningPromotionPricingSearchPromotionsCopy: case DTO.ModuleFeatureStepActionType.PlanningEverydayPricingSearchEverydayCopy: case DTO.ModuleFeatureStepActionType.PlanningKitPricingSearchKitsCopy: //Create a copy of the existing entity and load edit screen. SelectedPriceRoutine = SelectedPriceRoutine.Copy(); SelectedFeature.SelectedStep = SelectedFeature.DefaultActionStep; SelectedFeature.DisableRemainingSteps(); break; //Save the current entity. case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningAnalyticsIdentitySave: //TODO: call analytic save method on service. ExecuteAsyncCommand(SaveAnalyticIdentityCommand, x => SelectedFeatureViewModel = GetViewModel(SelectedStep), "Identity saving...", "Identity saved."); SelectedAnalytic.IsDirty = false; SelectedFeature.EnableRemainingSteps(); break; case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningEverydayPricingIdentitySave: case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningPromotionPricingIdentitySave: case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningKitPricingIdentitySave: //TODO: call price routine save method on service. SelectedPriceRoutine.IsDirty = false; SelectedFeature.EnableRemainingSteps(); break; case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningAnalyticsFiltersSave: ExecuteAsyncCommand(SaveFiltersCommand, x => SelectedFeatureViewModel = GetViewModel(SelectedStep), "Filters saving...", "Filters saved."); break; case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningAnalyticsPriceListsSave: ExecuteAsyncCommand(SavePriceListsCommand, x => SelectedFeatureViewModel = GetViewModel(SelectedStep), "Price Lists saving...", "Price Lists saved."); break; case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningAnalyticsValueDriversSave: ExecuteAsyncCommand(SaveValueDriversCommand, x => SelectedFeatureViewModel = GetViewModel(SelectedStep), "Value Drivers saving...", "Value Drivers saved."); break; case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningEverydayPricingPriceListsSave: case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningPromotionPricingPriceListsSave: case APLPX.Client.Entity.ModuleFeatureStepActionType.PlanningKitPricingPriceListsSave: break; } }