private void SaveAction(object window)
        {
            if (AddMode)
            {
                var person = new Person()
                {
                    Id        = GetNewPersonId(),
                    FirstName = FirstName,
                    LastName  = LastName
                };
                GlobalDataModel.Instance.Model.Persons.Add(person);
            }
            else
            {
                var person = GlobalDataModel.Instance.Model.Persons.Select(x => x).Where(x => x.Id == personId).FirstOrDefault();
                person.FirstName = FirstName;
                person.LastName  = LastName;
                person.UpdateUi();
                foreach (var item in StructureService.GetAllPositions())
                {
                    if (item.PersonId == person.Id)
                    {
                        item.UpdateUi();
                    }
                }
            }

            if (window != null)
            {
                ((Window)window).Close();
            }
        }
示例#2
0
        private void DeleteNodeAction(object data)
        {
            string nodeName = string.Empty;

            if (SelectedNode is Structure)
            {
                nodeName = ((Structure)SelectedNode).Name;
            }
            else
            {
                nodeName = ((Position)SelectedNode).Name;
            }

            if (MessageBox.Show("Do you want delete position \"" + nodeName + "\" ?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                if (SelectedNode is Structure)
                {
                    Structures.Remove((Structure)SelectedNode);
                }
                else
                {
                    Position position     = (Position)SelectedNode;
                    var      allPositions = StructureService.GetAllPositions();
                    var      parent       = allPositions.Select(x => x).Where(x => x.SubPositions.Contains(position)).FirstOrDefault();
                    if (parent != null)
                    {
                        parent.SubPositions.Remove(position);
                    }
                }
            }
        }