示例#1
0
        public void Delete(int id)
        {
            var context = new BreedContext();

            var personToDelete = context.People.Where(p => p.Id == id).FirstOrDefault();

            if (personToDelete == null)
            {
                return;
            }

            context.People.Remove(personToDelete);
            context.SaveChanges();
        }
示例#2
0
        public PersonDto Create(PersonDto person)
        {
            var personToCreate = Map(person);

            if (personToCreate == null)
            {
                return null;
            }

            personToCreate.Id = 0;

            var context = new BreedContext();
            context.People.Add(personToCreate);
            context.SaveChanges();

            return Map(personToCreate);
        }
示例#3
0
        public PersonDto Update(PersonDto person)
        {
            if (person == null)
            {
                return null;
            }

            var context = new BreedContext();

            var personToUpdate = context.People.Where(p => p.Id == person.Id).FirstOrDefault();

            if (personToUpdate == null)
            {
                return null;
            }

            personToUpdate.Name = person.Name;
            personToUpdate.Birthdate = person.Birthdate;
            personToUpdate.Deceased = person.Deceased;

            context.SaveChanges();

            return Map(personToUpdate);
        }
示例#4
0
        public PersonDto SetFather(int id, int fatherId)
        {
            var context = new BreedContext();

            var child = context.People.Include(p => p.Mother).Include(p => p.Father).Where(p => p.Id == id).FirstOrDefault();
            var father = context.People.Where(p => p.Id == fatherId).FirstOrDefault();

            if (child == null || father == null)
            {
                return null;
            }

            child.Father = father;

            context.SaveChanges();

            return Map(child);
        }