Exemple #1
0
 /// Delete
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     try
     {
         var query = (from portfolio in context.Portfolio
                      where portfolio.MasterId == AuthPage.userID
                      select new
         {
             id = portfolio.WorkId,
             Name = portfolio.Name,
             Image = portfolio.Image
         }).ToList();
         workID = query[worksDataGrid.SelectedIndex].id;
         if (MessageBox.Show("Do you really want to delete this work?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             Portfolio work = context.Portfolio
                              .Where(w => w.WorkId == workID)
                              .FirstOrDefault();
             context.Portfolio.Remove(work);
             context.SaveChanges();
         }
         updateDatagrid();
     }
     catch
     {
         MessageBox.Show("Choose a work you want to delete", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
         return;
     }
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Client client = new Client
            {
                Name    = nameTb.Text,
                Surname = surnameTb.Text,
                Phone   = phoneTb.Text
            };

            context.Client.Add(client);
            context.SaveChanges();



            Schedule schedule = new Schedule
            {
                MasterId      = Convert.ToInt32(masterCB.SelectedValue),
                ClientId      = client.ClientId,
                Date_and_time = Convert.ToDateTime(dataPicker.SelectedDate)
            };

            context.Schedule.Add(schedule);
            context.SaveChanges();
        }