示例#1
0
 private void AuthorDafaultDataLoad(Author author)
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             db.Authors.Attach(author);
             _AuthorStatus = new _AuthorStatus();
             _AuthorStatus.AuthorStatus = author.AuthorStatus;
             _Contacts             = new _Contacts();
             _Contacts.Contacts    = author.Persone.Contacts;
             _Contacts.TmpContacts = _Contacts.Contacts;
             _Dir = new _Direction();
             foreach (var item in author.Direction)
             {
                 _Dir.AuthorDirections.Add(item);
             }
             //Date = new Dates();
             //Date = author.Persone.Dates[0];
             PersoneContactsData.Date    = author.Persone.Dates[0];
             PersoneContactsData.Persone = author.Persone;
             //Persone = author.Persone;
             //PersoneDescription = author.Persone.PersoneDescription;
             PersoneContactsData.PersoneDescription = author.Persone.PersoneDescription;
             _Subj = new _Subject();
             foreach (var item in author.Subject)
             {
                 _Subj.AuthorSubjects.Add(item);
             }
         }
         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
        //bool notTheOne = false;//flag for



        private void DefaultDataLoad()
        {
            _Contacts    = new _Contacts();
            DefaultPhoto = "default_avatar.png";
            Usver        = new PersoneContactsData();

            AccessNameList = new ObservableCollection <string>()
            {
                "Админ", "Мастер-админ"
            };

            //first user have to be only "master-admin"
            Usver.User.AccessName = "Мастер-админ";
        }
示例#3
0
        private void DefaultDataLoadForEditUser(int usrId)
        {
            AccessNameList = new ObservableCollection <string>()
            {
                "Админ", "Мастер-админ"
            };
            _Contacts    = new _Contacts();
            DefaultPhoto = "default_avatar.png";
            Usver        = new PersoneContactsData();

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    Usver.User               = db.Users.Where(e => e.UserId == usrId).FirstOrDefault();
                    Usver.Persone            = Usver.User.Persone;
                    _Contacts.Contacts       = Usver.User.Persone.Contacts;
                    Usver.Date               = Usver.Persone.Dates.Where(e => e.Persone.PersoneId == Usver.Persone.PersoneId).FirstOrDefault();
                    Usver.PersoneDescription = Usver.Persone.PersoneDescription;
                    //SelectedRecord = Usver;
                    //Usver.Persone = db.Persones.Where(e => e.PersoneId == Usver.User.Persone.PersoneId).FirstOrDefault();
                    //_Contacts.Contacts = db.Contacts.Where(e => e.ContactsId == Usver.User.Persone.Contacts.ContactsId).FirstOrDefault();
                    //Dates date = Usver.Persone.Dates.Where(e => e.Persone.PersoneId == Usver.Persone.PersoneId).FirstOrDefault();
                    //db.Dates.Attach(date);
                    //Usver.Date = date;
                }
                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);
                }
            }
        }
示例#4
0
        private void DefaultDataLoad()
        {
            DefaultPhoto = "default_avatar.png";
            //Author = new Author();
            _AuthorStatus = new _AuthorStatus();
            _Contacts     = new _Contacts();
            //Date = new Dates();
            _Dir = new _Direction();
            //Persone = new Persone();
            PersoneContactsData = new PersoneContactsData();

            //PersoneDescription = new PersoneDescription();
            _Subj         = new _Subject();
            dialogService = new DefaultDialogService();
            showWindow    = new DefaultShowWindowService();
        }
