Ejemplo n.º 1
0
        private void button_Copy_Click(object sender, RoutedEventArgs e)
        {
            ResourceView newResource = new ResourceView();
            Resource     resource    = new Resource();

            if (!isNewResource)
            {
                foreach (var _resource in ResourcePage.ResourceList)
                {
                    if (_resource.Id == Int32.Parse(idLabel.Content.ToString()))
                    {
                        newResource = _resource;
                        break;
                    }
                }
            }
            else
            {
                newResource.Id = resource.Id;
            }

            if (nameTextBox.Text.Length == 0)
            {
                System.Windows.MessageBox.Show("Unesite pravilno ime materijala.");
                return;
            }
            var s = roomsComboBox.SelectedItem as RoomView;

            if (!isNewResource)
            {
                ResourcePage.ResourceList.Remove(newResource);
            }

            newResource.RoomId = (int)s.Id;
            newResource.Type   = nameTextBox.Text;

            resource = newResource.Convert();

            if (!isNewResource)
            {
                _resourceController.Update(resource);
            }
            else
            {
                _resourceController.Add(resource);
            }
            ResourcePage.ResourceList.Add(newResource);

            System.Windows.MessageBox.Show("Uspešno ste sačuvali informacije.");
            NavigationService.Navigate(new Page());
        }