Beispiel #1
0
        public bool Save() {
            bool isOkay = false;

            using (var dbContext = new PeopleEntities()) {

                if (languageID == null) {
                    Language = null;
                }
                else {
                    Language = dbContext.Languages.Find(languageID);
                }

                if (id > 0) {
                    dbContext.People.Attach(this);
                    dbContext.Entry(this).State = System.Data.EntityState.Modified;
                }
                else {
                    dbContext.People.Add(this);
                }

                if (dbContext.SaveChanges() > 0) {
                    isOkay = true;
                }
            }

            return isOkay;
        }
Beispiel #2
0
        public LanguageViewModel(int id) {
            using (var dbContext = new PeopleEntities()) {
                language = dbContext.Languages.First(l => l.id == id);
            }

            if (language == null) {
                language = new Language();
            }
        }
        public LanguagesViewModel() {
            InitializeDependencies();
            List<Language> languagesList;
            using (var dbContext = new PeopleEntities()) {
                languagesList = dbContext.Languages.ToList();
            }

            SetCollection(languagesList);
        }
Beispiel #4
0
        public static Person GetPerson(int id) {
            Person person;
            using (var dbContext = new PeopleEntities()) {
                person = dbContext.People
                    .Find(id);
                if (person != null) {
                    if (person.Language != null) { } // forces load of Language
                }
            }

            return person;
        }
Beispiel #5
0
 private List<Person> GetPeopleFromDB() {
     List<Person> peopleList;
     using (var dbContext = new PeopleEntities()) {
         peopleList = dbContext.People
         .Include(a => a.Language)
         .OrderBy(a => a.id)
         .ToList<Person>();
     }
     return peopleList;
 }