private void ButtonNew_Click(object sender, RoutedEventArgs e)
 {
     this.ButtonSave.IsEnabled = true;
     _currentVM            = new ProductRecommendVM();
     this.Grid.DataContext = _currentVM;
     _isEditing            = false;
 }
        public void Update(ProductRecommendVM vm, EventHandler <RestClientEventArgs <object> > callback)
        {
            var model = vm.ConvertVM <ProductRecommendVM, ProductRecommendInfo>((v, entity) => {
                entity.Location             = v.LocationVM.ConvertVM <ProductRecommendLocationVM, ProductRecommendLocation>();
                entity.Location.CompanyCode = CPApplication.Current.CompanyCode;
                entity.Location.WebChannel  = new BizEntity.Common.WebChannel {
                    ChannelID = vm.ChannelID
                };
            });;

            model.CompanyCode = CPApplication.Current.CompanyCode;
            model.WebChannel  = new BizEntity.Common.WebChannel {
                ChannelID = vm.ChannelID
            };
            string relativeUrl = "/MKTService/ProductRecommend/Update";

            restClient.Update(relativeUrl, model, callback);
        }
        public override void OnPageLoad(object sender, EventArgs e)
        {
            base.OnPageLoad(sender, e);

            //初始化页面数据
            this.lstChannel.ItemsSource = CPApplication.Current.CurrentWebChannelList.ToList <UIWebChannel>();
            this.rbInvalid.Content      = EnumConverter.GetDescription(ADStatus.Deactive, typeof(ADStatus));
            this.rbValid.Content        = EnumConverter.GetDescription(ADStatus.Active, typeof(ADStatus));
            //初始化DataContext
            _isEditing = !string.IsNullOrWhiteSpace(this.Request.Param);
            if (_isEditing)
            {
                new ProductRecommendFacade(this).Load(this.Request.Param, (s, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    _currentVM = args.Result.Convert <ProductRecommendInfo, ProductRecommendVM>((info, vm) =>
                    {
                        vm.LocationVM = info.Location.Convert <ProductRecommendLocation, ProductRecommendLocationVM>();
                        if (info.WebChannel != null)
                        {
                            vm.ChannelID = info.WebChannel.ChannelID;
                        }
                    });
                    this.ucPageType.PageTypeLoadCompleted     += new EventHandler(ucPageType_PageTypeLoadCompleted);
                    this.ucPageType.PageLoadCompleted         += new EventHandler(ucPageType_PageLoadCompleted);
                    this.ucPageType.PagePositionLoadCompleted += new EventHandler(ucPageType_PagePositionLoadCompleted);
                    this.Grid.DataContext         = _currentVM;
                    _positionID                   = _currentVM.LocationVM.PositionID;
                    lstPosition.SelectionChanged -= lstPosition_SelectionChanged;
                });
            }
            else
            {
                _currentVM                         = new ProductRecommendVM();
                this.Grid.DataContext              = _currentVM;
                this.lstChannel.SelectedIndex      = 0;
                this.lstPosition.SelectedIndex     = 0;
                this.ucPageType.ExtendC3Visibility = System.Windows.Visibility.Visible;
            }
        }