Пример #1
0
 //===================THIS METHOD IS FOR ADD RECORDS IN STATUS TABLES==============
 public void AddAuthorStatus()
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res4 = db.AuthorStatuses.Any(o => o.AuthorStatusName == AuthorStatus.AuthorStatusName);
             if (!res4)
             {
                 if (!string.IsNullOrEmpty(AuthorStatus.AuthorStatusName))
                 {
                     AuthorStatus.AuthorStatusName = AuthorStatus.AuthorStatusName.ToLower();
                     AuthorStatus.AuthorStatusName.Trim();
                     if (AuthorStatus.AuthorStatusName[0] == ' ')
                     {
                         dialogService.ShowMessage("Нельзя добавить пустую строку");
                         return;
                     }
                     db.AuthorStatuses.Add(AuthorStatus);
                     db.SaveChanges();
                     AuthorStatusRecords.Clear();
                     LoadData();
                     AuthorStatus = new AuthorStatus();
                 }
                 else
                 {
                     return;
                 }
             }
             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);
         }
     }
 }
Пример #2
0
 //===================THIS METHOD IS FOR DELETE RECORDS FROM STATUS TABLES==============
 public void DeleteAuthorStatus()
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res = db.Authors;
             if (AuthorStatus.AuthorStatusId != 1 && !CheckRecordBeforDelete(AuthorStatus))
             {
                 if (dialogService.YesNoDialog("Точно нужно удалить эту запись?") == true)
                 {
                     //changing DB
                     //we find all the records in which we have the desired Id and make a replacement
                     foreach (Author item in res)
                     {
                         if (item.AuthorStatus.AuthorStatusId == AuthorStatus.AuthorStatusId)
                         {
                             item.AuthorStatus = db.AuthorStatuses.Find(new AuthorStatus()
                             {
                                 AuthorStatusId = 1
                             }.AuthorStatusId);
                         }
                     }
                     db.AuthorStatuses.Remove(db.AuthorStatuses.Find(AuthorStatus.AuthorStatusId));
                     db.SaveChanges();
                     //changing collection
                     AuthorStatusRecords.Remove(AuthorStatus);
                 }
             }
             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);
         }
     }
 }
Пример #3
0
 //load data array from "Statuses" data
 private void LoadData()
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var list = db.AuthorStatuses.ToList();
             foreach (var item in list)
             {
                 AuthorStatusRecords.Add(
                     new AuthorStatus
                 {
                     AuthorStatusId   = item.AuthorStatusId,
                     AuthorStatusName = item.AuthorStatusName
                 });
             }
             AuthorStatus = AuthorStatusRecords[0];
         }
         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);
         }
     }
 }