Пример #1
0
        public void Refresh(TicketItemViewModel ticketItem, TicketTagGroup selectedTicketTag)
        {
            HideKeyboard();
            SelectedTicketTag = null;
            SelectedItemPortions.Clear();
            SelectedItemPropertyGroups.Clear();
            SelectedItemGroupedPropertyItems.Clear();
            TicketTags.Clear();

            SelectedItem = ticketItem;

            if (ticketItem != null)
            {
                var mi = AppServices.DataAccessService.GetMenuItem(ticketItem.Model.MenuItemId);
                if (mi.Portions.Count > 1)
                {
                    SelectedItemPortions.AddRange(mi.Portions.Select(x => new MenuItemPortionViewModel(x)));
                }

                SelectedItemGroupedPropertyItems.AddRange(mi.PropertyGroups.Where(x => !string.IsNullOrEmpty(x.GroupTag))
                                                          .GroupBy(x => x.GroupTag)
                                                          .Select(x => new MenuItemGroupedPropertyViewModel(SelectedItem, x)));

                SelectedItemPropertyGroups.AddRange(mi.PropertyGroups
                                                    .Where(x => string.IsNullOrEmpty(x.GroupTag))
                                                    .Select(x => new MenuItemPropertyGroupViewModel(x)));

                foreach (var ticketItemPropertyViewModel in ticketItem.Properties.ToList())
                {
                    var tip = ticketItemPropertyViewModel;
                    var mig = SelectedItemPropertyGroups.Where(x => x.Model.Id == tip.Model.PropertyGroupId).SingleOrDefault();
                    if (mig != null)
                    {
                        mig.Properties.SingleOrDefault(x => x.Name == tip.Model.Name).TicketItemProperty = ticketItemPropertyViewModel.Model;
                    }

                    var sig = SelectedItemGroupedPropertyItems.SelectMany(x => x.Properties).Where(
                        x => x.MenuItemPropertyGroup.Id == tip.Model.PropertyGroupId).FirstOrDefault();
                    if (sig != null)
                    {
                        sig.TicketItemProperty = ticketItemPropertyViewModel.Model;
                    }
                }
            }
            else
            {
                if (selectedTicketTag != null)
                {
                    SelectedTicketTag = selectedTicketTag;

                    if (selectedTicketTag.FreeTagging)
                    {
                        TicketTags.AddRange(Dao.Query <TicketTagGroup>(x => x.Id == selectedTicketTag.Id, x => x.TicketTags).SelectMany(x => x.TicketTags).OrderBy(x => x.Name).Select(x => new TicketTagViewModel(x)));
                    }
                    else
                    {
                        TicketTags.AddRange(selectedTicketTag.TicketTags.Select(x => new TicketTagViewModel(x)));
                    }
                    RaisePropertyChanged("TicketTags");
                }
                else
                {
                    RaisePropertyChanged("TicketNote");
                    ShowKeyboard();
                }
            }

            RaisePropertyChanged("SelectedItem");
            RaisePropertyChanged("IsPortionsVisible");
            RaisePropertyChanged("IsEditorsVisible");
            RaisePropertyChanged("IsTicketNoteVisible");
            RaisePropertyChanged("IsTagEditorVisible");
            RaisePropertyChanged("IsFreeTagEditorVisible");
            RaisePropertyChanged("TagColumnCount");
        }
        private void OnTicketViewModelEvent(EventParameters <TicketViewModel> obj)
        {
            if (obj.Topic == EventTopicNames.SelectTicketTag)
            {
                ResetValues(obj.Value);
                _showFreeTagEditor = SelectedTicket.LastSelectedTicketTag.FreeTagging;

                List <TicketTag> tags;
                if (_showFreeTagEditor)
                {
                    tags = Dao.Query <TicketTagGroup>(x => x.Id == SelectedTicket.LastSelectedTicketTag.Id,
                                                      x => x.TicketTags).SelectMany(x => x.TicketTags).OrderBy(x => x.Name).ToList();
                }
                else
                {
                    tags = AppServices.MainDataContext.SelectedDepartment.TicketTagGroups.Where(
                        x => x.Name == obj.Value.LastSelectedTicketTag.Name).SelectMany(x => x.TicketTags).ToList();
                }
                tags.Sort(new AlphanumComparator());
                TicketTags.AddRange(tags);

                if (SelectedTicket.IsTaggedWith(SelectedTicket.LastSelectedTicketTag.Name))
                {
                    TicketTags.Add(TicketTag.Empty);
                }
                if (TicketTags.Count == 1 && !_showFreeTagEditor)
                {
                    obj.Value.UpdateTag(SelectedTicket.LastSelectedTicketTag, TicketTags[0]);
                }
                RaisePropertyChanged("TagColumnCount");
                RaisePropertyChanged("IsFreeTagEditorVisible");
                RaisePropertyChanged("FilteredTextBoxType");
            }

            if (obj.Topic == EventTopicNames.SelectVoidReason)
            {
                ResetValues(obj.Value);
                Reasons.AddRange(AppServices.MainDataContext.Reasons.Values.Where(x => x.ReasonType == 0));
                if (Reasons.Count == 0)
                {
                    obj.Value.VoidSelectedItems(0);
                }
                RaisePropertyChanged("ReasonColumnCount");
            }

            if (obj.Topic == EventTopicNames.SelectGiftReason)
            {
                ResetValues(obj.Value);
                Reasons.AddRange(AppServices.MainDataContext.Reasons.Values.Where(x => x.ReasonType == 1));
                if (Reasons.Count == 0)
                {
                    obj.Value.GiftSelectedItems(0);
                }
                RaisePropertyChanged("ReasonColumnCount");
            }

            if (obj.Topic == EventTopicNames.SelectExtraProperty)
            {
                ResetValues(obj.Value);
                _showExtraPropertyEditor = true;
                RaisePropertyChanged("IsExtraPropertyEditorVisible");
                RaisePropertyChanged("IsPortionsVisible");
            }

            if (obj.Topic == EventTopicNames.EditTicketNote)
            {
                ResetValues(obj.Value);
                _showTicketNoteEditor = true;
                RaisePropertyChanged("IsTicketNoteEditorVisible");
            }
        }