示例#5
0
        private void SaveAuthorData()
        {
            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    string errValidation = ValidAuthorDataCheck();
                    if (errValidation != null)
                    {
                        errValidation += "\n\n Данные автора НЕ были сохранены";
                        dialogService.ShowMessage(errValidation);
                        return;
                    }
                    else
                    {
                        //if we  need to modified entrie
                        if (PersoneContactsData.Author.AuthorId != 0)
                        {
                            db.Entry(PersoneContactsData.Persone).State = EntityState.Modified;
                            db.Entry(PersoneContactsData.Date).State    = EntityState.Modified;
                            db.Entry(PersoneContactsData.Author).State  = EntityState.Modified;
                            db.Entry(_Dir.Dir).State   = EntityState.Modified;
                            db.Entry(_Subj.Subj).State = EntityState.Modified;
                            db.Entry(PersoneContactsData.PersoneDescription).State = EntityState.Modified;
                        }
                        PersoneContactsData.Persone.Contacts = _Contacts.Contacts;
                        if (PersoneContactsData.Author.AuthorId != 0)
                        {
                            PersoneContactsData.Persone.Dates[0] = PersoneContactsData.Date;
                        }
                        else
                        {
                            PersoneContactsData.Persone.Dates.Add(PersoneContactsData.Date);
                        }

                        PersoneContactsData.Persone.PersoneDescription = PersoneContactsData.PersoneDescription;
                        PersoneContactsData.Author.Persone             = PersoneContactsData.Persone;
                        PersoneContactsData.Author.AuthorStatus        = db.AuthorStatuses.Find(_AuthorStatus.AuthorStatus.AuthorStatusId);
                        if (PersoneContactsData.Author.AuthorId == 0)
                        {
                            db.Authors.Add(PersoneContactsData.Author);
                        }
                        db.SaveChanges();

                        //удаляем из списка направлений упоминания об авторе, если в списке направлений автора нет более того или  иного направления после правки
                        // remove the author’s mention from the list of directions if the author’s list does not have more than one direction or another after editing
                        var res = db.Directions.ToList();
                        foreach (var i in res)
                        {
                            if (i.Author.Contains(PersoneContactsData.Author) && !_Dir.AuthorDirections.Contains(i))
                            {
                                i.Author.Remove(PersoneContactsData.Author);
                            }
                            continue;
                        }


                        foreach (Direction item in _Dir.AuthorDirections)
                        {
                            var res1 = db.Directions.Find(item.DirectionId);
                            if (res1 != null && !res1.Author.Contains(PersoneContactsData.Author))
                            {
                                //changing DB
                                if (PersoneContactsData.Author.AuthorId != 0)
                                {
                                    res1.Author.Add(PersoneContactsData.Author);
                                    continue;
                                }
                                else
                                {
                                    res1.Author.Add(PersoneContactsData.Author);
                                }
                                continue;
                            }
                        }
                        db.SaveChanges();

                        //удаляем из списка предметов упоминания об авторе, если в списке предметов автора нет более того или  иного направления после правки
                        // remove the author’s mention from the list of subjects if the author’s list does not have more than one subject or another after editing
                        var res2 = db.Subjects.ToList();
                        foreach (var i in res2)
                        {
                            if (i.Authors.Contains(PersoneContactsData.Author) && !_Subj.AuthorSubjects.Contains(i))
                            {
                                i.Authors.Remove(PersoneContactsData.Author);
                            }
                            continue;
                        }
                        //here we add author in subjects
                        foreach (Subject item in _Subj.AuthorSubjects)
                        {
                            var res1 = db.Subjects.Find(item.SubjectId);
                            if (res1 != null)
                            {
                                //changing DB
                                res1.Authors.Add(PersoneContactsData.Author);
                                continue;
                            }
                            else
                            {
                                res1.Authors.Add(PersoneContactsData.Author);
                            }
                            continue;
                        }
                        db.SaveChanges();

                        dialogService.ShowMessage("Данные автора сохранены");
                        //обнуляем поля окна
                        //clear window fields
                        if (PersoneContactsData.Author.AuthorId == 0)
                        {
                            _Contacts = new _Contacts();
                            PersoneContactsData.Persone = new Persone();
                            _AuthorStatus = new _AuthorStatus();
                            PersoneContactsData.Author = new Author();
                            PersoneContactsData.Date   = new Dates();
                            _Subj = new _Subject();
                            _Dir  = new _Direction();
                            PersoneContactsData.PersoneDescription = new PersoneDescription();
                        }
                    }
                }
                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);
                }
            }
        }