public Person Create(CreatePersonViewModel createPerson)
        {
            Person person = new Person();  // skapar en person

            {
                person.Name     = createPerson.Name; // överför datan från createPerson till Person.
                person.InCityId = createPerson.CityId;
                person.Phone    = createPerson.Phone;
            }



            _peopleDbContext.Add(person);                // lägger till person med rätt namn city phone.

            int result = _peopleDbContext.SaveChanges(); //sparar ändringar.

            if (result == 0)
            {
                throw new Exception("Unable to add a Person to database");
            }


            person = Read(person.Id);


            return(person);
        }
        public PersonLanguage Create(PersonLanguage personLanguage)
        {
            _peopleDbContext.Add(personLanguage);

            if (_peopleDbContext.SaveChanges() > 0)
            {
                return(personLanguage);
            }
            return(null);
        }
예제 #3
0
        public City Create(City city)
        {
            _peopleDbContext.Add(city);
            int result = _peopleDbContext.SaveChanges();

            if (result == 0)
            {
                return(null);
            }
            return(city);
        }
예제 #4
0
        public Country Create(Country country)
        {
            _peopleDbContext.Add(country);

            int result = _peopleDbContext.SaveChanges();

            if (result == 0)
            {
                return(null);
            }
            return(country);
        }