예제 #1
0
        // редактирование
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            // если ни одного объекта не выделено, выходим
            if (ClientsList.SelectedItem == null)
            {
                return;
            }
            // получаем выделенный объект
            Client client = ClientsList.SelectedItem as Client;

            ClientsWindow clientWindow = new ClientsWindow(new Client
            {
                Id       = client.Id,
                Discount = client.Discount,
                Name     = client.Name,
                Email    = client.Email,
                Password = client.Password
            });

            if (clientWindow.ShowDialog() == true)
            {
                // получаем измененный объект
                client = db.Clients.Find(clientWindow.Client.Id);
                if (client != null)
                {
                    client.Email           = clientWindow.Client.Email;
                    client.Discount        = clientWindow.Client.Discount;
                    client.Name            = clientWindow.Client.Name;
                    client.Id              = clientWindow.Client.Id;
                    client.Password        = clientWindow.Client.Password;
                    db.Entry(client).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
예제 #2
0
        // добавление
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            ClientsWindow clientWindow = new ClientsWindow(new Client());

            if (clientWindow.ShowDialog() == true)
            {
                Client client = clientWindow.Client;
                db.Clients.Add(client);
                db.SaveChanges();
            }
        }