Example #1
0
        protected override void SetSelectedModel()
        {
            try
            {
                if (Models != null)
                {
                    Model = Models.CurrentItem as Period;
                    UpdateViewState(Edit.Mode.Editing);
                }

                if (Model != null)
                {
                    if (AllStatus != null)
                    {
                        ObservableCollection <Status> status = (ObservableCollection <Status>)AllStatus.SourceCollection;
                        if (status != null)
                        {
                            Status selectedStatus = status.Where(s => s.Name == Model.Status.Name).SingleOrDefault();
                            if (selectedStatus != null)
                            {
                                AllStatus.MoveCurrentTo(selectedStatus);
                            }
                        }
                    }

                    if (Types != null)
                    {
                        ObservableCollection <PeriodType> periodTypes = (ObservableCollection <PeriodType>)Types.SourceCollection;
                        if (periodTypes != null)
                        {
                            PeriodType selectedType = periodTypes.Where(p => p.Id == Model.Type.Id).SingleOrDefault();
                            if (selectedType != null)
                            {
                                Types.MoveCurrentTo(selectedType);
                            }
                        }
                    }

                    if (Years != null)
                    {
                        ObservableCollection <Value> years = (ObservableCollection <Value>)Years.SourceCollection;
                        if (years != null)
                        {
                            Value selectedYear = years.Where(y => y.Id == Model.Year).SingleOrDefault();
                            if (selectedYear != null)
                            {
                                Years.MoveCurrentTo(selectedYear);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.DisplayMessage(ex.Message);
            }
        }