示例#1
0
        /// <summary>
        ///     Удалить данные
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new MedIdeaContext())
            {
                if (treatmentsGrid.SelectedItems.Count > 0)
                {
                    for (var i = 0; i < treatmentsGrid.SelectedItems.Count; i++)
                    {
                        var treatment = treatmentsGrid.SelectedItems[i] as Treatment;
                        if (treatment != null)
                        {
                            db.Treatments.Remove(treatment);
                        }
                    }
                }

                db.SaveChanges();
            }

            UpdateTreatmentsGrid();
        }
示例#2
0
        /// <summary>
        ///     Удалить данные
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new MedIdeaContext())
            {
                if (usersGrid.SelectedItems.Count > 0)
                {
                    for (var i = 0; i < usersGrid.SelectedItems.Count; i++)
                    {
                        var user = usersGrid.SelectedItems[i] as User;
                        if (user != null)
                        {
                            db.Users.Remove(user);
                        }
                    }
                }

                db.SaveChanges();
            }

            UpdateGrid();
        }
示例#3
0
        /// <summary>
        ///     Сохранить изменения.
        /// </summary>
        /// <param name="newUser">
        ///     <see cref="User" />
        /// </param>
        /// <param name="user">
        ///     <see cref="User" />
        /// </param>
        private void SaveChanges(User newUser, User user)
        {
            using (var db = new MedIdeaContext())
            {
                AddNewDataFromFields(newUser);

                if (user != null)
                {
                    db.Update(newUser);
                    AddDataInList(newUser);
                    db.UpdateRange(list);
                }
                else
                {
                    db.Add(newUser);
                    AddDataInList(newUser);
                    db.UpdateRange(list);
                }

                db.SaveChanges();
            }
        }