Exemplo n.º 1
0
        public void DeleteSubj()
        {
            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    var res = db.Orderlines;
                    if (Subj.SubjectId != 1 && !CheckRecordBeforDelete(Subj))
                    {
                        if (dialogService.YesNoDialog("Точно нужно удалить эту запись?") == true)
                        {
                            //changing DB
                            //we find all the records in which we have the desired Id and make a replacement
                            foreach (OrderLine order in res)
                            {
                                if (order.Subject.SubjectId == Subj.SubjectId)
                                {
                                    order.Subject = db.Subjects.Find(new Subject()
                                    {
                                        SubjectId = 1
                                    }.SubjectId);
                                }
                            }
                            db.Subjects.Remove(db.Subjects.Find(Subj.SubjectId));
                            db.SaveChanges();
                            //changing collection
                            AuthorSubjects.Remove(Subj);
                            SubjRecords.Remove(Subj);

                            Subj          = SubjRecords[0];
                            SelectedSubj2 = Subj;
                        }
                    }
                    else
                    {
                        dialogService.ShowMessage("Нельзя удалить эту запись");
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
 private void AddAuthorSubject()
 {
     if (FindSubj(SelectedSubj2) || string.IsNullOrEmpty(SelectedSubj2.SubName) || SelectedSubj2.SubName == "---")
     {
         dialogService.ShowMessage("Уже есть такая запись в списке");
     }
     else
     {
         AuthorSubjects.Add(SelectedSubj2);
     }
 }
Exemplo n.º 3
0
 private void DelFromAuthorSubjects()
 {
     AuthorSubjects.Remove(AuthorSubjects[Index]);
 }