示例#1
0
        //===================THIS METHOD IS FOR EDIT RECORDS IN DIRECTIONS TABLE==============
        public void EditDir(string newDirName)
        {
            if (Dir.DirectionName == "---")
            {
                dialogService.ShowMessage("Нельзя редактировать эту запись");
                return;
            }
            Dir.DirectionName = newDirName;
            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    var res1 = db.Directions.Find(Dir.DirectionId);
                    if (res1 != null)
                    {
                        //changing DB
                        res1.DirectionName = Dir.DirectionName.ToLower();
                        Dir.DirectionName.Trim();

                        db.SaveChanges();
                        DirRecords.Clear();
                        LoadDirectionsData();
                    }
                }
                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 ADD RECORDS IN DIRECTIONS TABLE==============
        public void  AddDir(string newDirName)
        {
            if (Dir != null)
            {
                Dir.DirectionName = newDirName;
            }
            else
            {
                Dir = new Direction()
                {
                    DirectionName = newDirName
                }
            };

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    var res1 = db.Directions.Any(o => o.DirectionName == Dir.DirectionName);
                    if (!res1)
                    {
                        if (!string.IsNullOrEmpty(Dir.DirectionName) || Dir.DirectionName != "---")
                        {
                            Dir.DirectionName = Dir.DirectionName.ToLower();
                            Dir.DirectionName.Trim();
                            if (Dir.DirectionName[0] == ' ')
                            {
                                dialogService.ShowMessage("Нельзя добавить пустую строку");
                                return;
                            }
                            db.Directions.Add(Dir);
                            db.SaveChanges();
                            DirRecords.Clear();
                            LoadDirectionsData();
                            Dir          = new Direction();
                            SelectedDir2 = Dir;
                        }
                        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);
                }
            }
        }